【发布时间】:2023-02-24 04:50:36
【问题描述】:
我正在处理 X、Y、Z 格式的 3d MRI 图像,其中 Z 是大脑中的切片数。我有 JPEGS 和 niftis,我想将这两个文件保存为 xyz 格式的 numpy 数组。在 nifti 文件格式中,文件以 xyz 形式读入,但是当我打印第一个切片时,我将其作为 x 轴长度 z 和 Y 的长度。我怎样才能将它读作 xyz 并且仍然能够将三维打印为正方形。
img = nib.load(os.path.join(data_path, str(list_dir[i]) + ".nii.gz"))
# Get the data from the NIFTI image
data = img.get_fdata()
# Get the shape of the data
slices = []
print(data.shape)
data = np.transpose(data, (0, 1, 2))
shape = data.shape
print(shape)
# Loop through each slice in the data
for i in range(shape[2]):
# Get the current slice
slice = data[:,:,i]
slice = np.rot90(slice, axes = (1,0))
# Save the slice as a 3D Numpy array
slices.append(np.array(slice))
# Convert the list of slices to a Numpy array
print(len(slices))
slices = np.array(slices)
print(slices.shape)
【问题讨论】:
-
目前还不清楚。 “因为 z 的 x 轴长度和 Y 的长度是”无法理解。
-
首次加载图像时,
data.shape中的值是多少?他们是你所期望的吗?你说 X、Y 和 Z 是数字,x、y 和 z 是方向,对吗?您是否希望 x 从左到右,y 从前到后,z 从下到上?
标签: python image numpy nifti mri