# opencv::remap() How to remap an Image to another Image with different size

Now I have Image A and I want to remap it to Image B which has a different size than Image A.

For each pixel coordinate (x, y), it has the coordinate (r, theta) on image B.

Can any one tell me how to realize it, preferably with sample code? Because I don't really understand the arguments map_x, map_y in the remap function.

Can somebody explain it for me? Thanks a lot!

## Answers

remap decides where to map a pixel (i,j) by checking map_x(i,j) and map_y(i,j). At the end, your pixel (i,j) is mapped to (map_x(i,j),map_y(i,j)).

In your case, your pixel (x,y) should be mapped to (sqrt(x^2+y^2), atan(y/x)); so you need to populate map_x and map_y using these cart to polar equations:

for(int i = 0; i < src.rows; i++ ) { for(int j = 0; j < src.cols; j++ ) { map_x.at<float>(i,j) = sqrt(i^2 + j^2); map_y.at<float>(i,j) = atan(j/i); }}

You may also want to look at cartToPolar