0

I am using PIL to enhance my images. While saving I need both the geographic coordinates and the orientation angles written to the header of the enhanced image. So far I have failed find a way to write the orientation angles.

I could write the coordinates using piexif after reading Preserve exif data of image with PIL when resize(create thumbnail). But this seems not enough to write the orientation also, or maybe I am missing something.

    im = Image.open(direc + '\\' + filename)
    exif_dict = piexif.load(im.info["exif"])
    exif_bytes = piexif.dump(exif_dict)

    enhancer = ImageEnhance.Brightness(im)
    enhanced_im = enhancer.enhance(1.8)
    enhanced_im.save(s + 'enhanced\\' + directory + "\e_" + filename, "JPEG", exif=exif_bytes)

When I print my exif_dict I see two main keys 0th and Exif (with reasonable key-value pairs under each of them and a lot of \x00\x00\x00q\x00\x00\x00g\x00\x00\x00r\x00\x00\x00l\x00\x00\x0... such characters which continues even after the parenthesis of the dictionary has ended. Please advise.

Avishek Dutta
  • 97
  • 2
  • 11

1 Answers1

1

You could write a world file for every image: https://en.wikipedia.org/wiki/World_file

Create a text file, calculate the values, write them in the text file and add the corresponding extension to the file name.

EDIT: If you need to change the exif values I would recommend looking at the tags which already are in the exif data and change/add the orientation tag (How to modify EXIF data in python). If you search for exif orientation tag on google, you can find the explanation of the values. They are also explained on this page https://sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html. This page also explains how to change the orientation https://magnushoff.com/jpeg-orientation.html.

Hopefully it helps.

Jan-Pieter
  • 137
  • 2
  • 10
  • This won't be enough as I need to read in the images into a Bundle Block adjustment software and it only accesses the Exif for the necessary information. – Avishek Dutta Aug 30 '19 at 13:20
  • @AvishekDutta did it help? – Jan-Pieter Sep 03 '19 at 12:08
  • yes. It let to the workaround of writing out all the coordinates and orientation into a csv and then reading in the enhanced images, without orientation, only with whatever dump dumps in the header, along with the csv. The duplicate info does not create any conflict and the software reads the orientations from the csv correctly. Thanks! – Avishek Dutta Sep 05 '19 at 11:17