|
From: <jor...@ya...> - 2009-05-16 22:58:33
|
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? jorge |
|
From: Jae-Joon L. <lee...@gm...> - 2009-05-17 04:15:50
|
On Sat, May 16, 2009 at 6:58 PM, <jor...@ya...> 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. For imshow (and other similar commands), use the origin keyword. e.g., >>> imshow(a, origin="lower") http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.imshow -JJ > > jorge > > > > > > ------------------------------------------------------------------------------ > Crystal Reports - New Free Runtime and 30 Day Trial > Check out the new simplified licensing option that enables > unlimited royalty-free distribution of the report engine > for externally facing server and web deployment. > http://p.sf.net/sfu/businessobjects > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |
|
From: Pauli V. <pa...@ik...> - 2009-05-17 12:00:11
|
Sun, 17 May 2009 00:15:48 -0400, Jae-Joon Lee wrote: > On Sat, May 16, 2009 at 6:58 PM, > <jor...@ya...> 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__ -- Pauli Virtanen |
|
From: Jae-Joon L. <lee...@gm...> - 2009-05-18 04:07:41
|
>
> 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__
>
> --
> 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
|
|
From: John H. <jd...@gm...> - 2009-05-18 17:48:40
|
On Sun, May 17, 2009 at 11:07 PM, Jae-Joon Lee <lee...@gm...> 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. JDH |
|
From: Andrew S. <str...@as...> - 2009-05-18 18:10:47
|
John Hunter wrote:
> On Sun, May 17, 2009 at 11:07 PM, Jae-Joon Lee <lee...@gm...> 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
|