Author Topic: LensCorrection Pre-release  (Read 8448 times)

Offline Silvercup

  • PixInsight Addict
  • ***
  • Posts: 187
LensCorrection Pre-release
« on: 2010 April 02 10:08:00 »
Hello

I finished writing a script to correct the barrel/pinchcusion photographic objectives, using Helmut Dersch's formula:

Normal Mode: r_src = (a * (r_dest ^ 3) + b * (r_dest ^ 2) + c * r_dest + d) * r_dest
Inverse Mode: r_src = 1/(a * (r_dest ^ 3) + b * (r_dest ^ 2) + c * r_dest + d) * r_dest

a,b,c,d parameters are the radial distortion/correction coefficients for the X,Y dimension equation.

The coefficient a,b,c,d represents scaling and the radial terms control pincushion and barrel distortion. The higher order coefficients affect the pixels further from center. The whole expression has a scaling effect. Thus, to avoid overall scaling, keep a+b+c+d=1. For normal mode, pincushion correction and barrel distortion are achieved using a,b,c positive and barrel correction and pincushion distortion are achieved using a,b,c negative.
For a+b+c+d>1, the image will be scaled smaller and for a+b+c+d<1, the image will be scaled larger.
Typical values are: d near 1 and a,b,c near zero.
For inverse mode, the situation above is reversed. Thus for inverse mode, pincushion correction and barrel distortion are achieved using a,b,c, negative and barrel correction and pincushion distortion are achieved using a,b,c,d positive.
For a+b+c+d<1, the image will be scaled smaller and for a+b+c+d+e>1, the image will be scaled larger.
Values of a=0,b=0,c=0,d=1, makes no change in the image in the appropriate dimension.
Coefficients a,b,c,d,e are floating point values.

Some examples:

Original



Corrected



Original



Corrected





And now I need some help. I can implement a, b, c, d coefficients for X and Y independiently i.e. ax, bx, cx, dx  and ay, by, cy, dy. But theoretically, this formula
can correct chromatic aberration with independent coeficients for each RGB channels Redax, Redbx....Blueyc, Blueyd. You can shift x and y points, choose center of image, etc. A lot of controls.

I don't know how to implement this controls: simple text controls, sliders? SpinBox don't alow negative and decimal values.

And this for Juan. I got error calculations with standart formula r_src = (a * (r_dest ^ 3) + b * (r_dest ^ 2) + c * r_dest + d) * r_dest so I implemented r_src=(a*(r_dest*r_dest*r_dest) + b*(r_dest*r_dest) + c*r_dest + d)*r_dest. What I'm doing wrong?

Thanks

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: LensCorrection Pre-release
« Reply #1 on: 2010 April 02 13:42:45 »
Hi Silvercup,

this was always on my wishlist, see http://pixinsight.com/forum/index.php?topic=1476.0.

As for the controls: I have been using NumericControl (Sliders) in my scripts, see for example http://pixinsight.com/forum/index.php?topic=1159.msg9587#msg9587 .

Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline Enzo De Bernardini

  • PTeam Member
  • PixInsight Addict
  • ***
  • Posts: 274
  • Resistance is futile.
    • Astronomí­a Sur
Re: LensCorrection Pre-release
« Reply #2 on: 2010 September 11 11:13:53 »
This is a somewhat old post, but I ask: can this improve, even slightly, coma issues?

Enzo.

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: LensCorrection Pre-release
« Reply #3 on: 2010 November 03 05:43:19 »
Hi Silvercup,

For some strange reason I overlooked this post completely. Now I've seen it and this looks like a very interesting and promising work (and yes it has been in Georg's wish list for a long time :) ).

Quote
And this for Juan. I got error calculations with standart formula r_src = (a * (r_dest ^ 3) + b * (r_dest ^ 2) + c * r_dest + d) * r_dest so I implemented r_src=(a*(r_dest*r_dest*r_dest) + b*(r_dest*r_dest) + c*r_dest + d)*r_dest. What I'm doing wrong?

The ^ operator does not work as you expect in JavaScript. In PixelMath, ^ is the raise (exponentiation) operator, but JavaScript borrows most of the C/C++ operator syntax so ^ stands for the bitwise XOR operator.

So you must call Math.pow( x, y ) which returns the result of xy. Using this method, your expression would be:

r_src = (a*Math.pow( r_dest, 3 ) + b*Math.pow( r_dest, 2 ) + c*r_dest + d) * r_dest;

Although I personally would implement it using successive multiplications and a Horner scheme:

let(r_dest2 = r_dest*r_dest, r_dest3 = r_dest2*r_dest) r_src = (a*r_dest + b)*r_dest3 + c*r_dest2 + d*r_dest;

or, much better, using the Math.poly() method:

r_src = Math.poly( r_dest, [d, c, b, a] );

Let us know if you make progress with this extremely interesting script. Any chance you finish it so we can include it into the next release?
« Last Edit: 2010 November 03 05:55:23 by Juan Conejero »
Juan Conejero
PixInsight Development Team
http://pixinsight.com/