as the pic says,left is the distort pixel,right is the undistort pixel,r = root of (xx + yy),k is radial coefficients,p is tangential distortion coefficients.
if we know right,we can get the corresponding left without iterating.
if we know left,it is hard to get right,we can get it through iterating.but i wonder why we can get it by iterate(as far as i know,it must be convergent),so anyone can explain it in math theory/formula?
source code bellow
// compensate distortion iteratively
for( int j = 0; j < iters; j++ )//iters = 5
double r2 = x*x + y*y;
double icdist = (1 + ((k*r2 + k)*r2 + k)*r2)/(1 + ((k*r2 + k)*r2 + k)*r2);
double deltaX = 2*k*x*y + k*(r2 + 2*x*x)+ k*r2+k*r2*r2;
double deltaY = k*(r2 + 2*y*y) + 2*k*x*y+ k*r2+k*r2*r2;
x = (x0 - deltaX)*icdist;
y = (y0 - deltaY)*icdist;
This question / answer might help:
The distortion function is modeled as a Taylor series. I think you could just swap the order of the distorted / undistorted coordinates and compute an inverse function, too. Without an inverse function, though, you have to come up with some other way to undistort points, and an iterative approach works. A word of warning: 5 iterations is not enough if your lens has significant distortion. Newer versions of OpenCV accept a TermCriteria parameter which allows you to specify max iterations. When I care about accuracy (which is pretty much always) I set the maximum iterations quite high. I use 40. For my lens it makes a huge difference compared to 5
thanks . i have seen the link you post.
but i still wonder how we can ensure it is convergent for we use iterate to solve it
I’m not sure it is guaranteed to converge in all cases, but if you are working in a well-behaved region of the distortion function, it will converge. My understanding of how the distortion function works is that it it maps undistorted radius (distance from the image center to a given point) to a distorted radius - this tells you how much closer / further from the center the distorted point is.
The function can’t be correctly inverted by simply taking the reciprocal of the rational expression, but you can get a reasonable estimate by doing this. You then fine-tune the estimate by iterating, making smaller and smaller adjustments at each iteration. I think this works in most cases because your first estimate is a reasonable starting point for the search.
If you are looking for a proof that it will converge (or under which conditions it will/won’t converge), I don’t have anything for you. If you do find something, please share it - I would be interested to learn more.
sure,i am very interested in it .as soon as I get it ,I will post here for share.
much thanks for you:)