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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic rotation or perspective correction using camera metadata #17384

Open
rl-king opened this issue Aug 27, 2024 · 6 comments
Open

Automatic rotation or perspective correction using camera metadata #17384

rl-king opened this issue Aug 27, 2024 · 6 comments

Comments

@rl-king
Copy link

rl-king commented Aug 27, 2024

Some Leica cameras have a feature called "Perspective control", which automatically corrects the perspective or keystone distortion. Article with pictures here. This is directly applied to in-camera jpg files, and for raw files the data is stored in the camera metadata. Which looks like:

Xmp.xmpDSA.Version                           XmpText     5  1.0.0
Xmp.xmpDSA.CorrectionAlreadyApplied          XmpText     4  True
Xmp.xmpDSA.PitchAngle                        XmpText    12  0.9129999876
Xmp.xmpDSA.RollAngle                         XmpText    12  1.2159999608
Xmp.xmpDSA.FocalLength35mm                   XmpText    13  50.0000000000
Xmp.xmpDSA.TargetAspectRatio                 XmpText    12  1.5000000000
Xmp.xmpDSA.ScalingFactorHeight               XmpText    12  0.9687359333
Xmp.xmpDSA.ValidCropCorners                  XmpText     4  True
Xmp.xmpDSA.ApplyAutomatically                XmpText     4  True
Xmp.xmpDSA.NormalizedCropCorners             XmpSeq      8  0.0106867747, 0.0314993262, 0.9756190180, 0.0007762801, 0.9929105639, 0.9690485000, 0.0208023600, 1.0000000000

I could not find any documentation or information if this data is used by darktable, but it would be nice to be able to. It could even just be used for rotation.

Let me know if I can provide any other information or image samples.

@jenshannoschwalm
Copy link
Collaborator

Unfortunately those exiv tags are not documented for "how to apply" so no chance without Leica help.

@rl-king
Copy link
Author

rl-king commented Aug 28, 2024

I can't find anything online either, just some basic value type information. What docs or specification do we need from Leica to be able to use these values?

@jenshannoschwalm
Copy link
Collaborator

The maths. :-)

@pehar1
Copy link

pehar1 commented Aug 29, 2024

All the nice numbers that are stored in the Xmp.xmpDSA tags are parameters that are used in a proprietary algorithm from Leica to correct the image data. I don't know of any manufacturer that has ever made its algorithms public. The only way would be backwards engineering, involving a lot of work and time.

@Donatzsky
Copy link

The numbers seem fairly "sensible". Enough so that I suspect it shouldn't be too hard. Mostly a question of figuring out the coordinate system. Try to create a thread over on discuss.pixls.us with several samples (raw + corrected jpeg + exif). Many of the regulars there are good with math.

@Donatzsky
Copy link

Xmp.xmpDSA.PitchAngle                        XmpText    12  0.9129999876
Xmp.xmpDSA.RollAngle                         XmpText    12  1.2159999608

I guess that if the camera is perfectly level, then both pitch and roll would 1.

Xmp.xmpDSA.TargetAspectRatio                 XmpText    12  1.5000000000

Can you set the camera to record in different aspect ratios? And does this change accordingly?

Xmp.xmpDSA.ScalingFactorHeight               XmpText    12  0.9687359333

Don't actually know anything about keystone correction algorithms, but presumably this is to correct for distortion caused by straightening the trapezoid or to fit the aspect ratio.

Xmp.xmpDSA.ValidCropCorners                  XmpText     4  True

Is it possible to get False here?

Xmp.xmpDSA.NormalizedCropCorners             XmpSeq      8  0.0106867747, 0.0314993262, 0.9756190180, 0.0007762801, 0.9929105639, 0.9690485000, 0.0208023600, 1.0000000000

This appears to be the corners of the trapezoid, with the coordinates going from 0 to 1. Wouldn't be surprised if each number is just a multiplication factor applied to the pixel dimensions.

At a minimum, the following sample shots are needed:

  • A shot where the camera is perfectly level, or at least level enough that the correction isn't triggered.
  • One pointing up left.
  • One up right.
  • One down left.
  • One down right.

All shots should be done in both horizontal and vertical orientation, so ten total. Raw + camera JPEG.

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

4 participants