我很难为三种不同的观点(日冕、轴向和斜面)找出适当的仿射变换,每种观点都有以下各自的问题:
1:轴向彩色地图与原始视图重叠。

2:同样,矢状彩色图与轴向原始图像重叠。

他说:当日冕的彩色地图和原始图像正确的时候,每个人都有一些方向问题,比如在这里最容易看到,但是方向不对。

我保存的原始文件,我要发送到服务器进行某种预测,这会生成一个颜色地图,并返回该文件的可视化,稍后我将显示所有的东西在一起。
在预测后的服务器中,下面是保存文件的代码。
nifti_img = nib.MGHImage(idx, affine, header=header)而仿射和 header 是从我发送的文件中提取出来的原始仿射和标头。
我需要处理"idx"值,该值保存Numpy数组格式的原始数据,但不确定具体要做什么。这里需要帮助。
正在努力使用nibabel python库来解决这个问题,但由于我对这些文件的工作方式和仿射转换的了解非常有限,我很难弄清楚该如何做才能使它们正确。
我使用的是AMI,前端支持,支持,后端使用python支持nibabel。任何地方的前端或后端的解决方案都是可以接受的。
请帮帮忙。提前谢谢。
发布于 2019-05-16 11:26:55
它很简单,对来自nibabel的rawdata使用numpy.moveaxis()和numpy.flip()操作。如下所示。
# Getting raw data back to process for better orienation and label mapping.
orig_img_data = nib.MGHImage(numpy_arr, affine)
nifti_img = nib.MGHImage(segmented_arr_output, affine)
# Getting original and predicted data to preprocess to original shape and view for visualisation.
orig_img = orig_img_data.get_fdata()
seg_img = nifti_img.get_fdata()
# Placing proper views in proper place and flipping it for a better visualisation as required.
# moveaxis to get original order.
orig_img_ = np.moveaxis(orig_img, -1, 0)
seg_img = np.moveaxis(seg_img, -1, 0)
# Flip axis to overcome mirror image/ flipped view.
orig_img_ = np.flip(orig_img_, 2)
seg_img = np.flip(seg_img, 2)
orig_img_data_ = nib.MGHImage(orig_img_.astype(np.uint8), np.eye(4), header)
nifti_img_ = nib.MGHImage(seg_img.astype(np.uint8), np.eye(4), header)注意:,有相同的仿射矩阵来包装这两个数组是非常重要的。一个4*4的恒等矩阵比使用原始仿射矩阵更好,因为这给我带来了问题。
发布于 2021-04-01 04:05:15
img = nib.load(img_path)
# check the orientation you wanna reorient.
# For example, the original orientation of img is RPI,
# you wanna reorient it to RAS, the second the third axes should be flipped
# ornt[P, 1] is flip of axis N, where 1 means no flip and -1 means flip.
ornt = np.array([[0, 1],
[1, -1],
[2, -1]])
img_orient = img.as_reoriented(ornt)
nib.save(img_orient, img_path)https://stackoverflow.com/questions/56111388
复制相似问题