torchvision.io.read_image support processing EXIF information in JPEG file
🚀 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
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 ?
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 @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 ?)
Sure, go ahead @Zekrom-7780!
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 @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 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.