Question about imshow

Sun, 17 May 2009 00:15:48 -0400, Jae-Joon Lee wrote:

Hi,
I want to read images and do some processing with them. While learning
how to do this, i.e. opening images, displaying them, transforming them
tu numpy arrays, etc., I came across a strange behaviour. If I open an
image and use imshow() to display it, it comes upside down. See this
thread in the numpy mailing list for more details:
http://thread.gmane.org/gmane.comp.python.numeric.general/30148 .
Someone on that list suggested to check here if this behavior was
correct. Is it normal that the image appears upside down? If yes, can
someone explain what's going on?

Note that the image may be upside down for you but may be correct for
others. The array itself does not know about the orientation of the
image and you have to explicitly specify this.

I think the point here is that

  img = Image('foo.png')
  imshow(img)

and

  img = Image('foo.png')
  imshow(asarray(img))

give different results, since matplotlib.image.pil_to_array functions
differently from what PIL exposes in __array_interface__

···

On Sat, May 16, 2009 at 6:58 PM, > <jorgesmbox-ml@...1664...> wrote:

--
Pauli Virtanen

I think the point here is that

   img = Image\(&#39;foo\.png&#39;\)
   imshow\(img\)

and

   img = Image\(&#39;foo\.png&#39;\)
   imshow\(asarray\(img\)\)

give different results, since matplotlib.image.pil_to_array functions
differently from what PIL exposes in __array_interface__

--
Pauli Virtanen

I see. Thanks for clarifying this. And yes, I think this should be fixed.

Hmm, it seems that somehow pil_to_array tries to make the image
upside-down by itself.

        x_str = im.tostring('raw',im.mode,0,-1)

However. I'm afraid that changing this behavior may not be ideal for
backward-compatibility.

I think one possible solution would be to simply deprecate the support
for PIL image in imshow, and let users explicitly use array-interface
via asarray function.

Is there any other idea?
I'll make this change unless someone come up with something.

-JJ

I'm not wild about removing the PIL functionality entirely just to
remove an inconsistency. Andrew wrote the PIL support -- perhaps he
can comment.

JDH

···

On Sun, May 17, 2009 at 11:07 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

I think one possible solution would be to simply deprecate the support
for PIL image in imshow, and let users explicitly use array-interface
via asarray function.

Is there any other idea?
I'll make this change unless someone come up with something.

John Hunter wrote:

I think one possible solution would be to simply deprecate the support
for PIL image in imshow, and let users explicitly use array-interface
via asarray function.

Is there any other idea?
I'll make this change unless someone come up with something.

I'm not wild about removing the PIL functionality entirely just to
remove an inconsistency. Andrew wrote the PIL support -- perhaps he
can comment.

I wouldn't remove PIL support in imshow immediately, either, but I think
deprecation should be OK. Since Image->numpy conversion is now happening
through the array interface, I don't think there's much call to support
PIL directly anymore. We should make the deprecation warning give the
appropriate hint ("In the future, 'imshow(pil_image)' will not be
supported. Use 'imshow(np.array(pil_image))' instead. Note that you may
need an origin='upper' keyword argument for the latter case.")

-Andrew

···

On Sun, May 17, 2009 at 11:07 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote: