auromat.util.lensdistortion module

This module provides functions to extract camera and lens information from EXIF data and correct lens distortion using the lensfunpy library.

exception auromat.util.lensdistortion.CameraNotFoundInDBError[source]

Bases: exceptions.Exception

exception auromat.util.lensdistortion.CameraNotFoundInEXIFError[source]

Bases: exceptions.Exception

exception auromat.util.lensdistortion.LensNotFoundInDBError[source]

Bases: exceptions.Exception

exception auromat.util.lensdistortion.LensNotFoundInEXIFError[source]

Bases: exceptions.Exception

auromat.util.lensdistortion.correctLensDistortion(imagePath, undistImagePath, lensfunDbObj=None, mod=None, exiftoolObj=None, preserveExif=True, **saveImageKws)[source]

Correct lens distortion of an image using its EXIF headers and the lensfun library. If the camera or lens are not found in the lensfun database, an exception is raised.

Parameters:
  • undistImagePath – path to output image; folders must already exist!
  • exiftoolObj – if not None, use the given exiftool object (must have nums=False)
  • lensfunDbObj – if not None, use the given lensfun.Database object
  • mod – if not None, use this Modifier instead of calling getLensfunModifier() Note: lensfunDbObj is not used in this case.
Raises:
  • ValueError – when lens wasn’t found in EXIF data
  • CameraNotFoundInDBError – when the camera wasn’t found in lensfun database
  • LensNotFoundInDBError – when the lens wasn’t found in lensfun database
auromat.util.lensdistortion.findCameraAndLens(imagePath, lensfunDbObj=None, exiftoolObj=None, retTags=False, minAcceptedScore=100)[source]

Finds camera and lens from EXIF data.

Note: The lensfunDbObj reference must be kept as long as the returned camera and lens objects shall be used. Once lensfunDbObj gets garbage collected, the camera and lens objects get unusable (as their underlying C objects get freed).

auromat.util.lensdistortion.findCameraAndLensFromExif(tags, lensfunDbObj=None, minAcceptedScore=100, raiseIfNotFoundInDB=True)[source]
auromat.util.lensdistortion.getLensfunModifier(imagePath, width=None, height=None, lensfunDbObj=None, exiftoolObj=None, distance=10000)[source]

See getLensfunModifierFromExif() for a WARNING on not setting width and height.

auromat.util.lensdistortion.getLensfunModifierFromExif(tags, width=None, height=None, lensfunDbObj=None, distance=10000)[source]

WARNING: Not setting width and height may produce surprising results for RAW files. If width and height are not set, then Composite:ImageSize is used. This tag contains the full RAW size, but many RAW decoders produce slightly cropped images. Therefore it may be necessary to first decode the RAW image and determine the width and height directly.

Parameters:tags (dict) – must contain ‘EXIF:Model’, ‘EXIF:Make’, ‘Composite:LensID’, ‘EXIF:FocalLength’, ‘Composite:Aperture’ and optionally ‘Composite:ImageSize’ if width,height is None
auromat.util.lensdistortion.getLensfunModifierFromParams(model, params, width, height)[source]
Parameters:
  • model (str) – ‘ptlens’, ‘poly3’, or ‘poly5’
  • params (list) – a list of 1, 2 or 3 parameters, depending on the model
  • width – image width in pixels
  • height – image height in pixels
auromat.util.lensdistortion.lensDistortionPixelDistances(imagePath=None, mod=None, lensfunDbObj=None, exiftoolObj=None, retH=False)[source]

Return the difference between the distances from the image center to the distorted and undistorted pixel locations.

See correctLensDistortion() for parameters.

Return type:ndarray of shape (h,w)
auromat.util.lensdistortion.lensfunXML(model, *params)[source]

Return XML in lensfun DB format for the specified distortion profile.