首页 > 解决方案 > 如何更改轴 SimpleITK::ImageSeriesWriter 使用?

问题描述

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 个视图的切片?

标签: pythonimagingmedicalsimpleitk

解决方案


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

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

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


推荐阅读