Can't understand how to get (x', y') of original (x, y) in image, for Barrel/Pincushion distortion.
The standard distortion equations— ru = rd + k1 rd3 (3rd order), ru = rd + h1 rd3 + h2 rd5 (5th order), or the arctan/tan equations— do not give a clear picture of whether distortion takes the barrel or pincushion form.
Distortion refers to deformation of an image. There are two kinds of distortion, either of which may be present in a lens: barrel distortion, in which magnification decreases with distance from the axis, and pincushion distortion, in which magnification increases with distance from the axis.
Barrel and pincushion distortions can be caused by a stop or aperture. An aperture is a hole or opening, this could be the boundary of the lens. A stop restricts the amount of rays coming into the lens. Barrel distortion is caused when the stop appears before the lens.
Barrel distortion. In barrel distortion, image magnification decreases with distance from the optical axis. The apparent effect is that of an image which has been mapped around a sphere (or barrel).
These radial distortions can usually be classified as either barrel distortions or pincushion distortions. In barrel distortion, image magnification decreases with distance from the optical axis. The apparent effect is that of an image which has been mapped around a sphere (or barrel ).
What is Pincushion Distortion? Pincushion distortion is the opposite of barrel distortion. It causes straight lines to curve inward from the edges to the middle. Telephoto and telephoto-zoom lenses are most commonly associated with pincushion distortion. Images with pincushion distortion will appear squished in. What Causes Pincushion Distortion?
Mathematically, barrel and pincushion distortion are quadratic, meaning they increase as the square of distance from the center. In mustache distortion the quartic (degree 4) term is significant: in the center, the degree 2 barrel distortion is dominant, while at the edge the degree 4 distortion in the pincushion direction dominates.
You can find both pincushion and barrel distortion in zoom lenses that try to cover wide angles and telephoto, such as the AF-S DX NIKKOR 18-140mm f / 3.5-5.6G or the Canon EF-S 18-200mm f/3.5-5.6 IS.
Section 2 of this paper explains the transformation. Basically:
Here I made an example in Mathematica:
simple barrel\pincushion distortion in opencv c++
IplImage* barrel_pincusion_dist(IplImage* img, double Cx,double Cy,double kx,double ky)
{
IplImage* mapx = cvCreateImage( cvGetSize(img), IPL_DEPTH_32F, 1 );
IplImage* mapy = cvCreateImage( cvGetSize(img), IPL_DEPTH_32F, 1 );
int w= img->width;
int h= img->height;
float* pbuf = (float*)mapx->imageData;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
float u= Cx+(x-Cx)*(1+kx*((x-Cx)*(x-Cx)+(y-Cy)*(y-Cy)));
*pbuf = u;
++pbuf;
}
}
pbuf = (float*)mapy->imageData;
for (int y = 0;y < h; y++)
{
for (int x = 0; x < w; x++)
{
*pbuf = Cy+(y-Cy)*(1+ky*((x-Cx)*(x-Cx)+(y-Cy)*(y-Cy)));
++pbuf;
}
}
/*float* pbuf = (float*)mapx->imageData;
for (int y = 0; y < h; y++)
{
int ty= y-Cy;
for (int x = 0; x < w; x++)
{
int tx= x-Cx;
int rt= tx*tx+ty*ty;
*pbuf = (float)(tx*(1+kx*rt)+Cx);
++pbuf;
}
}
pbuf = (float*)mapy->imageData;
for (int y = 0;y < h; y++)
{
int ty= y-Cy;
for (int x = 0; x < w; x++)
{
int tx= x-Cx;
int rt= tx*tx+ty*ty;
*pbuf = (float)(ty*(1+ky*rt)+Cy);
++pbuf;
}
}*/
IplImage* temp = cvCloneImage(img);
cvRemap( temp, img, mapx, mapy );
cvReleaseImage(&temp);
cvReleaseImage(&mapx);
cvReleaseImage(&mapy);
return img;
}
more complicated form http://opencv.willowgarage.com/documentation/camera_calibration_and_3d_reconstruction.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With