Thanks for the response. Sorry for being slow to return here.
Would it be possible to explain what you are doing in the strict_load() function?
.get_fdata() does indeed not result in the same matrix, so the assert is not working when I am only replacing the nb.load functions by the strict_load function. I do expect .get_fdata() to result in the same values. The assert does work when I use the deprecated .get_data(), which is confusing because (as far as I understand) .get_fdata() should do nothing more than lead to strict float return types.
Could it be that the set_tr function should actually use the .get_unscaled() function?:
def set_tr(img, tr):
header = img.header.copy()
zooms = header.get_zooms()[:3] + (tr,)
header.set_zooms(zooms)
return img.__class__(np.array(img.dataobj.get_unscaled()), img.affine, header)
Btw, this part: np.array(img.dataobj.get_unscaled()) does not work because dataobj is a numpy array and Nifti1Image does not have the function .get_unscaled() (version 3.2.1 of nibabel).
Where is my mistake in understanding?