Login or Create Account

Using Distortion

   My Account  |  Cart Contents  |  Checkout   
Introduction Instructions Results Main figure Decentering Corrected image Intersection figure Radius correction fig Links Algorithm
See Also
Tour Distortion
Related
Distortion (van Walree)
New in Imatest 2.7.1  Distortion can now analyze square (checkerboard) patterns.

Imatest 2.3.6  Distortion calculations are now more robust, consistent, and less sensitive to region of interest (ROI) selection. The new ROI filtering input option, allows the selection of weak ROI filtering. which produces good results in most cases. A new Radius correction figure has been added (Imatest Master only).

Distortion

Distortion calculates the coefficient for correcting distortion using Picture Window Pro, which uses a tangent/arctangent distortion model. A procedure for obtaining approximate Ptlens coefficients is described below.

Lens distortion has two forms, barrel and pincushion, as illustrated below.


None

Barrel

Pincushion

Distortion tends to be most serious in extreme wide angle, telephoto, and zoom lenses. It is most objectionable in architectural photography and photogrammetry — photography used for measurement (metrology). It can be highly visible on tangential lines near the boundaries of the image, but it's not visible on radial lines. In a well-centered lens distortion is symmetrical about the center of the image. But lenses can be decentered due to poor manufacturing quality or shock damage.

In the simplest lens distortion model, the undistorted and distorted radii ru and rd (distances from the image center normalized to the center-to-corner distance (half-diagonal) so that r = 1 at the corner) are related by the equation,

ru = rd + k1 rd3        where k1 > 0 for barrel distortion and k1 < 0 for pincushion.

This third-order equation is one of the Seidel Aberrations, which are low-order polynomial approximations to lens degradations. Other aberrations include astigmatism, coma, curvature of field, etc. The third order approximation is sufficient for many lenses, but Imatest also calculates the fifth-order coefficients, which can be more accurate for certain lenses, for example, for the Sigma 18-125mm zoom at 18mm and the Zeiss 21mm f/2.8 Distagon.

ru = rd + h1 rd3 + h2 rd5

Distortion by Paul van Walree is excellent background reading.

To measure distortion, you'll need a rectangular or (preferably) a square grid pattern, which you can create using Test Charts. Print the chart, photograph it, and enter the image into the Imatest Distortion module, as described below.

Instructions

The Screen Patterns display, shown on the right, works best with large flat screen LCDs (it's not recommended with CRTs). Click on Screen Patterns on the right the Imatest main window, select Distortion grid or Squares (checkerboard) in the box at the bottom-center, then maximize the window. You can select the number of Horizontal and Vertical lines as well as the line width (in pixels). For best results the pattern should be square.

Screen Patterns Distortion pattern
Screen Pattern module for Distortion.

    • Line width (pxls). Only applies when Type is set to Grid. Typically in the range of .01*PPI to .025*PPI. The printed line should be clear (not pale), but not too thick. The relative line widths in the preview (to the right of the selection boxes) is not to scale. They are (relatively) thicker than in the final image.
      The line width should be thick enough to cover at least two pixels in the captured image.
      Narrower lines may result in errors (Inconsistent number...). For example, suppose your captured image were 640x480 pixels (VGA). The line width (as shown on the right) would be 3 pixels out of a chart width of 1476. In the captured chart, the line width would be 640*(3/1476) = 1.3, inadequate for this small image size, though this chart would be perfectly adequate for 1+ megapixel cameras.

Test Charts dialog box for preparing
a file to print the distortion grid.

Save the image. High quality JPEG format is preferred because it preserves EXIF data in a format Imatest can read. There is no need for RAW quality.

Resize the image? Because Matlab uses double precision for most math operations, each 24-bit color pixel requires 24 bytes. A 6.3 megapixel image can take 151 megabytes of memory (ouch). This can slow down computations in computers that don't have gobs of memory. (It can even bog down computers with 512k of memory.) We are looking into solving this problem. In the meantime we recommend resizing images to about 1000 pixels wide in an image editor. (Any editor will do.) Resizing has no effect on the results.

Launch Imatest. Click on Distortion.

Very large files (height x width x colors over 40 MB) may cause memory overflow problems. Files over 40 or 80 MB can be automatically reduced 1/2x linearly (using 1/4 the memory). Click Settings, Options and Settings... (in the Imatest main window) and make the appropriate setting in LARGE FILES (Light Falloff, Distortion).

Open the image file.

Batch mode  This module can operate in batch mode in Imatest Master, i.e., it can read multiple input files. All you need to do is select several files using the standard Windows techniques of shift-click or control-click. There are three requirements for the files.
They should (1) be in the same folder, (2) have the same pixel size, and (3) be framed identically.
The input dialogs (cropping (if applicable), settings, and save) are the same for the first run as for standard non-batch runs. Additional runs use the same settings as the first run. Since no user input is required they can run extremely fast.
If the order of the files in a batch runs is different from the selection order, click Settings, Options and Settings... (in the Imatest main window) and change the setting in Batch run order.
One caution: Imatest can slow dramatically on most computers when more than about twenty figures are open. For this reason we recommend checking the Close figures after save checkbox, and saving the results. This allows a large number of image files to be run in batch mode without danger of bogging down the computer.

Crop the image (select the ROI) if needed using the usual clicking and dragging technique. Cropping may be helpful if horizontal or vertical lines are not entirely within the ROI (region of interest), though Imatest 2.3.6+ often works well in such cases. An example is shown below in the section on Severe distortion. Click outside the the image to select the entire image. You can select either a grid pattern or a single line, which is useful in patterns such as the ISO 12233 chart, which contains two lines suitable for Distortion: one nearly vertical and one nearly horizontal (both slightly tilted). One of them is illustrated below. Make sure to leave some breathing room around the line. In selecting the crop for grid patterns (or deciding not to crop) try to choose a crop where no lines cross the crop boundaries, i.e., are partly inside and partly outside. The horizontal (well... sort of) line at the bottom right of the "Bad" image above is caused Distortion to terminate in Imatest versions earlier than 2.3.6, but is very likely to work will with 2.3.6+.

Three cropping (ROI selection) options are available by clicking Settings, Options and Settings... in the Imatest main window. These include

Never crop.
Select crop by dragging cursor. Ask to repeat crop for same sized image.
Select crop by dragging cursor. Do not ask to repeat crop.

Although the first option (Never crop...) was the default in early version of Distortion, the second option (Select crop by dragging cursor. Ask to repeat crop for same sized image), which is similar to the ROI selection in SFR, may be preferred in many cases.

The input dialog box, shown below, appears. Title defaults to the file name; you may change it if needed. The most important choice is the algorithm that detects pattern location. Figures can be selected in the Plot box on the right. Plot intersection points, Plot radius correction, and Display corrected image appear in Imatest Master only.

Distortion input dialog box
Distortion input dialog box

When the calculations are complete the Save dialog box appears. The default directory is subdirectory Results in the data file directory. You can change to another existing directory, but new results directories must be created outside of Imatest— using a utility such as Windows Explorer. (This is a limitation of this version of Matlab.) The selections are saved between runs. You can examine the output figures before you check or uncheck the boxes. Select the items you wish to save, then click Yes or No. File names (where filename is the input file name):

[filename]_distortion.png
[filename]_corrected.png 
(only if displayed)
[filename]_intersections.png
[filename]_radius_corr.png
[filename]_summary.csv

[filename].xml


Save results dialog box

The root file name ([filename], above) defaults to the image file name, but can be changed using the Results root file name box. Be sure to press enter. Checking Close figures after save is recommended for preventing a buildup of figures (which slows down most systems) in batch runs.

Results

Main figure

An example of Distortion output is shown below for the Sigma 18-125 mm f/3.5-5.6 DC lens (designed for APS-C-sized sensors, such as the Canon EOS-10D, 20D, Digital Rebel, Nikon D100, D70, etc. The Sigma is an excellent lens — a bargain — except for its autofocus. Mine doesn't autofocus as reliably as Canon lenses, but it works beautifully on manual. The autofocus problem is plainly visible when working with the distortion chart.


Main figure showing modest pincushion distortion

The Sigma has modest amounts of pincushion distortion at 125 mm and barrel distortion at 18mm, its widest angle setting. Corrected vertical lines are deep magenta; horizontal lines are blue. Results displayed below the image on the left include.

  • TV Distortion from the SMIA specification, §5.20. Referring to the image on the right,

         SMIA TV Distortion = 100( A-B )/B ;       A = ( A1+A2 )/2

    The box on the right is described in the SMIA spec as "nearly filling" the image. Since the test chart grid may not do this, Distortion uses a simulated box whose height is 98% that of the image. Note that the sign is opposite of k1 and p1. SMIA TV Distortion > 0 is pincushion; < 0 is barrel.
SMIA TV Distortion illustration
SMIA TV Distortion
TV distortion: traditional definitionSMIA vs. traditional TV distortion

Thanks to Mark Butterfield for pointing out that SMIA's distortion definition differs from the traditional TV industry definition by a factor of two. The traditional definition is shown in the illustration on the right, which has been adapted from the publication "Optical Terms," published by Fujinon. The same definition appears in "Measurement and analysis of the performance of film and television camera lenses" published by the European Broadcasting Union (EBU). SMIA TV distortion is double the traditional TV distortion definition.

Imatest will continue to use the SMIA definition, which has been widely adopted in the mobile imaging industry. We prefer it because it is self-consistent. In the traditional definition, TV distortion is the change (Δ) in the center-to-top distance divided by by the bottom-to-top distance. In the SMIA definition, both A and B are bottom-to-top distances.

Picture Window Pro uses a tangent/arctangent model of distortion, which works well for a variety of lenses, including fisheyes.

     ru = tan(10 p1 rd )/ (10 p1 ) ;      h1 > 0   (barrel distortion)
     ru = tan-1(10 p1 rd )/ (10 p1 ) ;    h1 < 0   (pincushion distortion)

Where p1 is the correction coefficient. Using Taylor series, we can show that it is similar to the third-order model,

     tan(x) = x + x3/3 +2x5/15 + ... ;   tan-1(x) = x - x3/3 + x5/5 - ...  ( x2 < 1) ;
     ru
= x + 100 p12x3/3 + ... (barrel);   ru = x - 100 p12x3/3 + ... (pincushion) ,

k1 ≈ sign( p1)*100 p12/3  for small values of k1 and p1k1 and p1 diverge for large values.

The plot includes arrows that illustrate the change in radius when distortion is corrected. Distortion was too low on the above plot to make the arrows visible. They are illustrated in the plot below for a large amount of simulated barrel distortion. You can try different line display calculations to see the difference.


Main figure with extreme (simulated) pincushion distortion, illustrating arrows.

Here is an example of results from an ISO 12233 test pattern, which contains two lines suitable for measuring distortion. They work but they're not ideal: they would be better if they were thinner and closer to the image boundaries. This camera has a modest amount of pincushion distortion. A zoom of a portion of the selected area is shown above.

Decentering (Imatest Master only)

Distortion is normally centered around the geometric center of the image, but it may be decentered due to poor lens manufacturing quality or shock (i.e., dropping the lens). Decentering can appear as a shift in the center of distortion symmetry or as asymmetrical MTF (sharpness) measurements in SFR. Distortion calculates decentering if Decentering calculation is checked in the Input dialog box and |k1| > 0.01. (k1 is the third-order coefficient.) If |k1| is smaller, distortion is insignificant (and difficult to see); hence decentering has no meaning.

Decentering is reported by the radius (in units of the distance from the image center to the corner) and angle in degrees of the center of distortion symmetry. It is illustrated in the simulated pattern below. The geometrical center of the image is indicated by a pale blue +. The center of the decentered distortion is indicated by bold red X.

Severe distortion: Corrected image figure

Images from optical systems with severe distortion (fisheye lenses, etc.) often need to be cropped so Distortion can detect vertical and horizontal lines. (See good/bad images, above.) The figure below illustrates an inexpensive fisheye lens. The crop area, shown in the middle, is displayed with full contrast; the area outside the crop has reduced contrast.

This figure does not show the corrected grid image outside the crop. The different correction formulas (3rd order polynomial, 5th order polynomial, or tangent/arctangent) can only be compared inside the crop area, where optimum coefficients have been calculated. They don't look very different in this region.

If Display corrected image in the input dialog box (Imatest Master only) is set to crop only or Always, the corrected image (shown below) is displayed. (The extreme corners are omitted for large amounts of barrel distortion). This figure is not perfect. It is calculated using a simple, fast algorithm that omits some pixels on the left and right. A semicircular "fingerprint" pattern" appears in their place. But is good enough to clearly illustrate the performance of the correction algorithm. (Another option, always - interpolated (SLOW!), produces a fine image without any gaps, but is too slow to be recommended.)

In this case, some residual barrel distortion is visible in vertical grid lines on the left and right and some residual pincushion distortion is visible in the horizontal grid lines on the top and bottom. The average correction is quite good. The tangent/arctangent algorithm (used in Picture Window Pro) gives slightly better results for this image than the 5th order polynomial (which is normally most accurate), and much better than the 3rd order polynomial.

This image has some perspective distortion: vertical convergence of lines. This results from the way the camera was pointed when the image was captured. It is not a lens aberration.

Intersection figure (Imatest Master only)

Checking Plot intersection points in the input dialog box displays a second figure that contains intersection points (line crossings) designated by "+," "T," or "L." "+" intersection points are inside the pattern; "T" points are on the boundaries (top, bottom, and sides), and "L" points are on the corners.

The image should be cropped so that only "+" intersection points (line crossings) are present inside the crop. Imatest doesn't like boundaries with "T" or "L" patterns inside the crop. To detect such patterns, they must be outside the crop (as shown above) and Detect points outside crop must be checked in the input dialog box. These points are not used in the for calculating distortion coefficients.

If the image contains letters or material unrelated to the the pattern, it should be edited out using an image editor. Picture Window Pro has a particularly convenient means of creating a rectangular mask for this purpose.

The (x,y) coordinates of the displayed points are included in the optional .CSV and XML output files. There coordinates can be used for further analysis of geometric distortion.

Thanks is due to Karl-Magnus Drake of the National Archives of Sweden for suggesting this figure.

Radius correction figure (Imatest Master only)

Checking Plot radius correction in the input dialog box displays a figure that contains detailed distortion/radius correction information, which can be useful for analyzing images like the one on the right, which has barrel distortion near the center but tends towards pincushion near the corners.

The upper plot shows the distortion-caused change in radius Δr (normalized to the center-to-corner distance, i.e., the half-diagonal) as a function of the distorted (input) radius r(distorted) = rd.

Δr = r(corrected) - r(distorted) = ru = rd

where r(corrected) = ru is the corrected ( undistorted) radius. Δr is a function of the scaling (i.e., magnification) of the corrected image,

Image showing barrel and pincushion distortion
Image showing complex distortion: barrel near center;
pincushion near corners.

The bold solid lines —— in the upper plot show Δr for no scaling, i.e., for the straight correction formulas: ru = rd + k1 rd3 (3rd order; blue);  ru = rd + h1 rd3 + h2 rd5 (5th order; green); or the arctan/tan equations (red). With these equations Δr tends to increase as a function of r(distorted), i.e., it tends to be largest near the image corners.

The dashed lines - - - - show Δr when ru (the corrected image) is scaled for no shift (Δr = 0) at the image corners (rd = 1). The scaling factor is shown in the Legend box, which also shows the error function (described in the Algorithm; different for the 5th order calculation) and the number of iterations.

The upper plot is difficult to relate to the perceived distortion type (pincushion or barrel); the only difference between the solid and dashed lines is the scaling factor (image magnification). The lower plot, which contains Curvature and Distortion measurements (explained in the green box below) is directly related to the distortion type .

Radius correction figure

Equations for distortion and curvature

The standard distortion equations— ru = rd + k1 rd3 (3rd order),  ru = rd + h1 rd3 + h2 rd5 (5th order), or the arctan/tan equations— do not give a clear picture of whether distortion takes the barrel or pincushion form. And to complicate matters, some images like the one above have barrel distortion at some radii and pincushion at others.

The key to determining the type of distortion is to recall that radius ru is the position of a point, its derivative dr/drd is the slope, and its second derivative d 2r/drd2 is the curvaturelocal curvature, which is a function of radius r closely related to distortion.

It is instructive to look at the first and second derivatives of the 3rd and 5th order equations.

3rd order:   dr/drd = 3 k1 rd2 ;    d 2r/drd2 = Curvature = 6 k1 r.  
5th order:   dr/drd = 3 h1 rd2 + 5 h2 rd4 ;    d 2r/drd2 = Curvature = 6 h1 rd + 20 h2 rd3 .

The problem with Curvature as defined here is that it tends to be proportional to r (it's exactly proportional for the 3rd order equation). To get a more consistent measurement, we define Distortion as Curvature divided by r.

Distortion = Curvature/r = 6 k1 (3rd order) = 6 h1 + 20 h2 rd2  (5th order)

Distortion is a single number for the 3rd order case. Distortion and Curvature is only visible in lines that have a tangential component. Tangential edges are illustrated in the page on Chromatic Aberration.

Curvature ( d 2r/drd2 ) and Distortion (Curvature/r) are plotted as dashed ( - - - ) and bold solid —— lines, respectively, in the lower plot. 

Interpretation:

Positive Distortion (and Curvature) represents local barrel distortion;
Negative represents local pincushion distortion.

In the example above, distortion goes from barrel to pincushion around rd = 0.8 (the diameter at the sides of the image). This is visible near the corners, where the (barrel) curved lines straighten out.

The blue lines (3rd order equation) are the simplest but least accurate approximation to distortion. The 5th order equation (red lines), which has two parameters (h1 and h2 ), is more accurate. If the 3rd and 5th order curves are close, the 3rd order curve is sufficient. In the above example, which is not typically, they are very different; the third order equation is completely inadequate. The arctan/tan equation is also characterized by a single parameter. It behaves differently from the 3rd order equation for large Δr.

The 3rd order distortion value in the figure is a constant solid blue blue equal to 6 k1 .

Links

Real-Time Lens Distortion Correction by Michael R. Bax (of Stanford) contains the standard distortion equation, ru = rd (1 + k1 rd2) and its inverse (more complex).

Distortion by Paul van Walree, who also has excellent descriptions of several of the lens (Seidel) aberrations and other sources of optical degradation.

Lens aberrations, including distortion, are discussed in pages from James R. Graham of the U.C. Berkeley Astronomy Department, based on Applied Optics & Optical Engineering, Vol XI by J. C. Wyant & K. Creath, which goes into real depth. Worth checking out if you're mathematically inclined.

Optical Metrology Center A UK consulting firm specializing in photographic metrology. (Site must be viewed with Internet Explorer.) They have a large collection of interesting technical papers emphasizing distortion and 3D applications, for example, Extracting high precision information from CCD images.

PTlens is an excellent program for correcting distortion. It uses the equation from Correcting Barrel Distortion by Helmut Dersch, creator of Panorama Tools, who states,

Photogrammetry is the science of making geometrical measurements from images. George Karras has sent me some interesting links with material relevant to Imatest development:  http://www.vision.caltech.edu/bouguetj/calib_doc/  |  http://nickerson.icomos.org/asrix/index.html.

The correcting function is a third order polynomial. It relates the distance of a pixel from the center of the source image (rsrc) to the corresponding distance in the corrected image (rdest) :

rsrc = ( a * rdest3 + b * rdest2 + c * rdest + d ) * rdest

The parameter d describes the linear scaling of the image. Using d=1, and a=b=c=0 leaves the image as it is. Choosing other d-values scales the image by that amount. a,b and c distort the image. Using negative values shifts distant points away from the center. This counteracts barrel distortion... The internal unit used for rsrc and rdest is the smaller of the two image lengths divided by 2.

This equation drives me nuts! rsrc and rdest are reversed from the equations on this page; it only goes up to fourth power (when you include rdest outside the parentheses; third power if you don't); and it has even order terms (a and c) when the theory implies that distortion can be modeled with odd terms only. Give me a higher order term (h * rdest4 ) and dump a * rdest3 and c * rdest. But nonetheless it works pretty well.

Mike Collins has posted a technique for finding PTlens parameters on a dpreview.com forum. I haven't checked to verify it. Briefly,
1) take a shot of the grid pattern and run Imatest distortion. Note the k1 (which is the r^3) parameter.
2) divide my magic number = -3.397. This result is now used as the b (r^3) parameter in Ptlens.
3) Edit the profile file used in Ptlens to include this new lens. Use the bodies multiplier, lens name, focal length, a, b, c ( make a and c 0.000000; and b from calculation in 2) ). More details on the post.

