[Neuroimaging] [nibabel] Issue when saving nifti files

Sulantha Sanjeewa sulantha.s at gmail.com
Fri Jun 3 10:11:59 EDT 2016


Dear all,
I am having trouble saving nifti files using nibabel. This is a simple load
- mask - save situation. However, when I save, the resultant image is only
two values [min and max] of the original image (almost like a mask). Can
you help me on this. I have added the code here. and a link to the three
files as well.
Thanks a lot for the help.
Best regards,
Sulantha.

Files Link: https://drive.google.com/open?id=0B-TWCTRv7UM1a0hxaWotbjRSSUE
Code:

img = nibabel.load('I300779.nii')
imgData = img.get_data()
mask = nibabel.load('FullBrain.nii')
maskData = mask.get_data()
maskedImgData = imgData[maskData>0.9]
new_image = numpy.zeros(maskData.shape)
new_image[maskData>0.9] = maskedImgData
aff = mask.affine
nibabel.save(nibabel.Nifti1Image(new_image, aff), 'I300779_m.nii')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20160603/50bd762c/attachment.html>


More information about the Neuroimaging mailing list