4DCT 數據讀取與顯示

4D-CT 數據集中 case1爲例,

使用nibabel庫進行讀取, 注意數據集只有 ANALYSE格式的 .img 文件,沒有提供 .hdr 頭文件,無法直接讀取。根據此issue提供的方法,在官網上找到該數據的shape,datatype等信息,通過構造 dataobj 解決。

並用matplotlib庫中的animation模塊進行動態顯示。

代碼如下:

import numpy as np
import matplotlib.animation as animation
import nibabel as nib
# load img
path='/home/xin/Downloads/Case1Pack/Images/case1_T00_s.img'
dataobj = np.memmap(path,dtype=np.int16,mode='r',shape=(256,256,94),order='F')
img = nib.Nifti1Image(dataobj,[[ -1. , -0. , -0. ,  0.],[ -0. , -1. , -0., 239.],[  0. ,  0.  , 1.  , 0.],[  0.  , 0. ,  0.  , 1.]])
img=img.get_data()
# %%capture
fig = plt.figure(figsize=(8, 8))
plt.axis("off")
ims = [[plt.imshow(img[:,:,i], animated=True)] for i in range(30)]
ani = animation.ArtistAnimation(fig, ims, interval=1000, repeat_delay=1000, blit=True)
ani.save('4dct.gif', writer='imagemagick', fps=10)

顯示結果如下:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章