# Polynomial

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 close merge delete

Sort by ยป oldest newest most voted

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

more

Official site

GitHub

Wiki

Documentation

## Stats

Seen: 736 times

Last updated: Oct 06 '20