Ask Your Question

Revision history [back]

i tried to test the case with the code below

#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

using namespace cv;
using namespace std;

int main()
{

String InterpolationFlags[] = {"INTER_NEAREST","INTER_LINEAR","INTER_CUBIC","INTER_AREA","INTER_LANCZOS4"};


for( int i=0; i < 5; i++)
{
Mat img = imread("fruits.jpg");

Mat roi1 =img(Rect( 0, 0, img.cols/2, img.rows/2)).clone();
Mat roi2 =img(Rect( img.cols/2, 0, img.cols/2, img.rows/2)).clone();
Mat roi3 =img(Rect( 0, img.rows/2, img.cols/2, img.rows/2)).clone();
Mat roi4 =img(Rect( img.cols/2, img.rows/2, img.cols/2, img.rows/2)).clone();

resize( img, img, Size( img.cols/2, img.rows/2 ),0,0, i);

resize( roi1, roi1, Size( roi1.cols/2, roi1.rows/2 ),0,0, i);
resize( roi2, roi2, Size( roi2.cols/2, roi2.rows/2 ),0,0, i);
resize( roi3, roi3, Size( roi3.cols/2, roi3.rows/2 ),0,0, i);
resize( roi4, roi4, Size( roi4.cols/2, roi4.rows/2 ),0,0, i);

Mat rroi1 =img(Rect( 0, 0, img.cols/2, img.rows/2));
Mat rroi2 =img(Rect( img.cols/2, 0, img.cols/2, img.rows/2));
Mat rroi3 =img(Rect( 0, img.rows/2, img.cols/2, img.rows/2));
Mat rroi4 =img(Rect( img.cols/2, img.rows/2, img.cols/2, img.rows/2));

rroi1 = rroi1 - roi1;
rroi2 = rroi2 - roi2;
rroi3 = rroi3 - roi3;
rroi4 = rroi4 - roi4;

img = img > 0;
imshow(InterpolationFlags[i],img);
//imshow("roi1",roi1);
//imshow("roi2",roi2);
//imshow("roi3",roi3);
//imshow("roi4",roi4);
waitKey(0);
}

return 0;

}

results

image description

as seen on the result images the answer depends on InterpolationFlags.

i tried to test the case with the code below

#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

using namespace cv;
using namespace std;

int main()
{

String InterpolationFlags[] = {"INTER_NEAREST","INTER_LINEAR","INTER_CUBIC","INTER_AREA","INTER_LANCZOS4"};
{"INTER_NEAREST","INTER_LINEAR","INTER_CUBIC","INTER_AREA","INTER_LANCZOS4"};    

for( int i=0; i < 5; i++)
{
Mat img = imread("fruits.jpg");

Mat roi1 =img(Rect( 0, 0, img.cols/2, img.rows/2)).clone();
Mat roi2 =img(Rect( img.cols/2, 0, img.cols/2, img.rows/2)).clone();
Mat roi3 =img(Rect( 0, img.rows/2, img.cols/2, img.rows/2)).clone();
Mat roi4 =img(Rect( img.cols/2, img.rows/2, img.cols/2, img.rows/2)).clone();

resize( img, img, Size( img.cols/2, img.rows/2 ),0,0, i);

resize( roi1, roi1, Size( roi1.cols/2, roi1.rows/2 ),0,0, i);
resize( roi2, roi2, Size( roi2.cols/2, roi2.rows/2 ),0,0, i);
resize( roi3, roi3, Size( roi3.cols/2, roi3.rows/2 ),0,0, i);
resize( roi4, roi4, Size( roi4.cols/2, roi4.rows/2 ),0,0, i);

Mat rroi1 =img(Rect( 0, 0, img.cols/2, img.rows/2));
Mat rroi2 =img(Rect( img.cols/2, 0, img.cols/2, img.rows/2));
Mat rroi3 =img(Rect( 0, img.rows/2, img.cols/2, img.rows/2));
Mat rroi4 =img(Rect( img.cols/2, img.rows/2, img.cols/2, img.rows/2));

rroi1 = rroi1 - roi1;
rroi2 = rroi2 - roi2;
rroi3 = rroi3 - roi3;
rroi4 = rroi4 - roi4;
absdiff(rroi1,roi1,rroi1);
absdiff(rroi2,roi2,rroi2);
absdiff(rroi3,roi3,rroi3);
absdiff(rroi4,roi4,rroi4);

img = img > 0;
imshow(InterpolationFlags[i],img);
//imshow("roi1",roi1);
//imshow("roi2",roi2);
//imshow("roi3",roi3);
//imshow("roi4",roi4);
waitKey(0);
}
}    
return 0;
0;    
}

results

image description

as seen on the result images the answer depends on InterpolationFlags.