nipy / nibabel

Python package to access a cacophony of neuro-imaging file formats
http://nipy.org/nibabel/
Other
654 stars 258 forks source link

parrec2nii #308

Open jyeatman opened 9 years ago

jyeatman commented 9 years ago

Noticed a few issues with parrec2nii.

-The help says that scaling=dv is the default but I don't think this is the case. No argument versus dv produce different image values

-With respect to the scaling again it says that the values in the image aren't changed, but only the scaling saved in the header. I think it would be better to change the values because most image processing toolboxes ignore the header scaling values and operate on the data.

matthew-brett commented 9 years ago

I do get the same answer with no scaling option specified on the command line, and with --scaling=dv. Can you put an image somewhere that doesn't give the same answer in these cases?

I can imagine that it's useful to be able to apply the scaling in the image, to make floating point values in the nifti. Of course you can do that in nibabel:

img = nib.load('converted.nii')
new_img = nib.Nifti1Image(img.dataobj, img.affine, img.header)
new_img.set_data_dtype(np.float32)
nib.save(new_img, 'converted_tofloat.nii')

Still - it would be nice to have a command line option to do this as part of the conversion, maybe an --apply-scaling option or similar. Would you consider submitting a PR for that?

It's strange that there are still packages out there not using the scalefactors in the NIfTI format - they have been there since the beginning of the format. For Analyze format, that is much more common.

matthew-brett commented 9 years ago

Hi Jason - would you mind checking the scaling= option - just to check we don't (any longer) have this bug?

matthew-brett commented 9 years ago

I guess https://github.com/nipy/nibabel/issues/321 relates, because we could solve both of your cases with an out-dtype flag. Although, it seems neater to me to do that in a little post-script processing.