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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting custom EXIF data from PNG files #8348

Open
frank690 opened this issue Mar 21, 2024 · 2 comments
Open

Extracting custom EXIF data from PNG files #8348

frank690 opened this issue Mar 21, 2024 · 2 comments

Comments

@frank690
Copy link

frank690 commented Mar 21, 2024

馃殌 The feature

Being able to use torchvision.io.read_image(...) to read PNG files alongside the custom metadata stored in the exchangeable image file format (EXIF).

Motivation, pitch

I am training different deep learning models and some of them rely on custom metadata stored in EXIF inside PNG files.
Currently I have to do

from PIL import Image

with Image.open(file_path) as image:
    image.load()

  if image.format == "TIFF":
      metadata = image.getexif()[37510]  # 0x9286
  else:  # png
      metadata = image.text

but would much rather just ditch PIL.Image and do

from torchvision.io import read_image

image, metadata = read_image(file_path, read_metadata=True)

Alternatives

No response

Additional context

No response

Edit

added case distinction between TIFF and PNG files

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Mar 21, 2024

@frank690 thansk for the feature request. Can you please share what kind of exif metadata you are interested in and for what purpose? Recently, we added auto orientation from exif application to read_image to transform the input image according to existing exif info.

@frank690
Copy link
Author

You are right, EXIF data mainly stores information about the camera and/or image in their different tags.
But there is - for example - also a tag called UserComment with the ID 0x9286.
In my use-case I train on image data and the labels are provided within this specific tag.
So while reading the image I also want to retreive said tag.

I updated the above code example to include the TIFF file-type case.

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

No branches or pull requests

2 participants