I'm using a particular toolbox (Tools for NIfTI and Analyze image) to process NIfTI files with MATLAB, but when I do a simple value modification, the spatial information associated with the image is somehow changed. I can't directly compare the before and after images because they have different origins and/or some slight translation. I did not (intentionally) modify the NIfTI header information. In fact, I used only three commands:
matlab_nii = load_nii('original.nii');
matlab_nii.img(matlab.nii.img > 10) = NaN;
save_nii(matlab_nii, 'new.nii');
Despite not editing any of the header information, only modifying the image values directly, the new NIfTI file has differing spatial properties, making it impossible to compare directly to the original, to verify that, indeed, the modifications took place.
I'm hoping someone has had experience with these tools and has encountered this issue.
Found the solution in one of the answers to this question about NIfTI/MATLAB.
The answer is to use load_untouch_nii
instead of load_nii
and save_untouch_nii
instead of save_nii
.
The functions I used initially will apply affine transformation data (if it exists, which apparently it did) to the image. Using these functions results in a direct spatial association between voxels.