【问题标题】:How Do I Change the Axis SimpleITK::ImageSeriesWriter Using?如何更改轴 SimpleITK::ImageSeriesWriter 使用?
【发布时间】:2019-01-12 13:35:23
【问题描述】:

SimpleITK::ImageSeriesWriter 默认沿 Z 轴切片给定 3D 体积,并在 XY 视图中写入 2D 图像切片。

如何更改轴以使输出在 XZ 或 YZ 视图中?

换句话说,如果默认的Z轴切片是在Axial视图中,我如何获得Coronal和Sagittal视图的切片?

我尝试了GitHub:FNNDSC/med2image 的输出 xyz 功能。 但是图像数组是盲目写入的,因此有时 X 和 Y 被转置,或者其中一个轴被反转(翻转)。 所以我觉得有必要编写自己的代码来完全控制。

def slice(dcm_folder, output_stem):
    print('Reading Dicom directory:', path.abspath(dcm_folder))
    reader = sitk.ImageSeriesReader()

    dicom_names = reader.GetGDCMSeriesFileNames(dcm_folder)
    reader.SetFileNames(dicom_names)

    image = reader.Execute()

    # cast the bit depth to PNG compatible "unsigned char"
    image = sitk.Cast(sitk.RescaleIntensity(image), sitk.sitkUInt8)

    size = image.GetSize()
    print( "Image size:", size[0], size[1], size[2] )

    # need Z filenames to write
    series_filenames = list([output_stem + '-slice' + str(i).zfill(3) + '.png' for i in range(size[2])])

    print('Writing {} image slices'.format(size[2]))
    writer = sitk.ImageSeriesWriter()
    writer.SetFileNames( series_filenames )
    writer.Execute(image)

上面的代码会成功写出 Z 轴的切片。 如何修改代码以便获得另外 2 个视图的切片?

【问题讨论】:

    标签: python imaging medical simpleitk


    【解决方案1】:

    您应该能够使用 PermuteAxesImageFilter 来交换体积的轴。这是该过滤器的文档:

    https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1PermuteAxesImageFilter.html

    或者,如果您更喜欢程序界面(就像我一样),您可以使用 PermuteAxes 函数。

    【讨论】:

    • 如果你能提供一个小代码sn-p来解释PermuteAxes是如何工作的就更好了。赞赏!
    【解决方案2】:

    嗯,我想你已经解决了你的问题。但我所做的只是导入一个 .mha 文件(或简单 ITK 支持的另一个扩展名)并将其转换为 3D 数组。然后你需要做的就是一次在不同的轴上切片这个数组。看一下(python代码):

    import SimpleITK as sitk #importing package
    path = '/current/folder/mha/file'
    ct = sitk.ReadImage(path) #var_type is SimpleITK.Image
    ndarray = sitk.GetArrayFromImage(ct) #converting from SimpleITK.Image to numpy ndarray
    # Axial view:
    plt.imshow(ndarray[100,:,:], cmap='gray') # plotting 100º image from axial view
    #Coronal view:
    plt.imshow(ndarray[:,100,:], cmap='gray') # plotting 100º image from coronal view
    #Sagittal view:
    plt.imshow(ndarray[:,:,100], cmap='gray') # plotting 100º image from sagittal view
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-29
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      相关资源
      最近更新 更多