Skip to content

PIL-opened image and imread-opened image render slightly differently in classic mode #14340

Open
@anntzer

Description

@anntzer

Bug report

Bug summary

Per the title.

Code for reproduction

from pathlib import Path
import matplotlib as mpl
from matplotlib.testing.compare import compare_images
from matplotlib import pyplot as plt, style
from PIL import Image

mpl.use("agg")
mpl.style.use("classic")

path = str(Path(mpl.__file__).parent / "tests/baseline_images/pngsuite/basn3p04.png")

fig = plt.figure()
fig.subplots().imshow(plt.imread(path))
fig.savefig("1.png")
fig = plt.figure()
fig.subplots().imshow(Image.open(path))
fig.savefig("2.png")
print(compare_images("1.png", "2.png", tol=0))

Actual outcome

Error: Image files did not match.
  RMS Value: 0.010865337342004415
  Expected:  
    1.png
  Actual:    
    2.png
  Difference:
    2-failed-diff.png
  Tolerance: 
    0

Expected outcome

No diff.

I think this may possibly(???) be due to rounding errors when imread converts from 0-255 (uint8) to 0-1 (float) and then imshow converts back to 0-255 (uint8)?

Note that this does not occur when using the mpl20 default style.

Matplotlib version

  • Operating system: linux
  • Matplotlib version: master
  • Matplotlib backend (print(matplotlib.get_backend())): agg
  • Python version: 3.7
  • Jupyter version (if applicable):
  • Other libraries:

Metadata

Metadata

Assignees

No one assigned

    Labels

    keepItems to be ignored by the “Stale” Github Actiontopic: images

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions