Skip to content

PNG images not being deinterlaced by read_image #4252

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

Closed
ConradStack opened this issue Aug 4, 2021 · 1 comment · Fixed by #4268
Closed

PNG images not being deinterlaced by read_image #4252

ConradStack opened this issue Aug 4, 2021 · 1 comment · Fixed by #4268

Comments

@ConradStack
Copy link

🐛 Bug

Interlaced PNG files are not de-interlaced when loaded by read_image.

To Reproduce

Steps to reproduce the behavior:

  1. Download test image (attached):
# download image
wget https://imagemagick.org/image/wizard.png

# create interlaced version using imagemagick 
convert -strip -interlace PNG wizard.png wizard-interlaced.png

# print imagemagick version info
convert -version

Version: ImageMagick 7.1.0-2 Q16 x86_64 2021-06-25 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP(5.0)
Delegates (built-in): bzlib fontconfig freetype gslib heic jng jp2 jpeg lcms lqr ltdl lzma openexr png ps tiff webp xml zlib

  1. Compare read_image to PIL.Image.open
import numpy as np
from PIL import Image
from torchvision.io import read_image, ImageReadMode
from torchvision.transforms import ToPILImage

# Using PIL:
pil_notinterlaced = Image.open("wizard.png")
pil_interlaced = Image.open("wizard-interlaced.png")
# PASS
assert np.all( np.asarray(pil_notinterlaced) == np.asarray(pil_interlaced) ), "differences btw interlaced and non-interlaced images loaded with PIL"


# Using torchvision:
tv_notinterlaced = read_image("wizard.png")
tv_interlaced = read_image("wizard-interlaced.png")

# PASS
assert tv_notinterlaced.shape == tv_interlaced.shape, "not the same shape"

# FAIL
assert (tv_notinterlaced == tv_interlaced).all(), "differences btw interlaced and non-interlaced images loaded with torchvision"

# ... (for manual comparison) convert the interlaced image tensor to PIL and save
topil = ToPILImage()
topil(tv_interlaced).save("wizard-interlaced-savedfromtv.png")

wizard.png:
drawing

wizard-interlaced.png:
drawing

wizard-interlaced-savedfromtv.png:
drawing

Expected behavior

Using read_image to load an interlaced PNG image would automatically de-interlace it.

Environment

Collecting environment information...
PyTorch version: 1.9.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 11.4 (x86_64)
GCC version: Could not collect
Clang version: 12.0.0 (clang-1200.0.32.2)
CMake version: version 3.17.3
Libc version: N/A

Python version: 3.8.8 (default, Feb 24 2021, 13:46:16)  [Clang 10.0.0 ] (64-bit runtime)
Python platform: macOS-10.16-x86_64-i386-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.21.0
[pip3] torch==1.9.0
[pip3] torchtext==0.10.0
[pip3] torchvision==0.10.0
[conda] blas                      1.0                         mkl  
[conda] ffmpeg                    4.3                  h0a44026_0    pytorch
[conda] mkl                       2021.3.0           hecd8cb5_517  
[conda] mkl-service               2.4.0            py38h9ed2024_0  
[conda] mkl_fft                   1.3.0            py38h4a7008c_2  
[conda] mkl_random                1.2.2            py38hb2f4e1b_0  
[conda] numpy                     1.21.0                   pypi_0    pypi
[conda] numpy-base                1.20.3           py38he0bd621_0  
[conda] pytorch                   1.9.0                   py3.8_0    pytorch
[conda] torchtext                 0.10.0                     py38    pytorch
[conda] torchvision               0.10.0                 py38_cpu    pytorch

Additional context

I reproduced the issue handling interlaced PNGs on a linux machine running centos 7 w/ similar python specs and using other interlaced PNG images that had not been converted by imagemagick.

@fmassa
Copy link
Member

fmassa commented Aug 9, 2021

Thanks for the report!

We will look into it and fix this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants