我使用此代码调整 3d nifti 数据的大小,但是当我检查结果时,我发现它很乱并且轴已更改
import numpy as np
import nibabel as nib
import itertools
initial_size_x = 560
initial_size_y = 560
initial_size_z = 240
new_size_x = 512
new_size_y = 512
new_size_z = 216
initial_data = nib.load("id001-512x512x216.nii.gz-pred.nii").get_data()
print('helooooooooooooooooooo')
delta_x = initial_size_x/new_size_x
delta_y = initial_size_y/new_size_y
delta_z = initial_size_z/new_size_z
new_data = np.zeros((new_size_x,new_size_y,new_size_z))
for x, y, z in itertools.product(range(new_size_x),
range(new_size_y),
range(new_size_z)):
new_data[x][y][z] = initial_data[int(x*delta_x)][int(y*delta_y)][int(z*delta_z)]
img = nib.Nifti1Image(new_data, np.eye(4))
img.to_filename("test_"+str(new_size_x)+""+str(new_size_y)+""+str(new_size_z)+".nii")