-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
Ah, that makes a lot more sense that my guess of pulling off just one of the channels. |
There was a problem hiding this 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.
lib/matplotlib/image.py
Outdated
@@ -667,6 +667,13 @@ def set_data(self, A): | |||
---------- | |||
A : array-like |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough, edited accordingly
If this had a test we would have caught it breaking in the first place. |
There was a problem hiding this 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.
Sure... added a test, and found #14340 at the same time... |
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))) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…ng ImageBase through Pillow.
…326-on-v3.1.x Backport PR #14326 on branch v3.1.x (Correctly apply PNG palette when building ImageBase through Pillow.)
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