Ask Your Question
0

What does the MapAffine::inverseMap() function do?

asked 2017-01-29 10:36:20 -0600

What does the following function Inversewarp do? I expected it to use the "this" affine mapping and warp the image, but everytime I run I get the exact same warp - doesnt matter what my mapping is - the code seems to suggest a constant map. I am new to opencv, so I could be missing something basic. What am I missing?

It is from opencv/source/opencv_contrib/modules/reg/src/mapaffine.cpp

    void MapAffine::inverseWarp(const Mat& img1, Mat& img2) const
{
    // Rows and columns in destination
    Mat dest_r, dest_c;
    dest_r.create(img1.size(), CV_32FC1);
    dest_c.create(img1.size(), CV_32FC1);
    for(int r_i = 0; r_i < img1.rows; ++r_i)
    {
        for(int c_i = 0; c_i < img1.cols; ++c_i)
        {
            dest_c.at<float>(r_i, c_i) = float(c_i*linTr_(0, 0) + r_i*linTr_(0, 1) + shift_(0));
            dest_r.at<float>(r_i, c_i) = float(c_i*linTr_(1, 0) + r_i*linTr_(1, 1) + shift_(1));
        }
    }

    //remap(img1, img2, dest_c, dest_r, INTER_CUBIC, BORDER_REPLICATE);
    // Parts that cannot be interpolated will be as in img1 (BORDER_TRANSPARENT means that
    // remap will not touch them).
    img1.copyTo(img2);
    remap(img1, img2, dest_c, dest_r, INTER_CUBIC, BORDER_TRANSPARENT);
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-01-29 10:58:20 -0600

LBerger gravatar image

updated 2017-01-29 13:47:34 -0600

mapping depends of linTr_ Mat and shift_ It is a constant map because there is no method to change transfomr. You can set affine transform only in constructor (You can compose current map with another map)

see sample

All is in sample :

Simulate a transformation img1 (reference) in img2 new image img2= [linTr shift] img1

Matx<double, 2, 2> linTr(1., 0.1, -0.01, 1.);
Vec<double, 2> shift(1., 1.);
MapAffine mapTest(linTr, shift);
mapTest.warp(img1, img2);

Now we want to find a transformation between img1 and img2. Of course projTr is unknown

MapperGradAffine mapper;
MapperPyramid mappPyr(mapper);
Ptr<Map> mapPtr;
mappPyr.calculate(img1, img2, mapPtr);

we find an estimation of projTr

--- Testing affine mapper ---
real --> [1, 0.1;
 -0.01, 1]
[1;
 1]
estimated --> [0.9999473655589267, 0.1009308875914515;
 -0.009985648108361955, 0.9998113921559071]
[0.9551427088080436;
 1.024064674225132]

and finally we transform img2 in dest to check difference between img1 and dest. We must inverse transformation using inverseWarp :

Mat dest;
mapAff->inverseWarp(img2, dest);
showDifference(img1, dest, DIFF_REGPIX_IM);
edit flag offensive delete link more

Comments

I am trying to first calculate the affine mapping between frames in a video and depending on the time difference between frames - I get different mappings. It is only when I use these mappings to do inversewarp i always get the same result.

poohmaan gravatar imagepoohmaan ( 2017-01-29 12:21:50 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-29 10:36:20 -0600

Seen: 324 times

Last updated: Jan 29 '17