Lens correction model

From PanoTools.org Wiki
(Difference between revisions)
Jump to: navigation, search
(rewritten)
m (a little cleanup and add minor details)
Line 1: Line 1:
 
== Lens correction model ==
 
== 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.
+
The panorama tools have a 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.  
 
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.  
 
* 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 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.
+
* The lens shift parameters '''d''' and '''e''' that correct for the lens [[optical axis]] not being 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'''.
+
Two more parameters correct for image errors that are not induced by the lens but by a scanner or scanning camera for example. These are the shear parameters '''f''' and '''g'''.
  
 
=== Field of View ===
 
=== Field of View ===
Line 14: Line 14:
 
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 [[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 Projection|rectilinear]], [[Fisheye Projection|fisheye]] or [[Cylindrical Projection|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.
+
The Field of View together with the lens projection ([[Rectilinear Projection|rectilinear]], [[Fisheye Projection|fisheye]] or [[Cylindrical Projection|cylindrical]] for swing lens cameras) determine the image [[perspective distortion]]. Perspective distortion is less with a smaller Field of View. See Helmut Dersch page [http://www.path.unimelb.edu.au/~dersch/perspective/Wide_Angle_Perspective.html] for details about different wide angle perspectives.
  
 
=== Lens distortion a, b & c parameters ===
 
=== Lens distortion a, b & c parameters ===
  
The [[lens distortion]] '''a''', '''b''' and '''c''' parameters correspond to a fourth-order polynomial describing radial lens distortion: <pre>r_src = a*r_dest^4 + b*r_dest^3 + c*r_dest^2 + d*r_dest</pre> 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).
+
The [[lens distortion]] '''a''', '''b''' and '''c''' parameters correspond to a fourth-order polynomial describing radial lens distortion: <pre>r_src = a*r_dest^4 + b*r_dest^3 + c*r_dest^2 + d*r_dest</pre> where '''r_dest''' and '''r_src''' refer to the normalized radius of an image pixel. Normalized means here that the largest circle that completely fits into an image is said to have radius=1.0 (In other words, radius=1.0 is half the smaller side of the image.) A perfect lens would have simply r_src = r_dest, so the factor (a*r_dest^3 + b*r_dest^2 + c*r_dest + d) is often called a '''cubic correction polynomial'''.
  
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)
+
Usual values for '''a''', '''b''' and '''c''' are below 1.0, in most cases below 0.01. Too high values suggest that you chose a wrong lens type, f.e. fisheye instead of rectilinear 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 [[Panorama Tools Plugins#Radial_Shift|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: <pre>d = 1-(a+b+c)</pre> Hence it is not available in the different [[GUI front-ends]] (you can see it in the PTOptimizer result script).
+
The fourth parameter ('''d''') is only available in the [[Panorama Tools Plugins#Radial_Shift|Correct, Radial Shift]] filter of the [[Panorama Tools Plugins]]. It controls the result image size and is calculated implicitly by [[pano12]] (used by PTOptimizer, PTStitcher and the GUIs) in order to keep the same image size: <pre>d = 1-(a+b+c)</pre> 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.
+
Unfortunately a different parameter also named '''d''' refers to image shift in PTStitcher and PTOptimizer scripts and the GUIs.  This sometimes causes confusion. (See more discussion 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).  
 
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).  
Line 30: Line 30:
 
=== Lens or image shift d & e parameters ===
 
=== 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.
+
Sometimes a lens and 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.
 
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.
Line 36: Line 36:
 
=== Image shear f & g parameters ===
 
=== 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)
+
Image shear is not a [[lens distortion]] but nevertheless is part of the panotools lens correction model. It corrects for a distortion induced by scanners or scanning cameras that causes a rectangular image being sheared to the form of a parallelogram (one side of the images is shifted parallel to the opposite side)
  
 
=== Determine lens correction ===
 
=== 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 [[Depth of Field#Hyperfocal_distance|hyperfocal distance]] you can savely reuse the parameters.
+
'''a''', '''b''', '''c''' and '''FoV''' are physical properties of a lens/camera-combination at a given focus distance. If you always shoot at the same focus setting, f.e. infinity or [[Depth of Field#Hyperfocal_distance|hyperfocal distance]], then you can safely reuse the parameters.  At a different focus setting, '''FoV''' will change noticeably, but usually it is ok to reuse '''a''', '''b''', and '''c''' even then.
  
 
There are a number of ways to determine the a, b, c and [[field of view|fov]]
 
There are a number of ways to determine the a, b, c and [[field of view|fov]]
 
parameters for a particular lens/camera combination:
 
parameters for a particular lens/camera combination:
 +
 +
* Taking a single photograph of a subject containing straight lines, defining one or more sets of straight line control points (types t3, t4, etc.), and optimising for just a, b, c.  You need to set the output format to [[Rectilinear Projection]] for this technique to work.  This method is used by the author of [[PTLens]].
  
 
* Taking a single photograph of a rectangular object, selecting lots of horizontal and vertical control points, then optimising [[roll]], [[pitch]], [[yaw]], [[field of view|fov]], a, b & c. You need to set the output format to [[Rectilinear Projection]] for this technique to work.  The process is similar to this [http://hugin.sourceforge.net/tutorials/architectural/ hugin architectural tutorial]:
 
* Taking a single photograph of a rectangular object, selecting lots of horizontal and vertical control points, then optimising [[roll]], [[pitch]], [[yaw]], [[field of view|fov]], a, b & c. You need to set the output format to [[Rectilinear Projection]] for this technique to work.  The process is similar to this [http://hugin.sourceforge.net/tutorials/architectural/ hugin architectural tutorial]:
  
* Taking two or more overlapping photographs and selecting lots of normal control points, then optimising [[roll]], [[pitch]], [[yaw]], [[field of view|fov]], a, b & c. This technique works with any output [[Projections|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.
+
* Taking two or more overlapping photographs and selecting lots of normal control points, then optimising [[roll]], [[pitch]], [[yaw]], [[field of view|fov]], a, b & c. This technique works with any output [[Projections|projection format]] but requires [[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.
 
* 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.
Line 55: Line 57:
 
If you optimize for lens correction in order to f.e. calibrate your lens you should keep some facts in mind:  
 
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.  
+
Since lens correction parameters are determined by evaluating the distortion at different radius values you should provide enough control points at different radii.  
* If you use a rectangular pattern for that task, make sure you set control points in all distances from the center.  
+
* If you use a rectangular pattern or straight lines 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.
 
* 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.  
+
'''a''', '''b''' and '''c''' parameters influence [[Field of View]], especially for images in landscape orientation but slightly for portrait 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]].
+
Outside this radius, especially in the image corners the size and hence the Field 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 cannot 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.
 
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.
Line 75: Line 77:
 
* [[nona]] or [[nona_gui]] (both part of the [[hugin]] distribution) can be used identically to [[PTStitcher]].
 
* [[nona]] or [[nona_gui]] (both part of the [[hugin]] distribution) can be used identically to [[PTStitcher]].
  
* The [[Panorama_Tools_Plugins#Radial_Shift|Correct Radial Shift]] filter in the [[Panorama Tools Plugins]] for the [[gimp]] or [[photoshop]] uses the same a, b & c parameters as [[PTStitcher]].  Note that it doesn't know about d & e parameters and uses 'd' as an overall scaling factor instead, which should be d = 1-(a+b+c) to keep the image roughly the same size. If you need to shift the correction center like with the d & e parameter you must combine it with [[Panorama_Tools_Plugins#Vertical_Shift_.26_Horizontal_Shift|Vertical Shift]] and/or [[Panorama_Tools_Plugins#Vertical_Shift_.26_Horizontal_Shift|Horizontal Shift]].
+
* The [[Panorama_Tools_Plugins#Radial_Shift|Correct Radial Shift]] filter in the [[Panorama Tools Plugins]] for the [[gimp]] or [[photoshop]] uses the same a, b & c parameters as [[PTStitcher]].  Note that it doesn't know about d & e shift parameters and uses 'd' as an overall scaling factor instead, which should be d = 1-(a+b+c) to keep the image roughly the same size. If you need to shift the correction center like with the d & e parameter you must combine it with [[Panorama_Tools_Plugins#Vertical_Shift_.26_Horizontal_Shift|Vertical Shift]] and/or [[Panorama_Tools_Plugins#Vertical_Shift_.26_Horizontal_Shift|Horizontal Shift]].
  
 
* [[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.
 
* [[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.

Revision as of 19:30, 17 December 2005

Contents

Lens correction model

The panorama tools have a 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 being 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. These are 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 less with a smaller Field of View. See Helmut Dersch page [1] for details about different wide angle perspectives.

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 largest circle that completely fits into an image is said to have radius=1.0 . (In other words, radius=1.0 is half the smaller side of the image.) A perfect lens would have simply r_src = r_dest, so the factor (a*r_dest^3 + b*r_dest^2 + c*r_dest + d) is often called a cubic correction polynomial.

Usual values for a, b and c are below 1.0, in most cases below 0.01. Too high values suggest that you chose a wrong lens type, f.e. fisheye instead of rectilinear 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 implicitly 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 a different parameter also named d refers to image shift in PTStitcher and PTOptimizer scripts and the GUIs. This sometimes causes confusion. (See more discussion 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 and 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 not a lens distortion but nevertheless is part of the panotools lens correction model. It corrects for a distortion induced by scanners or scanning cameras that causes a rectangular image being sheared 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. If you always shoot at the same focus setting, f.e. infinity or hyperfocal distance, then you can safely reuse the parameters. At a different focus setting, FoV will change noticeably, but usually it is ok to reuse a, b, and c even then.

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

  • Taking a single photograph of a subject containing straight lines, defining one or more sets of straight line control points (types t3, t4, etc.), and optimising for just a, b, c. You need to set the output format to Rectilinear Projection for this technique to work. This method is used by the author of PTLens.
  • 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 requires 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 radius values you should provide enough control points at different radii.

  • If you use a rectangular pattern or straight lines 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 portrait 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 Field 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 cannot 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.
Personal tools
Namespaces

Variants
Actions
Navigation
tools
Tools