Skip to content

Extracting custom EXIF data from PNG files #8348

Open
@frank690

Description

@frank690

🚀 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions