1

我很难为 3 个不同的视图(即冠状、轴向和矢状)找出适当的仿射变换,每个视图都有如下单独的问题:

1:轴向彩色图与矢状原始视图重叠。

在此处输入图像描述

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

在此处输入图像描述

3:当日冕的颜色图和原始图像正确但方向错误时,每个人都有一些方向问题,比如在这里最容易看到。

在此处输入图像描述

我正在保存要发送到服务器以进行某种预测的原始文件,该文件会生成颜色图并返回该文件以进行可视化,稍后我将一起显示所有内容。

在预测后的服务器中,这里是保存文件的代码。

 nifti_img = nib.MGHImage(idx, affine, header=header)

仿射标头是从我发送的文件中提取的原始仿射和标头。

我需要处理以 Numpy 数组格式保存原始数据的“idx”值,但不确定到底要做什么。在这里需要帮助。

正在努力使用nibabel python 库解决问题,但由于我对这些文件如何工作和仿射变换的了解非常有限,我很难弄清楚我应该怎么做才能使它们正确。

我在前端使用带有threejs支持的AMI js,在后端使用带有python的nibabel。任何地方的前端或后端解决方案都是可以接受的。

请帮忙。提前致谢。

4

2 回答 2

2
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)
于 2021-04-01T04:05:15.983 回答
1

这很简单,对来自 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 单位矩阵比使用原始仿射矩阵更好,因为这给我带来了问题。

于 2019-05-16T11:26:55.963 回答