pytorch / vision

Datasets, Transforms and Models specific to Computer Vision
https://pytorch.org/vision
BSD 3-Clause "New" or "Revised" License
15.99k stars 6.92k forks source link

Extracting custom EXIF data from PNG files #8348

Open frank690 opened 5 months ago

frank690 commented 5 months ago

🚀 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 commented 5 months ago

@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 commented 5 months ago

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.