SimpleITK读取NII格式三维图像及注意事项

SimpleITK

Python中SimpleITK被广泛用于医学图像的处理任务中,功能非常强大,但是使用的时候还需注意,尤其在图像读取时一定要注意维度。

读取NII格式的图像

#读取并显示NII图像文件
from matplotlib import pyplot as plt
import SimpleITK as sitk

img_path = 'res.nii.gz'
I = sitk.ReadImage(img_path)
img = sitk.GetArrayFromImage(I)
plt.imshow(img[1,...], cmap='gray', interpolation='bicubic')
plt.xticks([]), plt.yticks([])  and Y axis
plt.show()

上面的代码很简单,不多做解释,加入我们在最后加上

print(img.shape)

如果输出(300,200,120),其中分别表示该三维体数据在Z轴,Y轴,X轴上的尺寸,这和MATLAB以及ImageJ都有点不同,后续处理一定要注意。

SimpleITK读取nii文件并显示

import SimpleITK as sitk
from matplotlib import pyplot as plt
 
def showNii(img):
    for i in range(img.shape[0]):
        plt.imshow(img[i,:,:],cmap='gray')
        plt.show()
 
itk_img = sitk.ReadImage('C:\\Users\\86472\\Desktop\\1552282517.831928.nii')
img = sitk.GetArrayFromImage(itk_img)
showNii(img)

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

原文地址:https://blog.csdn.net/qq_36763031/article/details/103707557

相关文章:

  • 2021-12-26
  • 2023-02-07
  • 2021-10-22
  • 2021-12-02
  • 2021-11-19
  • 2022-12-23
  • 2021-07-04
猜你喜欢
  • 2022-12-23
  • 2023-02-10
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
  • 2021-10-20
  • 2021-08-08
相关资源
相似解决方案