Ask Your Question

hulo's profile - activity

2015-05-28 02:37:15 -0600 commented answer strange warpAffine precision issue

Thanks Eduardo. I just implemented my own warpAffine function, and it achieves the desired accuracy, even though running time is much worse than OpenCV's warpAffine. This goes in the direction of your explanation, and it seems that OpenCV's warpAffine sacrifices precision for performance...

2015-05-27 12:38:43 -0600 asked a question strange warpAffine precision issue

I am trying to use OpenCVs warpAffine to transform an image. I use the bilinear interpolation option (set by default). When using a very small transformation (e.g., translation of 0.01 pixel), the transformed image is exactly identical to the original. This is problematic since I need a big precision as further computations are performed on the transformed image.

Example:

Mat img_test = (Mat_<double>(5,5) << 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0);
Mat tfm; Mat transf_img_test;
tfm = Mat::eye(2,3,CV_64F);
tfm.at<double>(0,2) = 0.01;
warpAffine( img_test, transf_img_test, tfm, img_test.size(), INTER_LINEAR);
cout << "Original = " << img_test << endl;
cout << "Transformed = " << transf_img_test << endl;

The two images are exactly identical:

Original = [0, 0, 0, 0, 0;
        0, 0, 1, 0, 0;
        0, 0, 1, 0, 0;
        0, 0, 1, 0, 0;
        0, 0, 0, 0, 0]
Transformed = [0, 0, 0, 0, 0;
           0, 0, 1, 0, 0;
           0, 0, 1, 0, 0;
           0, 0, 1, 0, 0;
           0, 0, 0, 0, 0]

Note that when I set

tfm.at<double>(0,2) = 0.5

instead, warpAffine correctly transforms (and interpolates) the image.