Hi Malcolm,

>> Now, the actual reason for my post is that I'd like to convert the
>> lensfun distortion calibration parameters to equivalent parameters of
>> the SIP model [1] used in astronomy.
>>
>> The main difference is that the SIP model is not based on radius but on
>> the x,y (unnormalized) pixel coordinates. For both the undistorted x and
>> y coordinates a separate polynomial can be defined with an arbitrary
>> order. It seems as if it's more general than the lensfun models, hence I
>> thought I could map them easily.
>>
>> So, basically you have x = u + f(u,v) and y = v + g(u,v) where u,v are
>> the original (distorted) pixel coordinates relative to the image center,
>> and x,y the undistorted coordinates. Therefore f and g have to provide
>> the amount to walk for each axis in pixels to get from the distorted
>> position to the undistorted one.
> 
> I'm not sure if you've tackled the conversion between models correctly:
> the lensfun models as written transform from ideal to distorted
> coordinates, whereas you have written the SIP model as a transformation
> from distorted to undistorted.

I'm a bit confused by that, too, but I had a look at lensfun's code and
in mod-coord.cpp for example at ModifyCoord_UnDist_Poly3() the
undistorted coordinates are calculated with
Ru = Rd * (1 - k1 + k1 * Rd^2)
in principle, and actually with
xu = xd * (1 - k1 + k1 * (xd*xd+yd*yd))
yu = yd * (1 - k1 + k1 * (xd*xd+yd*yd))
(Ru,xu,yu are the undistorted coordinates)

So it seems as Ru and Rd were simply exchanged here. I'd be glad if
someone could explain that a little.

The formulas I had were a little wrong, as I incorporated the
normalization wrongly. Also, the signs were wrong. For poly3 it is now:
s = h/2
f(u,v) = -k1*u + k1/s^2*u*v^2 + k1/s^2*u^3
g(u,v) = -k1*v + k1/s^2*u^2*v + k1/s^2*v^3

And poly5:
f(u,v) = k1/s^2*u*v^2 + k1/s^2*u^3 + 2*k2/s^4*u^3*v^2 + k2/s^4*u*v^4 +
k2/s^4*u^5
g(u,v) = k1/s^2*u^2*v + k1/s^2*v^3 + 2*k2/s^4*u^2*v^3 + k2/s^4*u^4*v +
k2/s^4*v^5

I still haven't tested it with reference software, but a little test
case I wrote leads to matching undistorted coordinates for both models
(lensfun and SIP). See the bottom of
https://github.com/neothemachine/lensfunx/blob/master/sip.py

Cheers
Maik

------------------------------------------------------------------------------
_______________________________________________
Lensfun-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lensfun-users

Reply via email to