Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formulas for Barrel/Pincushion distortion

Can't understand how to get (x', y') of original (x, y) in image, for Barrel/Pincushion distortion.

like image 219
breethe Avatar asked Jun 01 '11 10:06

breethe


People also ask

What is the formula of 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.

What is pincushion and barrel distortion?

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.

What causes barrel and pincushion distortion?

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.

What is barrel distortion physics?

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).

What are barrel and pincushion distortions?

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 and how to fix it?

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?

What is the degree of distortion in a barrel?

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.

Which zoom lenses have barrel distortion and pincushion?

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.


2 Answers

Section 2 of this paper explains the transformation. Basically:

enter image description here

Here I made an example in Mathematica:

enter image description here

like image 98
Dr. belisarius Avatar answered Oct 28 '22 13:10

Dr. belisarius


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

like image 25
mrgloom Avatar answered Oct 28 '22 14:10

mrgloom