resize and remap functions utterly wrong
As far as I can tell, both remap and resize functions are implemented incorrectly (at least with default bilinear interpolation). Consider the following code:
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char **argv)
{
int inputSize=2;
Mat test(inputSize,inputSize,CV_32FC1);
test.at<float>(0,0)=1.0;
test.at<float>(0,1)=2.0;
test.at<float>(1,0)=3.0;
test.at<float>(1,1)=4.0;
int size=4;
Mat output;
resize(test,output,Size(size,size),0.0,0.0,INTER_LINEAR);
for(int ridx=0;ridx<size;++ridx)
{
for(int cidx=0;cidx<size;++cidx)
printf("%f ",output.at<float>(ridx,cidx));
printf("\n");
}
printf("\n");
size = 5;
Mat rowMap(size,size,CV_32FC1),colMap(size,size,CV_32FC1);
for(int ridx=0;ridx<size;++ridx)
for(int cidx=0;cidx<size;++cidx)
{
rowMap.at<float>(ridx,cidx) = ridx*(static_cast<float>(inputSize-1)/(size-1));
colMap.at<float>(ridx,cidx) = cidx*(static_cast<float>(inputSize-1)/(size-1));
}
remap(test,output,colMap,rowMap,INTER_LINEAR);
for(int ridx=0;ridx<size;++ridx)
{
for(int cidx=0;cidx<size;++cidx)
printf("%f ",rowMap.at<float>(ridx,cidx));
printf("\n");
}
printf("\n");
for(int ridx=0;ridx<size;++ridx)
{
for(int cidx=0;cidx<size;++cidx)
printf("%f ",colMap.at<float>(ridx,cidx));
printf("\n");
}
printf("\n");
for(int ridx=0;ridx<size;++ridx)
{
for(int cidx=0;cidx<size;++cidx)
printf("%f ",output.at<float>(ridx,cidx));
printf("\n");
}
return 0;
}
And output:
1.000000 1.250000 1.750000 2.000000
1.500000 1.750000 2.250000 2.500000
2.500000 2.750000 3.250000 3.500000
3.000000 3.250000 3.750000 4.000000
0.000000 0.000000 0.000000 0.000000
0.333333 0.333333 0.333333 0.333333
0.666667 0.666667 0.666667 0.666667
1.000000 1.000000 1.000000 1.000000
0.000000 0.333333 0.666667 1.000000
0.000000 0.333333 0.666667 1.000000
0.000000 0.333333 0.666667 1.000000
0.000000 0.333333 0.666667 1.000000
1.000000 1.343750 1.656250 2.000000
1.687500 2.031250 2.343750 2.687500
2.312500 2.656250 2.968750 3.312500
3.000000 3.343750 3.656250 4.000000
The results for resize and remap should both be smooth in 1/3 intervals - I don't know what the heck opencv is doing. To me, these seem completely inaccurate results. Please enlighten me!