• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Restore photo orientation

Enthusiast ,
Apr 14, 2018 Apr 14, 2018

Copy link to clipboard

Copied

I needed to restore the orientation to a bunch of photos, and I couldn't find anything about this (admittedly, with a brief search). So here is recipe in case others need to do it.

Ingredients:

Lightroom Classic

Jeffrey's Data Explorer Plugin

Phil Harvey's exiftool

John Ellis' AnyFilter Plugin (optional)

When you import photos into Lightroom, they are oriented according to metadata that the camera adds to the photo. One place this is recorded is the Orientation EXIF field. I am using Canon cameras, and some of my cameras, but not all, also record this data in the Camera Orientation field. (Confusingly, the Camera Orientation doesn't have a "Rotate 180" value.)

Values for the Orientation Field are:

1 = Horizontal (normal)

2 = Mirror horizontal

3 = Rotate 180

4 = Mirror vertical

5 = Mirror horizontal and rotate 270 CW

6 = Rotate 90 CW

7 = Mirror horizontal and rotate 90 CW

8 = Rotate 270 CW

The data explorer plugin can be used to restore a photo to "sensor orientation", but it can't be used to figure out the original camera orientation.

The first thing is to restore all of the photos to "sensor orientation." Use Data Explorer to break your photos up into collections depending on the "Orientation with Respect to Image Sensor", and then rotate the photos in each collection appropriately (if they are rotated 90° CW, apply a 90° CCW rotation, etc.)

The next thing to do is to find the original orientation. If all of your photos have the "Camera Orientation" metadata, it seems that you can use the Any Filter plugin to find them, which is quite straightforward. E.g., do a search for "Aggregate Text" "Searchable EXIF" "contains" "Rotate 90 CW". However, my photos from my old Canon 1Ds don't have the "Camera Orientation" metadata, and it seems that Any Filter can't search on the "Orientation" metadata (probably because the values of Orientation are integers, not strings).

So I used the following command in exiftool to set a subject keyword according to the original orientation:

  % cd <the folder with all your photos in it>​

  % exiftool '-subject+<$orientation' -ext xmp -overwriteoriginalinplace .

This sets a keyword that is derived from the value of the orientation field for the sidecar files in the directory. (Replace "xmp" with "TIFF", "psd", etc to change those file types). Be careful, the "-overwriteoriginalinplace" flag will do exactly that -- make sure you have a backup before doing this command.

Now you just need to read the metadata in Lightroom, and sort by the keyword values and restore the camera's suggested orientation.

Hope this helps.

A

Views

4.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 14, 2018 Apr 14, 2018

Copy link to clipboard

Copied

I don't think your recipe works in the case when LR has saved metadata back to the photos.  Here's a straightword but tedious method that just involves just Any Filter or just Data Explorer.

First, some background. There are three different places the orientation of a photo can be stored:

- EXIF:Orientation is set by most cameras.  LR will overwrite this field when you do Metadata > Save Metadata To File or you have set the option Catalog Settings > Metatadata > Automatically Write Changes Into XMP.

- EXIF MakerNotes may have an orientation field set by the camera. E.g. some Canons and Sonys store MakerNotes:CameraOrientation. LR doesn't read or write this field.

- The LR catalog's Orientation field contains the current orientation of the photo within LR. It is initialized on import from EXIF:Orientation but changes when you do Photo > Rotate Right / Left.

Next, there are two different cases to consider, each with a different recipe:

A. LR hasn't written metadata back to the photos with Save Metadata To File or Automatically Write Changes.

1. Reset all photos back to 0 degrees rotation (horizontal / landscape). Use Any Filter with the criterion "Orientation = 90" to find all photos with 90 degrees rotation, and then use Photo > Rotate Left to rotate them back to 0.  Then use Any Filter to find all photos with 180 degrees and rotate them twice.  Similarly for 270 degrees.

2. Set the rotation of all photos to that set by the camera  (still stored in EXIF:Orientation). Use Any Filter with the criterion "ExifTool Field = Rotate 90 CW | Orientation" to find all photos rotated 90 degrees by the camera.  Use Photo > Rotate Right to rotate those photos back to 90 degrees.  Then repeat for "Rotate 180" and "Rotate 270 CW".

B. LR has written metadata back to photos with Save Metadata To File or Automatically Write Changes. In this case, you'll only be able to restore the camera rotation for those cameras that have also stored the rotation in a Makernotes field (e.g.  Canon's Makernotes:CameraOrientation), since LR has overwritten the original EXIF:Orientation field set by the camera.

