[Numpy-discussion] asarray() and PIL

Stéfan van der Walt stefan@sun.ac...
Wed May 27 10:19:20 CDT 2009


2009/5/27 cp <lubensch.proletariat.inc@gmail.com>:
> img=Image.open('something.tif')
> img.size
> (1900,1600)
>
> then
>
> arr=asarray(img)
> arr.shape
> (1600,1900,3)
>
> This means that the array-image has 1600 color channels, 1900 image pixel rows
> and 3 image pixel columns. Why is that?

No, it means that you have 1600 rows, 1900 columns and 3 colour channels.

> if I reshape with
>
> arr.reshape(3,1900,1600)
>
> will there be a mix-up in pixel values and coordinates when compared to the
> initial PIL image?

You'll have to use np.rollaxis(img, -1) to get the shape you want.

Regards
Stéfan


More information about the Numpy-discussion mailing list