That is some weird mojo; I'm guessing that numpy simply doesn't  
recognize the 'LA' type (luminance+alpha) as it's pretty uncommon. In  
the meantime you probably want to convert to RGBA, since that file  
giving you problems is grayscale+alpha channel, and a conversion to  
RGB might lose the alpha channel.

  FWIW that's pretty much what matplotlib does, see  
matplotlib.image.pil_to_array which does the conversion fine.

David

On 7-Jul-09, at 8:07 PM, Nicolas Pinto wrote:

> Dear all,
>
> For some reason I have a problem converting a specific png image  
> using array().
>
> Here is what I am getting (using numpy 1.3.0 and scipy 0.7.0).
>
> % wget http://files.getdropbox.com/u/167753/spiky_adj_023.png
> % python -c "import numpy as np; import Image; print  
> np.array(Image.open('spiky_adj_023.png'))"
> <PngImagePlugin.PngImageFile instance at 0xd1a050>
>
> % wget http://files.getdropbox.com/u/167753/spiky_norm_001.png
> % python -c "import numpy as np; import Image; print  
> np.array(Image.open('spiky_norm_001.png'))"
> [[134  30 140 ..., 230  83  59]
>  [ 99 202 233 ..., 160  63 133]
>  [ 93 241  35 ...,   7 240 101]
>  ...,
>  [206 132 196 ..., 139 190 112]
>  [218  21 217 ..., 121 152 109]
>  [ 83 188 187 ...,   6 240 251]]
>
>
> I was initially using scipy's misc.imread when I found this bug. I  
> am currently using the following workaround:
> % python -c "import numpy as np; import Image; print  
> np.array(Image.open('spiky_adj_023.png').convert('RGB'))"
>
> Let me know what you think.
>
> Thanks in advance.
>
> Sincerely,
>
> -- 
> Nicolas Pinto
> Ph.D. Candidate, Brain & Computer Sciences
> Massachusetts Institute of Technology, USA
> http://web.mit.edu/pinto
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to