[Neuroimaging] RGB Nifti

Fernando Pérez-García fepegar at gmail.com
Tue Feb 16 11:44:18 EST 2016


Hi Paulo,

Thanks for your response. It seems that ConvertScalarImageToRGB reads a
gray nifti and makes an RGB nifti (using ITK) with a certain colormap. The
image I'm reading is a PNG file already RGB, as you can see in my code, so
I think ANTS won't help here.


Cheers,

Fernando

2016-02-16 17:32 GMT+01:00 paulo rodrigues <khamael at gmail.com>:

> Hi Fernando,
>
> Did you have a look at ants? It has some tools for that kind of
> operations: check ConvertScalarImageToRGB
>
> Cheers,
> Paulo
>
> On Tue, Feb 16, 2016 at 5:05 PM, Fernando Pérez-García <fepegar at gmail.com>
> wrote:
>
>> Dear Nibabel experts,
>>
>> I'm trying to create an RGB nifti image from a PNG file. I've been
>> messing around with a working RGB nifti, in order to mimic the datatype
>> found in its header. So far I've managed to convert the image pixel-wise
>> with for loops, which is very slow. Do you know how this could be done in a
>> faster way?
>>
>>
>> My code:
>>
>> import numpy as np
>> import Image
>> import nibabel as nib
>>
>> p = '/home/fernando/test/nii_rgb/TC1.png'
>> im = Image.open(p)
>>
>> data = np.array(im)
>> data = np.rot90(data)
>> rgb = np.zeros((data.shape[0], data.shape[1], 1, 1), [('R', 'u1'), ('G',
>> 'u1'), ('B', 'u1')])
>>
>> for i in range(data.shape[0]):
>>     for j in range(data.shape[1]):
>>         rgb[i, j] = tuple(data[i, j, :])
>>
>> nii = nib.Nifti1Image(rgb, np.eye(4))
>> nib.save(nii, p.replace('png', 'nii'))
>>
>>
>>
>> Thanks in advance,
>>
>> Fernando
>>
>> _______________________________________________
>> 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/20160216/e4c94838/attachment.html>


More information about the Neuroimaging mailing list