Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[b4a227]: tutorials / tca / en.2006-03-14.shtml Maximize Restore History

Download this file

en.2006-03-14.shtml    248 lines (206 with data), 8.8 kB

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Correcting Chromatic Aberrations with Hugin and PanoTools</title>
<style media="screen" type="text/css" title="Screen style sheet">
@import url(/css/normal.css);
</style>
<link rel="icon" href="/css/icon.png" type="image/png" />
</head>
<body>

<!--#include virtual="/ssi/menu.shtml"-->
<div class="content">

<h1>Correcting Chromatic Aberrations</h1>

<p> This is a short howto on determining transversal chromatical aberration
(TCA) correction coefficients for use with fulla (a program of the Hugin suite
to correct images for distortion, TCA and vignetting) or the Panotools correct
plugin.  Contrary to other approaches (Krause, PTShift) the approach presented
here relies only on free software (Hugin and octave). It is based on
automatically creating many control points between the color channels and using
these to let PTOptimizer (or another tool) automatically calculate the radial
correction parameters. </p>

<p>
It is similar to a method proposed by Erik
Krause earlier, but according to his words it didn't work very well.
This is probably, because the control points were not good enought and/or the images were too colorful.
</p>

<p>
More information about TCA and its correction using panotools
can be found a these webpages:</p>
<ul>
<li>A good <a href="http://www.vanwalree.com/optics/chromatic.html">Introduction by Paul van Walree</a>
</li>
<li><a href="http://www.pinlady.net/vr/">PTShift</a>, photoshop extension for determination of TCA correction coefficients. An alternative way to the approach proposed below. If I had access to photoshop, I would have tried this method first.
</li>
<li><a href="http://www.erik-krause.de/index.htm?./ca/">Tutorial by Erik Krause</a>, explains how TCA correction coefficients can be calculated with the help of Picture Window Pro and Excel
</li>
</ul>

<h2>Estimating the radial correction parameters using Hugin</h2>

<ol>
<li>
Use a RAW or TIFF photo, trying to correct chromatic aberration
   of a JPEG photo is a big waste of time. If possible, use an image
   without much color. Make sure that it not overexposed.
</li>
<li>
Split the image into red, green and blue files. This can be done using the decompose filter of the GIMP, or with imagemagick.
</li>

<li>
Load them into Hugin, the order should be red, green, blue.
</li>

<li>
Give each image a separate 'lens'. Choose equirectangular projection and set the HFOV to 10
</li>

<li>
Switch to the Stitcher Tab. Set the Panorama to equirectangular and use a HFOV of 10. Press the "Calculate Optimal Size" button.
</li>

<li>
Switch to the Control Points tab. Use the 'g' key to create lots of control points between the green &amp; blue and green &amp; red images.
A corner threshold of 50 and a scale of 2 should result in many useful points at corners in the image.
</li>

<li>
Open the preferences and set the fine tune options as in the screenshot below.
<p>
<img src="finetune_prefs.png" alt="recommended fine tune preferences"/>
</p>
  Fine tune all points (Edit-&gt;Finetune all points). delete any points with less than 98%
  correlation. This can be done easily with the the control points list. Unfortunately Hugin is very slow when manually selecting many points. Users of Hugin versions later than 10th of March 2006, or 0.6 and higher can use "select by distance" and enter -0.98 to
  select all points with correlation lower than 0.98
</li>

<li>
Optimise FoV, a, b &amp; c for the red and blue images.
</li>

<li>
Delete any bogus control points (with large errors) and
  reoptimise.
</li>

<li>
With any luck you should now have several hundred control-points
   with an average error of around 0.2 pixels.  If not, go back to 8.

   The preview with blend mode difference can be used to check if the images match well.
   Mismatches are either caused by overfittng the correction parameters or by color in the input image.
</li>

<li>
Save the pto file.
</li>
</ol>

<h2>Extracting TCA correction parameters</h2>

<p>
The distortion parameters of the red and blue channel cannot be used directly by fulla or the PanoTools correct plugin. Therfore I have written an octave script reads the .pto file, displays the correction curves and provides the parameters for fulla.
</p>

<p>
The script will also calculate correction parameters based on the control points directly. These are usually better than the ones estimated by PTOptimizer.
</p>

