Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Bug in warpAffine?

I think the following examples shows a bug in warpAffine: Mat x(1,20, CV_32FC1); for (int iCol(0); iCol<x.cols; icol++)="" {="" x.col(icol).setto(icol);="" }="" mat="" crop;="" point2d="" c(10.,="" 0.);="" double="" scale(1.3);="" int="" cropsz(11);="" double="" vals[6]="{" scale,="" 0.0,="" c.x-(cropsz="" 2)*scale,="" 0.0,="" scale,="" c.y="" };="" mat="" map(2,="" 3,="" cv_64fc1,="" vals);="" warpaffine(x,="" crop,="" map,="" size(cropsz,="" 1),="" warp_inverse_map="" |="" inter_linear);="" float="" dx="(crop.at&lt;float">(0, crop.cols-1) - crop.at<float>(0, 0))/(crop.cols-1); Mat constGrad = crop.clone().setTo(0); for (int iCol(0); iCol<constgrad.cols; icol++)="" {="" constgrad.col(icol)="c.x" +="" (icol-cropsz="" 2)*scale;="" }="" mat="" diff="crop" -="" constgrad;="" double="" err="norm(diff," norm_inf);="" if="" (err="">1e-4) { cout << "Problem" << endl; } I create an image with entries 0, 1, 2, ...n-1, and cut a region around (10,0) with scale 1.3. I also create an expected image constGrad. However, they are not the same. It's not a boundary stuff problem, the same happens at the inner of an image and also without WARP_INVERSE_MAP The error is at most about 0.03.

Bug in warpAffine?

I think the following examples shows a bug in warpAffine: warpAffine:

   Mat x(1,20, CV_32FC1);
    for (int iCol(0); iCol<x.cols; icol++)="" {="" x.col(icol).setto(icol);="" }="" mat="" crop;="" point2d="" c(10.,="" 0.);="" double="" scale(1.3);="" int="" cropsz(11);="" double="" vals[6]="{" scale,="" 0.0,="" c.x-(cropsz="" 2)*scale,="" 0.0,="" scale,="" c.y="" };="" mat="" map(2,="" 3,="" cv_64fc1,="" vals);="" warpaffine(x,="" crop,="" map,="" size(cropsz,="" 1),="" warp_inverse_map="" |="" inter_linear);="" float="" dx="(crop.at&lt;float">(0, iCol++) { x.col(iCol).setTo(iCol); }
    Mat crop;
    Point2d c(10., 0.);
    double scale(1.3);
    int cropSz(11);
    double vals[6] = { scale, 0.0, c.x-(cropSz/2)*scale, 0.0, scale, c.y };
    Mat map(2, 3, CV_64FC1, vals);
    warpAffine(x, crop, map, Size(cropSz, 1), WARP_INVERSE_MAP |  INTER_LINEAR);
    float dx = (crop.at<float>(0, crop.cols-1) - crop.at<float>(0, 0))/(crop.cols-1);
    Mat constGrad = crop.clone().setTo(0);
    for (int iCol(0); iCol<constgrad.cols; icol++)="" {="" constgrad.col(icol)="c.x" +="" (icol-cropsz="" 2)*scale;="" }="" mat="" diff="crop" -="" constgrad;="" double="" err="norm(diff," norm_inf);="" if="" (err="">1e-4) iCol<constGrad.cols; iCol++) {
      constGrad.col(iCol) = c.x + (iCol-cropSz/2)*scale;
    }
    Mat diff = crop - constGrad;
    double err = norm(diff, NORM_INF);
    if (err>1e-4) {
      cout << "Problem" << endl;
    }

I create an image with entries 0, 1, 2, ...n-1, and cut a region around (10,0) with scale 1.3. I also create an expected image constGrad. However, they are not the same. It's not a boundary stuff problem, the same happens at the inner of an image and also without WARP_INVERSE_MAP The error is at most about 0.03.

Bug in warpAffine?

