ImageSeriesWriter默认为沿Z轴剖切给定的三维体积,并在XY视图中写入二维图像切片。在
如何更改轴以使输出在XZ或YZ视图中?在
换言之,如果默认的Z轴切片是轴向视图,如何获得冠状和矢状视图的切片?在
我尝试了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轴的切片。 如何修改代码,以便可以获得另两个视图的切片?在
您应该能够使用PermuteAxesImageFilter交换卷的轴。以下是该过滤器的文档:
https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1PermuteAxesImageFilter.html
或者,如果您喜欢过程接口(就像我一样),可以使用PermuteAxes函数。在
相关问题 更多 >
编程相关推荐