Modeling distortion of super-wide-angle lenses for architectural and archaeological applications by G. E. Karras, G. Mountrakis, P. Patias, E. Pets

Algorithm for calculating correction coefficients.
The coefficients of the standard distortion equations are calculated using nonlinear optimization that straightens the lines (minimizes their curvature). The equations are

     ru = rd + k1 rd3                   (3rd order)  rd is the distorted (input) radius; ru is the undistorted (output) radius.
     ru = rd + h1 rd3 + h2 rd5       (5th order)
     ru = tan(10 p1 rd )/ (10 p1 ) ;      h1 > 0   (arctan/tan; barrel distortion)
     ru = tan-1(10 p1 rd )/ (10 p1 ) ;    h1 < 0   (arctan/tan; pincushion distortion)

The optimizer
  • finds the average locations of vertical and horizontal lines in the image,
  • scans between the lines to find (x,y) locations on the lines (and if there is room, scans lines that intersect the image boundaries),
  • finds polynomial fit for each line,
  • minimizes the sum of squares of the second order polynomial coefficients, which are the line curvatures. For the 5th order case the optimizer minimizes the sum of squares of the second and fourth order polynomial coefficients— a slightly different error function from the 3rd order and arctan/tan cases.
Since optimization is performed only to straighten curved lines, this algorithm is relatively insensitive to perspective distortion and small amounts of camera misalignment.