<p>
If you don't have access to octave, here is how the parameters are calcuated (red channel):
</p>
<pre>

scale = hfov_green / hfov_red

d_pt = 1 - a_pt - b_pt - c_pt
a = a_pt * scale^4
b = b_pt * scale^3
c = c_pt * scale^2
d = d_pt * scale
</pre>
<p>
Use a similar calculation for the blue channel. The values of a_pt, b_pt, c_pt are the distortion parameters from Hugin.
</p>

<p> Download <a href="show_tca.m">show_tca.m</a> and place it in the same
directory as your .pto file. The script requires octave and octave-forge. While
I haven't tested if it can be used with MATLAB, it should be useable after
slight modifications. </p>

<p>
open octave and type:
</p>
<pre>
octave:2&gt; display_tca('pano_tutorial.pto');
</pre>
<p>
This will produce two figures:
</p>
<div>
<img src="corr_curves.png" alt="plot of correction curves" />
<p>
This plot shows the scaling factors required for TCA correction of the red and blue channel over the distance from the image center. Each dot represents a control point.
</p>

<p> The red and blue line the correction curve estimated by PTOptimizer. The
correction curve is also estimated by the show_tca and given by the dotted
lines. The correction curves should approximately go through the center of
the point clouds.
</p>
<p>In my case the values estimated by show_tca look better, since they
only depend on the center distance difference (sagittal distance) of the
points. PTOptimizer minimizes the tangential and sagittal distance between the
points. However, then tangential distance is not of interest for TCA
correction, and is caused by the limited accuracy of the fine tune function,
especially close the the edge of the fisheye image.  </p>

</div>

<div>
<img src="distance.png" alt="tangential and sagittal distance between points" />

<p> This plot displayes the tangential and sagital distance between the
control points of the red and green channel. One can see that there is a
significant tangential distance (especially at higher radi), leading to a
non-optimal correction coefficients, if PTOptimizer is used.  </p>

</div>

<p>
The calculated correction parameters are printed to the console:
</p>
<pre>
correction parameters read from pto file:
 -r 0.0000000:-0.0019056:0.0030218:0.9995177
 -b 0.0000000:0.0003038:-0.0006342:1.0012401
new fit, based on distance to image center:
 -r 0.0001368:0.0002725:-0.0006605:1.0007630
 -b 0.0011642:-0.0046154:0.0055706:0.9989218
</pre>
<p>
Choose the set of parameters that looks better on the diagram above. I suspect that the second parameter set
is usually preferable.
</p>

<p>The correction parameters should be useable with all future images shot
using the same lens at the same focal length. The correction coefficients will
probably vary (a little?) with the focus setting, and maybe even with the
aperture (but probably to a lesser degree).
</p>

<h2>Correcting TCA</h2>
<p>
The estimated TCA correction coefficients can then be used with fulla or the PanoTools correct plugin. 
</p>

<p>
Correct TCA using fulla:
</p>
<pre>
fulla  -r 0.0001368:0.0002725:-0.0006605:1.0007630 \
       -b 0.0011642:-0.0046154:0.0055706:0.9989218 \
        input.tif output.tif
</pre>

<p>
This correction can be combined with all other correction options of fulla,
like the distortion correction based on the PTLens database (-p option) or the
vignetting correction.
</p>

<h2>Results</h2>
<p>
Here are some results of the correction of 8mm Peleng fisheye, used on a Canon 300D:
</p>

<div>
<img src="compare_corner.jpg" alt="comparison of corrected and uncorrected area near the image corner" />
<p>Correction results near the image corner. The color seams are corrected well.
</p>
</div>

<div>
<img src="compare_near_center.jpg" alt="comparison of corrected and uncorrected area near the image center" />

<p>Correction results near the image center. The center area doesn't show such
less TCA than the edges, but it is still corrected well.
</p>

</div>
<p>
Here are the full resolution images: <a href="uncorrected.jpg">original</a> <a href="corrected.jpg">corrected</a>
</p>

<p>
Author and photo: <a href="mailto:pablo.dangelo@web.de">Pablo d'Angelo</a> - Created March 2006
</p>
</div>
</body>
</html>