Ask Your Question

Do I have to worry about borders when I resize a large image in blocks?

asked 2015-08-19 04:09:52 -0500

ChaoyuanYeh gravatar image

updated 2015-08-19 05:19:00 -0500


If I first divide an image into 4 (2x2) blocks, resize them by 50% in each dimension separately and put them back together, will the image be different from an image directed resized from the original. I mean will I have to worry that borders between blocks will have some artifacts because they now lose neighbors during calculation?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-08-19 11:06:27 -0500

updated 2015-11-15 15:27:31 -0500

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()


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));


img = img > 0;
return 0;    


image description

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

edit flag offensive delete link more


i made a change on the code. used absdiff to check changes ( thank to @pklab who remind me )

sturkmen gravatar imagesturkmen ( 2015-11-15 15:34:47 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-08-19 04:09:52 -0500

Seen: 213 times

Last updated: Nov 15 '15