After loading a NIFTI (.nii) image (using Nibabel) with the code scan = nibabel.load(filepath), it is useful to display the image header information via scan.header.
If you call scan.get_fdata() before calling scan.header, the error arises: AttributeError: 'memmap' object has no attribute 'header'. Example of such code:
scan = nibabel.load(test_image.nii)
scan_volume_data = scan.get_fdata()
print(scan.header)
You have to call
scan.headerbefore callingscan.get_fdata(). This is because after callingscan.get_fdata(), the image object gets transformed to a memmap (memory-map) object, which loses the header information. Example of correct code is the following:We can observe the change of the image datatype with the following code: