[ptx] new command line tool for vignetting, radial distortion and TCA correction

Pablo d'Angelo pablo.dangelo at web.de
Fri Mar 10 17:28:48 GMT 2006


Hi Bruno,

Thanks for the nice post. I have played with a similar workflow, however,
there are some things that make the estimation process a bit tricky.

Bruno Postle wrote:
> On Thu 09-Mar-2006 at 09:03 +0100, Pablo d'Angelo wrote:
> 
>>
>> I have written a command line tool, whose working title is fulla, to
>> perform vignetting, radial distortion and transversal chromatic
>> abberation correction.
> 
> 
> I've played with the aberration correction and it works nicely, some
> detail from a photo enlarged:
> 
> http://bugbear.blackfish.org.uk/~bruno/fulla/dscn3079-before.jpg
> http://bugbear.blackfish.org.uk/~bruno/fulla/dscn3079-correct.jpg

Nice results.

> The workflow to figure-out the parameters goes something like this:
> 
> 1. Use a RAW or TIFF photo, trying to correct chromatic aberration
>   of a JPEG photo is a big waste of time.
> 
> 2. Split the image into red, green and blue files.  I used the gimp
>   decompose filter and saved them each as PNG.
> 
> 3. Load them into hugin, set the green image as the anchor.
> 
> 4. Give each image a separate 'lens'.
> 
> 5. Set the output to the same FoV as the green image, set output
>   type to rectilinear if the input is rectilinear.

Actually, it might be better to use the equirect for both output and input,
since then, changes in FoV result in a linear magnification everywhere.
The amount of HFOV should not matter in that case.

> 6. Use the 'g' key to create lots of control points between the
>   green & blue and green & red images.
> 
> 7. Fine tune all points. delete any points with less than 98%
>   correlation.
> 
> 8. Optimise FoV, a, b & c for the red and blue images.

Optimizing all distortion parameters might not work perfectly, especially
for the corners, where usually less control points are located.

I also got good results when using only FoV and c. Then the optimisation is
less sensitive to outliers and areas where less control points are located
(like the image corners)

Since most other software just uses scaling for TCA correction, I think its
good to start with FoV and c, and set a & b to zero.

> 9. Delete any bogus control points (with large errors) and
>   reoptimise.
> 
> 10. 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 7.
> 
> 11. Now write down the a, b & c values for the red and blue images.
>    Calculate the d parameters by dividing the FoV of the green image
>    by the FoV of the optimised image.

Unfortunately it is not that simple, because PTOptimizer applies the FoV
(scaling) before the distortion correction.

The following octave code can be used to calcuate the parameters for fulla:

% scaling factor hfov_green / hfov
scale = 10/9.99176;

% coefficients as optimized by hugin
a = 0;
b = 0;
c = 0.000384;

d = 1 - a - b - c;
a = a*scale^4;
b = b*scale^3;
c = c*scale^2;
d = d*scale;

disp(sprintf('%f:%f:%f:%f', a,b,c,d));


> 12. Run fulla on the command-line, something like this:
> 
>      fulla -b -0.001344:0.003245:-0.002050:1.0000714 \
>            -r -0.000980:0.001960:-0.000540:1.0005016 \
>               dscn3079.tif dscn3079-correct.png

With the above formula the correct values are:
-b -0.001344:0.003246:-0.002050:1.000220
-r -0.000982:0.001963:-0.000541:1.000061

Sometimes it is good to see how the curve actually looks like. It can be
easily plotted using octave. To plot the correction curve for the blue
channel in your example, start octave and type:

octave:1> p = [a b c d];
octave:2> x = [0:0.05:1]; plot(x,polyval(p,x));

Its strange that your correction curve curve got some kind of U shape, I
suspected that the correction curves should be monotonous, without turning
point.

Either the lens behaves stranger than I thought, or the data is not good
enought to fit a 4th degree polynomial to it. Is your image corrected well
at all radi?

> That's it, in principle these parameters should be the same for all
> future pictures taken with the same lens combination.

Yes, I think so too.. Since I have just added support for PTLens profiles to
fulla, I'm thinking about storing these coefficents there too :) Have to
check with Thomas if the file format can be extended to contain these values.

ciao
  Pablo


More information about the ptx mailing list