[Image-SIG] Image.getdata()? [PIL]

William Ryu wsryu@fas.harvard.edu
Tue, 20 Feb 2001 07:57:51 -0500


<html>
<font size=3>Hello:<br>
<br>
I have a question about PIL's Image.getdata() method. The manual
states:<br>
<br>
<b>getdata()</b>. Returns the contents of a the image as a sequence
object containing pixel values. The sequence object is flattened, so that
values for line one follows directly after the values for line zero, and
so on. <br>
<br>
But when I tested this this does not seem to be the case. My test image
is a TIFF file with a simple black line (value = 0) on a white background
(255). The code below doesn't return the correct data array. The zeros
are all in the wrong places, and from their jumbled pattern it doesn't
seem to be a simple swapping of the axes.<br>
<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>im =
Image.open('test.tif')<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>size =
im.size<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>data =
im.getdata()<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>flatarray
= array(flatdata)<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>return
reshape(flatarray, size)<br>
<br>
Im.show() works just fine however. It's late, so I'm hoping that I'm not
missing the obvious, but isn't this how getdata() should work?<br>
<br>
Would appreciate some help. thanks,<br>
<br>
-willryu</font></html>