Correctly apply PNG palette when building ImageBase through Pillow.#14326
Conversation
|
Ah, that makes a lot more sense that my guess of pulling off just one of the channels. |
tacaswell
left a comment
There was a problem hiding this comment.
I am happy to merge this without a test.
| @@ -667,6 +667,13 @@ def set_data(self, A): | |||
| ---------- | |||
| A : array-like | |||
There was a problem hiding this comment.
Could add here that this now also accepts a PIL.Image.Image type?
There was a problem hiding this comment.
Technically, PIL images are array-likes (in the sense that asarray, for example, works on them).
There was a problem hiding this comment.
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.
fair enough, edited accordingly
|
If this had a test we would have caught it breaking in the first place. |
timhoffm
left a comment
There was a problem hiding this comment.
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.
Looks good - why is this "str" here?
There was a problem hiding this comment.
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