Skip to content
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

Extend the supported types of decodePNG #2984

Merged
merged 4 commits into from
Nov 10, 2020

Conversation

datumbox
Copy link
Contributor

@datumbox datumbox commented Nov 10, 2020

Fixes #2823

This PR adds support of RGB with transparency, grayscale, grayscale with transparency and palette to the decodePNG() method. To test the changes we reuse the test_decode_png() unit-test and we add additional data. The test compares for differences between reading data from PIL vs torchvision.io.image.

The following script was used to produce the additional images required for the test:

from PIL import Image

# manually downloaded from https://pytorch.org/assets/images/pytorch-logo.png
original = 'pytorch-logo.png'
path = 'rgbalpha_pytorch.png'
with Image.open(original) as img:
    img = img.convert("RGBA")
    img = img.resize((100, 100)) 
    img.save(path)

with Image.open(path) as img:
    img = img.convert("P", palette=Image.ADAPTIVE, colors=32) 
    img.save("pallete_pytorch.png")

with Image.open(path) as img:
    img = img.convert("L") 
    img.save("gray_pytorch.png")

with Image.open(path) as img:
    img = img.convert("LA") 
    img.save("grayalpha_pytorch.png")

with Image.open(path) as img:
    img = img.convert("RGB") 
    img.save("rgb_pytorch.png")

Notes:

  • To avoid any licensing issues, we use the pytorch logo.
  • The images are shrunk to 100x100 pixels to keep their total size less than 4kb.
  • The use of real images allows us to reuse existing tests. It also allows for easier manual inspection/visualization.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

Looks great, thanks a lot!

@fmassa fmassa merged commit 78159d6 into pytorch:master Nov 10, 2020
@datumbox datumbox deleted the feature/read_image_pngtypes branch November 10, 2020 15:12
bryant1410 pushed a commit to bryant1410/vision-1 that referenced this pull request Nov 22, 2020
* Add support of different color types in readpng.

* Adding test images and unit-tests.

* Use closest possible type.

* Fix formatting.
vfdev-5 pushed a commit to Quansight/vision that referenced this pull request Dec 4, 2020
* Add support of different color types in readpng.

* Adding test images and unit-tests.

* Use closest possible type.

* Fix formatting.
@datumbox datumbox mentioned this pull request Jan 5, 2021
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support paletted images for io.image.read_image
3 participants