I think the following examples shows a bug in warpAffine:

   Mat x(1,20, CV_32FC1);
    for (int iCol(0); iCol<x.cols; iCol++) { x.col(iCol).setTo(iCol); }
    Mat crop;
    Point2d c(10., 0.);
    double scale(1.3);
    int cropSz(11);
    double vals[6] = { scale, 0.0, c.x-(cropSz/2)*scale, 0.0, scale, c.y };
    Mat map(2, 3, CV_64FC1, vals);
    warpAffine(x, crop, map, Size(cropSz, 1), WARP_INVERSE_MAP |  INTER_LINEAR);
    float dx = (crop.at<float>(0, crop.cols-1) - crop.at<float>(0, 0))/(crop.cols-1);
    Mat constGrad = crop.clone().setTo(0);
    for (int iCol(0); iCol<constGrad.cols; iCol++) {
      constGrad.col(iCol) = c.x + (iCol-cropSz/2)*scale;
    }
    Mat diff = crop - constGrad;
    double err = norm(diff, NORM_INF);
    if (err>1e-4) {
      cout << "Problem" "Problem:" << endl;
      cout << "computed output: " << crop << endl;
      cout << "expected output: " << constGrad << endl;
      cout << "difference: " << diff << endl;
      Mat dxImg;
      Mat dxFilt(1, 2, CV_32FC1);
      dxFilt.at<float>(0) = -1.0f;
      dxFilt.at<float>(1) = 1.0f;
      filter2D(crop, dxImg, crop.depth(), dxFilt);
      cout << "x-derivative in computed output: " << dxImg(Rect(1,0,10,1)) << endl;
      cout << "Note: We expect a constant difference of 1.3" << endl;
    }

Here is the program output:

Problem:
computed output: [3.5, 4.8125, 6.09375, 7.40625, 8.6875, 10, 11.3125, 12.59375, 13.90625, 15.1875, 16.5]
expected output: [3.5, 4.8000002, 6.0999999, 7.4000001, 8.6999998, 10, 11.3, 12.6, 13.9, 15.2, 16.5]
difference: [0, 0.012499809, -0.0062499046, 0.0062499046, -0.012499809, 0, 0.012499809, -0.0062503815, 0.0062503815, -0.012499809, 0]
x-derivative in computed output: [1.3125, 1.28125, 1.3125, 1.28125, 1.3125, 1.3125, 1.28125, 1.3125, 1.28125, 1.3125]
Note: We expect a constant difference of 1.3

I create an image with entries 0, 1, 2, ...n-1, and cut a region around (10,0) with scale 1.3. I also create an expected image constGrad. However, they are not the same. It's same. Even more, since the input image has a constant derivative in x-direction and the mapping is affine, I expect also a constant gradient in the resulting image. The problem is not a boundary stuff problem, the same happens at the inner of an image and image. It's also without WARP_INVERSE_MAP The error is at most about 0.03.not related to WARP_INVERSE_MAP.

Bug in warpAffine?

I think the following examples shows a bug in warpAffine:

   Mat x(1,20, CV_32FC1);
    for (int iCol(0); iCol<x.cols; iCol++) { x.col(iCol).setTo(iCol); }
    Mat crop;
    Point2d c(10., 0.);
    double scale(1.3);
    int cropSz(11);
    double vals[6] = { scale, 0.0, c.x-(cropSz/2)*scale, 0.0, scale, c.y };
    Mat map(2, 3, CV_64FC1, vals);
    warpAffine(x, crop, map, Size(cropSz, 1), WARP_INVERSE_MAP |  INTER_LINEAR);
    float dx = (crop.at<float>(0, crop.cols-1) - crop.at<float>(0, 0))/(crop.cols-1);
    Mat constGrad = crop.clone().setTo(0);
    for (int iCol(0); iCol<constGrad.cols; iCol++) {
      constGrad.col(iCol) = c.x + (iCol-cropSz/2)*scale;
    }
    Mat diff = crop - constGrad;
    double err = norm(diff, NORM_INF);
    if (err>1e-4) {
      cout << "Problem:" << endl;
      cout << "computed output: " << crop << endl;
      cout << "expected output: " << constGrad << endl;
      cout << "difference: " << diff << endl;
      Mat dxImg;
      Mat dxFilt(1, 2, CV_32FC1);
      dxFilt.at<float>(0) = -1.0f;
      dxFilt.at<float>(1) = 1.0f;
      filter2D(crop, dxImg, crop.depth(), dxFilt);
      cout << "x-derivative in computed output: " << dxImg(Rect(1,0,10,1)) << endl;
      cout << "Note: We expect a constant difference of 1.3" << endl;
    }

