用体素尺寸保存nibabel图像

2024-10-01 11:31:03 发布

您现在位置:Python中文网/ 问答频道 /正文

无法在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')

如何用新的体素尺寸保存成像仪 ? 在


Tags: 图像imageget尺寸nploadsomearray
1条回答
网友
1楼 · 发布于 2024-10-01 11:31:03

在保存之前,您需要更改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')

相关问题 更多 >