区别
标准NIfTI
图像的扩展名是.nii
,包含了头文件及图像资料。由于NIfTI
格式和Analyze
格式的关系,因此NIfTI
格式也可使用独立的图像文件[.img]
和头文件[.hdr]
。单独的.nii
格式文件的优势就是可以用标准的压缩软件[如gzip
],而且一些分析软件包[比如FSL
]可以直接读取和写入压缩的.nii
文件[扩展名为.nii.gz
]。
读取
import matplotlib
from matplotlib import pylab as plt
import nibabel as nib
from nibabel.viewers import OrthoSlicer3D
file = '' #你的nii或者nii.gz文件路径
img = nib.load(file)
print(img)
print(img.header['db_name']) #输出nii的头文件
width, height, queue = img.dataobj.shape
OrthoSlicer3D(img.dataobj).show()
num = 1
for i in range(0, queue, 10):
img_arr = img.dataobj[:,:,i]
plt.subplot(5,4,num)
plt.imshow(img_arr, cmap='gray')
num += 1
plt.show()