1. Find all photos that have a MakerNotes:CameraOrientation field. Use Any Filter with the criterion "ExifTool Field isn't empty | CameraOrientation".

2. Reset the rotation of all the photos from step 1 to 0 degrees (horizontal / landscape). Use Any Filter with the criterion "Orientation = 90" to find all photos with 90 degrees rotation, and then use Photo > Rotate Left to rotate them back to 0.  Then use Any Filter to find all photos with 180 degrees and rotate them twice.  Similarly for 270 degrees..

3. Set the rotation of all photos from step 1 to that set by the camera  (still stored in MakerNotes:CameraOrientation). Use Any Filter with the criterion "ExifTool Field = Rotate 90 CW | CameraOrientation" to find all photos rotated 90 degrees by the camera.  Use Photo > Rotate Right to rotate those photos back to 90 degrees.  Then repeat for "Rotate 180" and "Rotate 270 CW".

------------------

You can use a similar recipe with Data Explorer, which also lets you search ExifTool fields.

Finally, note that this recipe omits the case of mirroring (flipping photos in LR horizontally or vertically).  The same general approach works -- first identify and undo LR-applied mirroring, then identify and undo LR-applied rotation.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 15, 2018 Apr 15, 2018

Copy link to clipboard

Copied

Hi John

I hadn't realized that Any Filter had an orientation filter, I see now how it works. This means, as you say, that I can accomplish my goal with just your plugin. Thanks for the recipes.

I don't know why you think that Lightroom writes the Orientation field when you synchronize metadata. In my experience (sample size ~6,000 photos in one catalog with "Automatically write metadata changes" on), it does not. In any event, even if it did, for raw files the original value would be available in the raw file. (For others following this conversation, Lightroom does not, in general, write changes to raw files, but only to the xmp sidecar.)

If it is the case that Lightroom has changed the data in the .xmp sidecar, you can add the flag

    % exiftool <flags>  -ext xmp -tagsFromFile %f.CR2 <directory>

which will read the flags from the corresponding .CR2 file but operate on the .xmp file.

I have not experimented with non-raw file formats. Again, if you save your dngs, TIFFs, psds and jpgs with the same name as the raw files, and put them in the same directory, the -tagsFromFile trick can be used.

Again, thanks for your awesome plugin.

A

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 15, 2018 Apr 15, 2018

Copy link to clipboard

Copied

I don't know why you think that Lightroom writes the Orientation field when you synchronize metadata.

Try the experiment: Pick a non-raw photo, rotate it, and do Metadata > Save Metadata To File. Then do

exiftool -exif:orientation file

and observe that EXIF:Orientation has changed.

For raws, the orientation is written to the sidecar (in XMP:Orientation), not to the raw. So as you hinted and I neglected to realize, for raws you can always recover the original camera orientation by reading EXIF:Orientation from the raw.  But for non-raws, if LR has written metadata back to the file, you'll need a manufacturer-specific MakerNotes field to recover the original orientation.

Thus, the conditions for my two recipes are a little different:

A. The photos are either raw, or for non-raws, LR hasn't written metadata back to the photos with Save Metadata To File or Automatically Write Changes.

B. The photos are non-raws and LR has written metadata back to photos with Save Metadata To File or Automatically Write Changes.

