Skip to content

Correctly apply PNG palette when building ImageBase through Pillow. #14326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented May 25, 2019

PR Summary

Closes #14293.
A test would be nice but I would prefer not adding a test image (as usual), so I'd need to think more about the best way to do it. In the meantime, the fact that this closes #14293 can be checked manually...

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label May 25, 2019
@anntzer anntzer added this to the v3.1.1 milestone May 25, 2019
@tacaswell
Copy link
Member

Ah, that makes a lot more sense that my guess of pulling off just one of the channels.

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to merge this without a test.

@@ -667,6 +667,13 @@ def set_data(self, A):
----------
A : array-like
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add here that this now also accepts a PIL.Image.Image type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, PIL images are array-likes (in the sense that asarray, for example, works on them).

Copy link
Member

@timhoffm timhoffm May 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, from a practical point of view, most places we use array-like do not reasonably take PIL images (even if they sometimes technically could). For the few places of dedicated image-related stuff, I would be explicit and use array-like or PIL.Image.Image. Not every user will know that an PIL Image is technically an array-like).

Side-remark: In case somebody is interested in the technical definition of numpys usage of array-like: https://stackoverflow.com/questions/40378427/numpy-formal-definition-of-array-like-objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough, edited accordingly

@anntzer anntzer force-pushed the pillowpngpalette branch from ebe1fb2 to 28cd6ec Compare May 26, 2019 22:00
@jklymak
Copy link
Member

jklymak commented May 26, 2019

If this had a test we would have caught it breaking in the first place.

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonus if adding a test.

The test could be a direct comparison between calls with (M, N, 3) data and a PIL image.

@anntzer anntzer force-pushed the pillowpngpalette branch from 28cd6ec to 4adb996 Compare May 27, 2019 09:47
@anntzer
Copy link
Contributor Author

anntzer commented May 27, 2019

Sure... added a test, and found #14340 at the same time...

@anntzer anntzer force-pushed the pillowpngpalette branch from 4adb996 to 5873efb Compare May 27, 2019 10:11
axs[0].imshow(PIL.Image.open(png_path))
axs[1].imshow(PIL.Image.open(tiff_path))
axs = fig_ref.subplots(2)
axs[0].imshow(plt.imread(str(png_path)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - why is this "str" here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because imread() doesn't support Path inputs for png only.

@jklymak jklymak merged commit 89db355 into matplotlib:master May 27, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request May 27, 2019
@anntzer anntzer deleted the pillowpngpalette branch May 27, 2019 13:51
timhoffm added a commit that referenced this pull request May 27, 2019
…326-on-v3.1.x

Backport PR #14326 on branch v3.1.x (Correctly apply PNG palette when building ImageBase through Pillow.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

imshow() producing "inverted" colors since 3.0.3
5 participants