vision icon indicating copy to clipboard operation
vision copied to clipboard

torchvision.io.read_image support processing EXIF information in JPEG file

Open kero-ly opened this issue 2 years ago • 7 comments

🚀 The feature

In #7947, I found that torchvision.io.read_image will not process the EXIF information in JPEG file. I'm wondering if PyTorch will consider supporting processing EXIF information in the future versions?

Motivation, pitch

I have millions of images in my project, some JPEG files have orientation tag in EXIF information. If I use torchvision.io.read_image to read them directly, the model accuracy seems not good enough since some images have the wrong orientation.

I want to ask if PyTorch will provide a convenient way to process the orientation tag?

Alternatives

No response

Additional context

No response

kero-ly avatar Sep 19 '23 09:09 kero-ly

Thanks for opening this issue @kero-ly .

From https://github.com/pytorch/vision/issues/7947#issuecomment-1733310035 it looks like PIL and torchvision provide the same output dimensions (they agree on H and W, despite different conventions) and seem to ignore the EXIF information.

I guess we could add support for that... as a bug fix? But the fact that PIL ignores it as well makes me wonder whether there's something we're missing here. Any thought @pmeier @vfdev-5 ?

NicolasHug avatar Sep 25 '23 09:09 NicolasHug

the fact that PIL ignores it as well makes me wonder whether there's something we're missing here

Maybe this is intentional on PILs side? If so, we should not "fix" this behavior on our side since we align with PIL. I'm ok with adding a flag like process_exif: bool = False to read_image to enable this if the user wants it.

pmeier avatar Sep 25 '23 12:09 pmeier

@pmeier @NicolasHug , can I try to work on this? (i.e. adding a flag like process_exif: bool = False to read_image to enable this if the user wants it ?)

Zekrom-7780 avatar Nov 07 '23 11:11 Zekrom-7780

Sure, go ahead @Zekrom-7780!

pmeier avatar Nov 07 '23 12:11 pmeier

Hello, are there updates regarding this feature? I recently switched to torchvision.io.read_image() from PIL to take advantage of libjpeg-turbo (making PIL to use libjpeg-turbo instead of libjpeg is not so straightforward). With PIL, I could use ImageOps.exif_transpose() to apply EXIF orientation info, but this is currently not possible with torchvision. This feature would be very useful for me. FYI, OpenCV will apply EXIF orientation by default.

gau-nernst avatar Jan 26 '24 02:01 gau-nernst

@gau-nernst @kero-ly I'll be working on this feature, could you please provide few examples with exif data with defined orientation to test on. Thanks.

vfdev-5 avatar Jan 29 '24 13:01 vfdev-5

@vfdev-5 I found some samples here: https://github.com/recurser/exif-orientation-examples

For example, the one below needs to be rotated clock-wise.

wget https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_6.jpg

For testing against PIL, I use this

from PIL import Image, ImageOps

img = Image.open("path.jpg")
img = ImageOps.exif_transpose(img)

My browser (Edge) also seems to display all the samples from https://github.com/recurser/exif-orientation-examples correctly.

gau-nernst avatar Jan 29 '24 13:01 gau-nernst