如何将 3D nii gz 图像阵列重塑为 2D?

How can I reshape a 3D nii gz image array to a 2D?

我有很多 nii.gz 图像需要从 3D 重塑为 2D,我正在尝试使用以下代码,但由于 nii.gz 扩展名,它无法正常工作:

import nibabel as nib
img = nib.load('teste01converted.nii.gz')
img.shape
newimg = img.reshape(332,360*360)

谁能帮帮我?

这是我正在处理的图像类型的示例:https://drive.google.com/drive/folders/1681T99hp6qZRUgx1Ej_h1hwFv1g_LJo4?usp=sharing

根据 NiBabel Getting Started 指南,您可以将 NiBabel 对象转换为 numpy 数组,然后使用 reshape:

This information is available without the need to load anything of the main image data into the memory. Of course there is also access to the image data as a NumPy array

>>> data = img.get_fdata()
>>> data.shape
(128, 96, 24, 2)
>>> type(data)
<... 'numpy.ndarray'>

因此您可以像这样调整您的代码:

import nibabel as nib
img = nib.load('teste01converted.nii.gz')
newimg = img.get_fdata().reshape(332,360*360)

当我这样做时,我得到一个具有这种形状的 numpy 数组:

(332, 129600)

顺便说一句,我对神经影像一无所知,所以我不知道你要求的转换是否有意义。