binford
binford

Reputation: 1805

How do I use cvResize/resize correctly?

I have trouble resizing a 6x6 image to 120x120. It looks like the resized image is somewhat shifted by 1 pixel. This happens with the cvResize and with cv::resize. My code looks like this:

warpPerspective(greyImg, warpedImg, homography, Size(6, 6));
Mat bigWarpedImg = Mat(120,120,CV_8UC1);
resize(warpedImg, bigWarpedImg, Size(0,0), 20, 20, INTER_NEAREST);

warpedImg looks like this (I resized it with gimp to make it easier to recognize): http://picasaweb.google.com/103165673068768416583/Opencv#5565090881969794706

bigWarpedImg looks like this: http://picasaweb.google.com/103165673068768416583/Opencv#5565090880773608210

As you can see, in bigWarpedImg the left and upper border is to small whereas the right and bottom border is too thick. It looks like a bug in OpenCV. Is this one or do I use this function incorrectly?

Upvotes: 0

Views: 7706

Answers (2)

Utkarsh Sinha
Utkarsh Sinha

Reputation: 3305

It could be because you're using nearest interpolation. Try the better ones (I think bicubic).

Upvotes: 0

etarion
etarion

Reputation: 17169

Mat bigWarpedImg = Mat(120,120,CV_8UC1);

this line is unneccessary - resize will allocate the target Mat to make it fit, so Mat bigWarpedImg would be fine.

Not sure about the resizing - I always use the

resize(warpedImg, bigWarpedImg, Size(120,120), 0, 0, INTER_NEAREST);

form of resize and never noticed such behaviour. I'd say it's a bug though, from the documentation it shouldn't act like that.

Upvotes: 2

Related Questions