[Neuroimaging] [nibabel] Issue when saving nifti files
Sulantha Sanjeewa
sulantha.s at gmail.com
Fri Jun 3 12:32:36 EDT 2016
Hi Ariel,
Thanks a lot for helping me to figure this out. In fact, I used nii2mnc to
convert the image to MINC before viewing the final image.
You are correct. The problem is with that conversion, not from nibabel. I
viewed the image with fslview and the image looks as expected.
Thanks a lot, sorry to bother you with this.
Best regards,
Sulantha.
On Fri, Jun 3, 2016 at 11:38 AM, Ariel Rokem <arokem at gmail.com> wrote:
> Hi Sulantha,
>
> Thanks for getting in touch. Let's see if I can be helpful.
>
> On Fri, Jun 3, 2016 at 7:11 AM, Sulantha Sanjeewa <sulantha.s at gmail.com>
> wrote:
>
>> 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')
>>
>>
> I am not seeing this when I run your code (
> https://gist.github.com/arokem/7f996b56d8f7e17ae8377677314a25ad). I also
> find that whole range of values in the file you processed and provided (try
> running those two last cells on your file). What are you doing to check the
> values in "I300779_m.nii"? Maybe the software reading this file downstream
> is doing something funny?
>
> Cheers,
>
> Ariel
>
>
>> _______________________________________________
>> Neuroimaging mailing list
>> Neuroimaging at python.org
>> https://mail.python.org/mailman/listinfo/neuroimaging
>>
>>
>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20160603/df599e5e/attachment.html>
More information about the Neuroimaging
mailing list