无法在 nibabel 的 NiftiHeader 中设置图像体素尺寸。如何为给定图像设置特定的体素尺寸?
我需要在 nibabel 中保存具有某些特定体素尺寸的图像。
image = nib.load('some_image')
c = np.array(image.get_fdata())
x = nib.Nifti1Image(c, image.affine)
nib.save(x, 'something.nii.gz')
如何使用一些新的体素尺寸保存成像器?
header information
在保存前更改:image = nib.load('some_image')
header_info = image.header
print(header_info)
# change the voxel dimensions to [2,2,2]
header_info['pixdim'][1:4] = [2,2,2]
c = np.array(image.get_fdata())
# Use the new `header_info` before writing
x = nib.Nifti1Image(c, image.affine, header_info)
nib.save(x, 'something.nii.gz')