← 输入框|github.com|刷新
Skip to content

RGB image is flipped a different way depending on whether it is PNG or JPG #101

Closed

Description

@astrofrog

If I run the following example

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1,2,1)
image = plt.imread('2mass_rgb.png')
ax.imshow(image, origin='upper', extent=[0.5,723.5,0.5,724.5])

ax = fig.add_subplot(1,2,2)
image = plt.imread('2mass_rgb.jpg')
ax.imshow(image, origin='upper', extent=[0.5,723.5,0.5,724.5])

fig.savefig('rgb.png')

the left and right hand subplots show the RGB image flipped a different way. This does not happen if I use PIL to read in the image using Image.open, so presumably it is a bug in imread? The files I am using can be found here.

Activity

  1. mdboom commented on Apr 29, 2011

    @mdboom
    Member

    JPG loading is handled through PIL, and the pil_to_array code explicitly flips the image upside down. This seems like a bug, but I'm hesitant to fix it since it's been that way for at least 3 years in a commit by @jdh2358 -- I'm surprised we're just finding it now -- and this isn't an area I'm terribly familiar with.

    diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py
    index f2d9984..93402d4 100644
    --- a/lib/matplotlib/image.py
    +++ b/lib/matplotlib/image.py
    @@ -1257,7 +1257,7 @@ def pil_to_array( pilImage ):
         """
         def toarray(im):
             'return a 1D array of floats'
    -        x_str = im.tostring('raw',im.mode,0,-1)
    +        x_str = im.tostring()
             x = np.fromstring(x_str,np.uint8)
             return x
     
  2. leejjoon commented on May 1, 2011

    @leejjoon
    Contributor

    I think the thread below is related with this issue. I don't think we actually made any action though.

    http://old.nabble.com/Question-about-imshow-ts23578564.html

  3. ghost assigned on Jun 15, 2011
  4. ghost assigned on Jun 20, 2011
  5. mdboom commented on Jun 20, 2011

    @mdboom
    Member

    Changing assignment to Andrew, since I don't quite understand the history and backward incompatibility issues.

  6. stefanv commented on Sep 19, 2011

    @stefanv
    Contributor

    I can verify that this is a bug. Here's the much simplified version we use in scikits.image:

    https://github.com/scikits-image/scikits.image/blob/master/scikits/image/io/_plugins/pil_plugin.py#L12

  7. mdboom commented on Jun 1, 2012

    @mdboom
    Member

    I believe this is fixed by #616.

  8. pelson commented on Jun 10, 2012

    @pelson
    Member

    I can confirm that this was fixed 5 days ago.

  9. mdboom commented on Jun 11, 2012

    @mdboom
    Member

    Just a note: as this is a pretty significant backward-incompatible change, it is only on master, and won't be in the 1.1.2rc.

  10. added a commit that references this issue on Dec 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions