我有一些维度(50,100,50)的3D nifti文件。我想反转y轴和z轴,这样尺寸就是(50,50,100)。执行此操作的最佳方法是什么,以及如何修改与文件关联的仿射?
目前,我正在将nifti文件转换为numpy数组,并像这样交换坐标轴
array = np.asanyarray(niiobj.dataobj)
img_after_resample_swapped_array = np.swapaxes(img_after_reample_array, 1, 2)我对下一步感到困惑。我知道我可以使用函数nib.Nifti1Image将numpy数组转换为nifti对象,但是我如何修改仿射才能考虑轴的变化呢?
谢谢你的帮助。
发布于 2020-06-25 22:14:10
如果您使用SimpleITK,有一个PermuteAxes函数可以看到Y轴和Z轴。并且它将适当地保留图像的变换。
下面是一个如何做到这一点的示例:
import SimpleITK as sitk
img = sitk.ReadImage("tetra.nii.gz")
print (img.GetDirection())
img2 = sitk.PermuteAxes(img, [0,2,1])
print (img2.GetDirection())
sitk.WriteImage(img2, "permuted.nii.gz")下面是3x3方向矩阵的输出:
(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0)输入图像具有方向的单位矩阵,并且对于置换矩阵,Y和Z行被交换。
下面是PermuteAxesImageFilter和PermuteAxes函数的文档:
https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1PermuteAxesImageFilter.html https://simpleitk.org/doxygen/latest/html/namespaceitk_1_1simple.html#a892cc754413ba3b60c731aac05dddc65
https://stackoverflow.com/questions/62571357
复制相似问题