-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nibabel copying mgz header incorrectly #1402
Comments
Since you're passing the affine, it's being converted back into the header format. If you use |
OK, I tried that out. everything look good except it set the c_ras to zeros. |
Can you |
Ok here is the updated script import nibabel as nb
import numpy as np
import sys
oldfilledmgz = nb.freesurfer.mghformat.load(sys.argv[1])
newfilledmgz = nb.freesurfer.mghformat.load(sys.argv[2])
WMmgz = nb.freesurfer.mghformat.load(sys.argv[3])
oldfilled=np.asanyarray(oldfilledmgz.dataobj)
newfilled=np.asanyarray(newfilledmgz.dataobj)
WM=np.asanyarray(WMmgz.dataobj)
if not np.array_equal(oldfilled,newfilled):
WM[(oldfilled == 0) & ((newfilled == 127) | (newfilled==255)) ] = 255
WM[(newfilled == 0) & ((oldfilled == 127) | (oldfilled==255)) ] = 1
print(WMmgz.header)
WMnew = nb.freesurfer.mghformat.MGHImage(WM, affine=None, header=WMmgz)
print(WMnew.header)
WMnew.set_filename(sys.argv[3])
nb.save(WMnew, sys.argv[3])
else:
print('No changes were made to the filled.mgz image.') Here is the output
Than I loaded the wm file in python. the header output is
|
Oh, - WMnew = nb.freesurfer.mghformat.MGHImage(WM, affine=None, header=WMmgz)
+ WMnew = nb.freesurfer.mghformat.MGHImage(WM, affine=None, header=WMmgz.header) |
This does help. I ran the code again and used the output for it in FreeSurfer's recon-all and it fails. After some investigation i figured out that the output of the python script is still producing a mgz with the incorrect header. I was able to copy over the header from the original wm.mgz using FreeSurfer's mri_convert with the --in_like flag. After coping the header FreeSurfer over recon-all run all the way through with out an issue. So nibabel is till not coping over all of the header. |
I am currently using nibabel 5.3.2. I wrote a script to makes an edit to an mgz image. After running the script I noticed that nibabel adds what looks like rounding error to some of the mgz header. Below is my whole script.
The text was updated successfully, but these errors were encountered: