Lens correction model

From PanoTools.org Wiki
Revision as of 17:09, 17 December 2005 by Erik Krause (talk | contribs) (rewritten)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Lens correction model

The panorama tools have very flexible model to correct for typical geometrical lens errors. Even better, it can estimate the correction parameters under certain conditions.

There are a total of 6 parameters that have to do with lens correction.

  • First of all there is the lens Field of View (FoV) - not exactly an error, but a parameter that determines the image perspective distortion.
  • The actual lens correction parameters a, b and c which are used to correct for barrel distortion, pincushion distortion and even wavy distortion.
  • The lens shift parameters d and e that correct for the lens optical axis not beeing in the image center.

Two more parameters correct for image errors that are not induced by the lens but by a scanner or scanning camera for example. The shear parameters f and g.

Field of View

The Focal Length is a physical property of the lens. Together with the effective sensor or film size and the focusing distance it determines the image Field of view. Caution: Cropping the image changes the Field of View. If you need to crop your source images for a panorama, crop them all to the same size!

The Field of View together with the lens projection (rectilinear, fisheye or cylindrical for swing lens cameras) determine the image perspective distortion. Perspective distortion is the smaller the smaller the Field of View is. See Helmut Dersch page [ttp://www.path.unimelb.edu.au/~dersch/perspective/Wide_Angle_Perspective.html] for details about different wide angle perspective.

Lens distortion a, b & c parameters

The lens distortion a, b and c parameters correspond to a fourth-order polynomial describing radial lens distortion:

r_src = a*r_dest^4 + b*r_dest^3 + c*r_dest^2 + d*r_dest

where r_dest and r_src refer to the normalized radius of an image pixel. Normalized means here that the radius oft the largest circle that completely fits into an image is set to 1.0 (or in other words: It is half the smaller side of the image).

Usual values for a, b and c are below 1.0, in most cases below 0.01. Too high values suggest that you choose a wrong lens type, f.e. fisheye instead of rectlinear or vice versa. This refers to the absolute values of course since a, b and c can be positive or negative (f.e. both 4.5 and -4.5 are considered too high values)

The fourth parameter (d) is only available in the Correct, Radial Shift filter of the Panorama Tools Plugins. It controls the result image size and is calculated implicit by pano12 (used by PTOptimizer, PTStitcher and the GUIs) in order to keep the same image size:

d = 1-(a+b+c)

Hence it is not available in the different GUI front-ends (you can see it in the PTOptimizer result script).

Unfortunately the parameter d refers to image shift in PTStitcher and PTOptimizer scripts and the GUIs what sometimes causes confusion. More see below.

This polynomial approach is never exact, but can give a pretty good approximation to the real behaviour of a given lens. If you need better correction you must use a distortion matrix, as used by Distortion Remove (see link below).

Lens or image shift d & e parameters

Sometimes a lens or an image sensor might not be centered to each other. In this case the optical axis doesn't hit the image center. This is particularly the case for scanned images where you never can say whether the film is centered on the scanner or not.

If the above lens correction algorithm is used on such images both lens correction and perspective correction work on the wrong center point. The lens shift parameters d (horizontal shift) and e (vertical shift) compensate for that problem. They contain values in pixel units which determine how the center for correction is shifted outside the geometrical image center.

Image shear f & g parameters

Image shear is no lens distortion but nevertheless part of the panotools lens correction model. It corrects for a distortion induced by scanners or scanning cameras that causes a rectangular image beeing sheard to the form of a parallelogram (one side of the images is shifted parallel to the opposite side)

Determine lens correction

a, b, c and FoV are physical properties of a lens/camera-combination at a given focus distance. Since if you always shoot at infinity or hyperfocal distance you can savely reuse the parameters.

There are a number of ways to determine the a, b, c and fov parameters for a particular lens/camera combination:

  • Taking two or more overlapping photographs and selecting lots of normal control points, then optimising roll, pitch, yaw, fov, a, b & c. This technique works with any output projection format but rquires parallax free images shot exactly from the Nodal Point. Note that to get a really accurate measure of the field of view, you have to take a full 360 degree panorama.
  • Using a tool such as PTLens or clens to read the JPEG EXIF data and correct the image automatically by looking up the lens in an existing database.

Optimize for lens correction

If you optimize for lens correction in order to f.e. calibrate your lens you should keep some facts in mind:

Since lens correction parameters are determined by evaluating the distortion at different radiuses you should provide enough control points at different radiuses.

  • If you use a rectangular pattern for that task, make sure you set control points in all distances from the center.
  • If you use two or more images make sure you overlap regions with large potential distortion (f.e. the corners) with regions with low possible distortion (f.e. the center). An only horizontal overlap would do, but use at least 50% in order to overlap the image center of one image with the border of the other.

a, b and c parameters influence Field of View, especially for images in landscape orientation but slightly for portrai oriented ones, too. This is because although the implicit calculation of the fourth polynomial parameter tries to keep the image at the same size, this is only possible along the radius r_src = 1.0.

Outside this radius, especially in the image corners the size and hence the Fild of View might differ. This is why you should always allow the optimization for FoV too, if you optimize for a, b and c with more than one image. (You can not optimize for FoV with only one image). As noted above you need a full 360 degree panorama in order to get an accurate measure of the field of view.

The a and c parameters control more complex forms of distortion. In most cases it will be enough to optimize for the b parameter only.

If you want to see how changing the parameters influences distortion correction go to http://www.4pi.org/downloads/ and get abc.xls. Don't deactivate macros on loading.

See also Helmut Dersch's barrel distortion page.

Tools to correct barrel and pincushion distortion

  • The original PTStitcher can be scripted to batch process images with known a, b & c parameters. It can also be operated with one of the GUI front-ends.
  • PTLens is a Photoshop plugin and a stand-alone Windows tool that uses the same a, b & c parameters and comes with a database of popular lenses.
  • CamChecker is a tool for automatically determining lens distortion and generates a different set of parameters from everything else.