SimpleITK 和 Nibabel 读取医学图像 nii 数据(2D显示)
作者:互联网
SimpleITK 和 Nibabel 区别在于:(nii图像可以看成2维,也可以看成三维)
SimpleITK读取数据是(X,Y,Z)显示,Nibabel读取图像是(Z,Y,X)显示,也就是Nibabel加载的图像会旋转90°,其中X表示通道数,即切片层数。详情
import SimpleITK as sitk import skimage.io as io def read_img(path): img = sitk.ReadImage(path) data = sitk.GetArrayFromImage(img) return data #显示一个系列图 def show_img(data): for i in range(data.shape[0]): io.imshow(data[i,:,:], cmap = 'gray') print(i) io.show() #单张显示 def show_img(ori_img): io.imshow(ori_img[60], cmap = 'gray') io.show() path = 'F:/BaiduNetdiskDownload/COVID-19CTSeg/data/volume-0.nii' data = read_img(path) show_img(data)
import nibabel as nib import matplotlib.pyplot as plt def read_data(path): image_data = nib.load(path).get_data() return image_data # 单张显示 def show_img(ori_img): plt.imshow(ori_img[:,:,60], cmap = 'gray') plt.show() path = 'F:/BaiduNetdiskDownload/COVID-19CTSeg/data/volume-0.nii' data = read_data(path) show_img(data)
SimpleITK图像:
Nibabel图像:
标签:Nibabel,nii,img,show,2D,io,path,data 来源: https://www.cnblogs.com/dyc99/p/12539365.html