Ask Your Question
0

Polynomial

asked 2020-10-06 08:28:15 -0600

RickF gravatar image

I am looking for a polynomial warping filter that takes coefficients a, b, as inputs, and can warp the image.

X=a0 +a1x+ a2y + a3xy + a4x^2 +a5y^2

Y=b0 + b1x + b2y + b3xy+ b4x^2 + b5y2

For example, this can be used for X ray pin cushion un distortion where camera parameters are unknown.

as an example, this can be done in MATLAB with

tform= fitgeotrans(points, distortedpoints,'polynomial', 2); % create 2 nd degree polynomial fit transformation ImgOut = imwarp(Img, tform);

I have looked at the opencv docs, but don't see the equivalent- recall that there is nothing known about the "camera" in this case.

Is there something in opencv to do this? I need to bring the code over to c++ and I dint want to re invent any wheels.

Thanks

Rick

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-10-06 09:12:37 -0600

berak gravatar image

updated 2020-10-06 09:34:57 -0600

you can use opencv's builtin remapping to warp the image, but you have to calculate the mapping coords manually, similar to this:

Mat_<float> map_x(img.size()), map_y(img.size());
for( int i = 0; i < map_x.rows; i++ )
{
    for( int j = 0; j < map_x.cols; j++ )
    {
           map_x(i,j) = a0 + a1*j + a2*i + a3*j*i + a4*j*j + a5*i*i;
           map_y(i,j) = b0 + b1*j + b2*i + b3*j*i + b4*j*j + b5*i*i;
    }
}

Mat dst;
remap(img, dst, map_x, map_y, INTER_LINEAR, BORDER_CONSTANT, Scalar(0, 0, 0) );
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-10-06 08:28:15 -0600

Seen: 1,590 times

Last updated: Oct 06 '20