<div dir="ltr">Gotcha. <div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 16, 2016 at 8:53 AM, Fernando Pérez-García <span dir="ltr"><<a href="mailto:fepegar@gmail.com" target="_blank">fepegar@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:tahoma,sans-serif">Hi Ariel,</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">data.shape is (5256, 3216, 3) at that point.</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">If I do just</div><div style="font-family:tahoma,sans-serif"><div style="font-family:arial,sans-serif;font-size:12.8px">nii = nib.Nifti1Image(data, np.eye(4))</div><span style="font-family:arial,sans-serif;font-size:12.8px">nib.save(nii, p.replace('png', 'nii')),</span></div><div style="font-family:tahoma,sans-serif"><span style="font-family:arial,sans-serif;font-size:12.8px"><br></span></div><div style="font-family:tahoma,sans-serif"><span style="font-family:arial,sans-serif;font-size:12.8px">I'll get a 3D nifti image with three slices, with one value per pixel. I want a 2D nifti image with one slice, three values per pixel. I do accomplish what I want with my code, but it's not very efficient. Do you think I should ask in the NumPy or SciPy mailing list?</span></div></div></blockquote><div><br></div><div>You can certainly ask on these lists as well -- lots of knowledgable people there. </div><div><br></div><div>In the meanwhile, here's what I have managed to dig up on SO. Something along these lines might work: </div><div><br></div><div><a href="http://stackoverflow.com/a/10016379/3532933" target="_blank">http://stackoverflow.com/a/10016379/3532933</a></div><div><br></div><div>But I don't have the full solution quite yet.</div><div><br></div><div>Ariel</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:tahoma,sans-serif"><span style="font-family:arial,sans-serif;font-size:12.8px"></span></div><div style="font-family:tahoma,sans-serif"><span style="font-family:arial,sans-serif;font-size:12.8px"><br></span></div><div style="font-family:tahoma,sans-serif"><span style="font-family:arial,sans-serif;font-size:12.8px">Cheers,</span></div><div style="font-family:tahoma,sans-serif"><span style="font-family:arial,sans-serif;font-size:12.8px"><br></span></div><div style="font-family:tahoma,sans-serif"><span style="font-family:arial,sans-serif;font-size:12.8px">Fernando</span></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2016-02-16 17:46 GMT+01:00 Ariel Rokem <span dir="ltr"><<a href="mailto:arokem@gmail.com" target="_blank">arokem@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi Fernando, <div><br></div><div>Just trying to understand what you are trying to achieve: </div><div class="gmail_extra"><br><div class="gmail_quote"><span>On Tue, Feb 16, 2016 at 8:44 AM, Fernando Pérez-García <span dir="ltr"><<a href="mailto:fepegar@gmail.com" target="_blank">fepegar@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:tahoma,sans-serif">Hi Paulo,</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">Thanks for your response. It seems that <span style="font-size:12.8px;font-family:arial,sans-serif">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.</span></div><div style="font-family:tahoma,sans-serif"><span style="font-size:12.8px;font-family:arial,sans-serif"><br></span></div><div style="font-family:tahoma,sans-serif"><span style="font-size:12.8px;font-family:arial,sans-serif"><br></span></div><div style="font-family:tahoma,sans-serif"><span style="font-size:12.8px;font-family:arial,sans-serif">Cheers,</span></div><div style="font-family:tahoma,sans-serif"><span style="font-size:12.8px;font-family:arial,sans-serif"><br></span></div><div style="font-family:tahoma,sans-serif"><span style="font-size:12.8px;font-family:arial,sans-serif">Fernando</span></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2016-02-16 17:32 GMT+01:00 paulo rodrigues <span dir="ltr"><<a href="mailto:khamael@gmail.com" target="_blank">khamael@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi Fernando,<div><br></div><div>Did you have a look at ants? It has some tools for that kind of operations: check ConvertScalarImageToRGB</div><div><br></div><div>Cheers,</div><div>Paulo</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Tue, Feb 16, 2016 at 5:05 PM, Fernando Pérez-García <span dir="ltr"><<a href="mailto:fepegar@gmail.com" target="_blank">fepegar@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div><div dir="ltr"><div style="font-family:tahoma,sans-serif">Dear Nibabel experts,</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">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?</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">My code:</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><div>import numpy as np</div><div>import Image</div><div>import nibabel as nib</div><div><br></div></div><div><div><font face="tahoma, sans-serif">p = '/home/fernando/test/nii_rgb/TC1.png'</font></div><div><font face="tahoma, sans-serif">im = Image.open(p)</font></div><div><font face="tahoma, sans-serif"><br></font></div><div><font face="tahoma, sans-serif">data = np.array(im)</font></div><div><font face="tahoma, sans-serif">data = np.rot90(data)</font></div></div></div></div></div></blockquote></div></div></blockquote></div></div></div></div></blockquote><div><br></div></span><div>What is `data.shape` at this point? </div><div><br></div><div>Why wouldn't the following work? </div><div><br></div><div> nii = nib.Nifti1Image(data, np.eye(4))</div><span><div> nib.save(nii, p.replace('png', 'nii'))</div><div><br></div></span><div>Cheers, </div><span><font color="#888888"><div><br></div><div>Ariel </div></font></span><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div><div dir="ltr"><div><div><font face="tahoma, sans-serif">rgb = np.zeros((data.shape[0], data.shape[1], 1, 1), [('R', 'u1'), ('G', 'u1'), ('B', 'u1')])</font></div><div><font face="tahoma, sans-serif"><br></font></div><div><font face="tahoma, sans-serif">for i in range(data.shape[0]):</font></div><div><font face="tahoma, sans-serif"> for j in range(data.shape[1]):</font></div><div><font face="tahoma, sans-serif"> rgb[i, j] = tuple(data[i, j, :])</font></div><div><font face="tahoma, sans-serif"><br></font></div><div><font face="tahoma, sans-serif">nii = nib.Nifti1Image(rgb, np.eye(4))</font></div><div><font face="tahoma, sans-serif">nib.save(nii, p.replace('png', 'nii'))</font></div></div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">Thanks in advance,</div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">Fernando</div></div>
<br></div></div>_______________________________________________<br>
Neuroimaging mailing list<br>
<a href="mailto:Neuroimaging@python.org" target="_blank">Neuroimaging@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/neuroimaging" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/neuroimaging</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
Neuroimaging mailing list<br>
<a href="mailto:Neuroimaging@python.org" target="_blank">Neuroimaging@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/neuroimaging" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/neuroimaging</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Neuroimaging mailing list<br>
<a href="mailto:Neuroimaging@python.org" target="_blank">Neuroimaging@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/neuroimaging" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/neuroimaging</a><br>
<br></blockquote></span></div><br></div></div>
<br>_______________________________________________<br>
Neuroimaging mailing list<br>
<a href="mailto:Neuroimaging@python.org" target="_blank">Neuroimaging@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/neuroimaging" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/neuroimaging</a><br>
<br></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Neuroimaging mailing list<br>
<a href="mailto:Neuroimaging@python.org" target="_blank">Neuroimaging@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/neuroimaging" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/neuroimaging</a><br>
<br></blockquote></div><br></div></div>