Here is the program output:

Problem:
computed output: [3.5, 4.8125, 6.09375, 7.40625, 8.6875, 10, 11.3125, 12.59375, 13.90625, 15.1875, 16.5]
expected output: [3.5, 4.8000002, 6.0999999, 7.4000001, 8.6999998, 10, 11.3, 12.6, 13.9, 15.2, 16.5]
difference: [0, 0.012499809, -0.0062499046, 0.0062499046, -0.012499809, 0, 0.012499809, -0.0062503815, 0.0062503815, -0.012499809, 0]
x-derivative in computed output: [1.3125, 1.28125, 1.3125, 1.28125, 1.3125, 1.3125, 1.28125, 1.3125, 1.28125, 1.3125]
Note: We expect a constant difference of 1.3

I create an image with entries 0, 1, 2, ...n-1, and cut a region around (10,0) with scale 1.3. I also create an expected image constGrad. However, they are not the same. Even more, since the input image has a constant derivative in x-direction and the mapping is affine, I expect also a constant gradient in the resulting image. The problem is not a boundary stuff problem, the same happens at the inner of an image. It's also not related to WARP_INVERSE_MAP.WARP_INVERSE_MAP. Is this a known issue? any comments on this?

Bug in warpAffine?

I think the following examples shows a bug in warpAffine:

   Mat x(1,20, CV_32FC1);
    for (int iCol(0); iCol<x.cols; iCol++) { x.col(iCol).setTo(iCol); }
    Mat crop;
    Point2d c(10., 0.);
    double scale(1.3);
    int cropSz(11);
    double vals[6] = { scale, 0.0, c.x-(cropSz/2)*scale, 0.0, scale, c.y };
    Mat map(2, 3, CV_64FC1, vals);
    warpAffine(x, crop, map, Size(cropSz, 1), WARP_INVERSE_MAP |  INTER_LINEAR);
    float dx = (crop.at<float>(0, crop.cols-1) - crop.at<float>(0, 0))/(crop.cols-1);
    Mat constGrad = crop.clone().setTo(0);
    for (int iCol(0); iCol<constGrad.cols; iCol++) {
      constGrad.col(iCol) = c.x + (iCol-cropSz/2)*scale;
    }
    Mat diff = crop - constGrad;
    double err = norm(diff, NORM_INF);
    if (err>1e-4) {
      cout << "Problem:" << endl;
      cout << "computed output: " << crop << endl;
      cout << "expected output: " << constGrad << endl;
      cout << "difference: " << diff << endl;
      Mat dxImg;
      Mat dxFilt(1, 2, CV_32FC1);
      dxFilt.at<float>(0) = -1.0f;
      dxFilt.at<float>(1) = 1.0f;
      filter2D(crop, dxImg, crop.depth(), dxFilt);
      cout << "x-derivative in computed output: " << dxImg(Rect(1,0,10,1)) << endl;
      cout << "Note: We expect a constant difference of 1.3" << endl;
    }

Here is the program output:

Problem:
computed output: [3.5, 4.8125, 6.09375, 7.40625, 8.6875, 10, 11.3125, 12.59375, 13.90625, 15.1875, 16.5]
expected output: [3.5, 4.8000002, 6.0999999, 7.4000001, 8.6999998, 10, 11.3, 12.6, 13.9, 15.2, 16.5]
difference: [0, 0.012499809, -0.0062499046, 0.0062499046, -0.012499809, 0, 0.012499809, -0.0062503815, 0.0062503815, -0.012499809, 0]
x-derivative in computed output: [1.3125, 1.28125, 1.3125, 1.28125, 1.3125, 1.3125, 1.28125, 1.3125, 1.28125, 1.3125]
Note: We expect a constant difference of 1.3

I create an image with entries 0, 1, 2, ...n-1, and cut a region around (10,0) with scale 1.3. I also create an expected image constGrad. However, they are not the same. Even more, since the input image has a constant derivative in x-direction and the mapping is affine, I expect also a constant gradient in the resulting image. The problem is not a boundary stuff problem, the same happens at the inner of an image. It's also not related to WARP_INVERSE_MAP. WARP_INVERSE_MAP.

Is this a known issue? any comments on this?