Open lxmedai opened 1 month ago
The extra dictionary is purely for passing around images in memory. You could write a NIfTI extension to pack anything you want in the header, though:
The basic procedure is:
ext = nb.nifti1.Nifti1Extension(0, bytestring) # 0 for unknown, and you need some bytestring
img.header.extensions.append(ext)
Now you can save the image, and then retrieve it on a received image with img.header.extensions[0].get_content()
.
I tried to put some extra information to the field 'extra' (which is just an empty dict by default) by using
img_nii.extra = {'Test': 'See what happens'}
# img_nii is my loaded nifti1 image.This assignment worked perfectly fine. Then I tried to save it by calling:
img_nii.to_filename('myTestFilename.nii.gz')
, which also worked with no errors reported. But if I tried to load the nifti1 image again by calling img_nii_new =nib.load('myTestFilename.nii.gz')
, what I got in the field 'extra' of img_nii_new was simply an empty dict. What should I do in order to save extra information there? I plan to save some numpy arrays to this 'extra' field. How can I solve this problem? Any suggestions?