BUG: Consistently apply color palettes by default #955
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
xref: scikit-image/scikit-image#6764 revealed that ImageIO is not behaving consistently when decoding images that use a color palette. GIFs have their palette applied by default; however, other formats (like PNG) don't.
This is a regression from the old pillow plugin, and while paletted images that aren't GIF are fairly rare in practice, we should still behave consistently and avoid surprising behavior. Hence, this PR updates the pillow plugin to apply palettes by default. The (raw) index data can still be read by passing
mode="P"
.This PR also updates how the color palette is exposed as part of the metadata. (1) Since we apply a color palette by default, we should (by default) exclude it from the metadata. This PR changes that behavior and aligns the plugin to the documented API. (2) It changes the returned value from a
PIL.ImagePalette.ImagePalette
to anp.ndarray
. This should make interacting with and inspecting the palette much easier in the future.