The actual recipes for A and B remain the same. (The Any Filter ExifTool criterion always reads metadata from the raw file, not its sidecar.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 15, 2018 Apr 15, 2018

Copy link to clipboard

Copied

Something strange was going on with my computer. I see the behavior you describe now. (Scratching my head in puzzlement).

A

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

I have just the raw files and I want to change the orientation of them in the metadata by 180° degrees. How can I do this?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

"I have just the raw files and I want to change the orientation of them in the metadata by 180° degrees. How can I do this?"

 

When you rotate a raw in LR and then do Metadata > Save Metadata To File, it creates a .xmp sidecar containing the new orientation metadata field. 

 

If that's not what you want, and you instead want to write the orientation back to the raw file itself, rather than a sidecar, you can't do that in LR.  LR never (well, almost never) changes raw files. 

 

If you want to do something different, please explain in more detail.

 

[Use the blue reply button under the first post to ensure replies sort properly.]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

Also, if you do indeed want to change the orientation field of the raw photo itself, you'll need to use another app, such as the free ExifTool.

 

[Use the blue reply button under the first post to ensure replies sort properly.]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 06, 2020 Jun 06, 2020

Copy link to clipboard

Copied

Hi johnrellis

and thank you for the reply. Yes indeed I want to change the orientation inside the metadata of the original rawfiles. I made a bunch of pictures of the same mnotive with two different cameras. The two cameras were orientated in different way. So one camera turned the picture 90° CW and the other 90° CCW. In Lightroom all seems to be correct, but I cannot sync the transformation tools because LR will rotate the information by 180°. 

I guess I first need to erase the information regarding orientation the cameras wrote to the raw files and then I can sync properly.....?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 06, 2020 Jun 06, 2020

Copy link to clipboard

Copied

I just saw that you replied also to the other feed. Sorry for posting in two feeds! I understand that within LR it is not possible to do this. Could you please tell me how to do it with ExifTool?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 06, 2020 Jun 06, 2020

Copy link to clipboard

Copied

[This post contains embedded images that don't appear in email. View the post in your Web browser to see the images.]

 

"The two cameras were orientated in different way. So one camera turned the picture 90° CW and the other 90° CCW. In Lightroom all seems to be correct, but I cannot sync the transformation tools because LR will rotate the information by 180°.  I guess I first need to erase the information regarding orientation the cameras wrote to the raw files and then I can sync properly.....?"

 

Unfortunately, deleting the EXIF:Orientation from the raw photos before you import them into LR won't help in this situation.  Suppose you did that. Then when you imported the photos, one would appear rotated 180 degrees from the other, e.g.

Untitled.png

 

If you first applied Transform tool settings to one photo and then copied/synced them to the other photo, they would appear in the same position in the photo, but that's not what you want -- you'd want the transform settings to be rotated 180 degrees to match the content of the second photo.

 

[Use the blue reply button under the first post to ensure replies sort properly.]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 06, 2020 Jun 06, 2020

Copy link to clipboard

Copied

Exactly. So if I cannot change it in LR, I need to 'rotate' the EXIF of the files?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 06, 2020 Jun 06, 2020

Copy link to clipboard

Copied

Changing the field EXIF:Orientation outside of LR using ExifTool and then importing into LR is exactly the same as applying the Photo > Rotate Left/Right and Photo > Flip Horizontal/Vertical commands inside of LR.  You'll still trip over the bug, because LR represents the coordinates of local adjustments, crops, and transforms relative to the photo before the EXIF:Orientation tag is applied.

 

So the rule is: copying local adjustments, crops, and transforms only works if the source and target photos all have the same EXIF:Orientation tag.

 

The only workaround is to import the raws into LR, rotate them so they appear correctly orientated, export them in a non-raw format (e.g. TIFF, PSD, or JPEG), reimport those into LR, and then copy the adjustments between those. (Those exported/reimported photos will all have EXIF:Orientation = 0.)

 

[Use the blue reply button under the first post to ensure replies sort properly.]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 07, 2020 Jun 07, 2020

Copy link to clipboard

Copied

LATEST

Ok. I will have to do it this way. Thank you for your help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines