OpenCV resize quality

asked 2016-05-13 00:37:06 -0500

pnus gravatar image

I am trying to resize a set of images using OpenCV. The resolution is correct, but the quality of the image degrades. However, if I do a manual resize through Apple Preview, the image quality is not affected. I am making all of these images smaller, rather than blowing them up. Here are two images comparing the quality. Please note the jagged spokes and jagged top tube of the bike:

Bad Resize

Bad resize

* Good Resize using Apple Preview* Good resize using Apple Preview

Here is my code:

cv::Mat srcimg = cv::imread(src_filepath);
cv::Mat destimg = cv::imread(lowres_path);
cv::Size img_size = srcimg.size();
int img_width = img_size.width;
int img_height = img_size.height;
double percentage = 1000.0/(img_width);
double new_height = img_height * percentage;
cv::Size new_size = cv::Size(1000.0, new_height);
cv::resize(srcimg, destimg, new_size,0,0,CV_INTER_LANCZOS4);
cv::imwrite(lowres_path, destimg);

I've messed with the the interpolation but that seems to have no effect on the image.

edit retag flag offensive close merge delete



documentation says:

To shrink an image, it will generally look best with cv::INTER_AREA interpolation, whereas to enlarge an image, it will generally look best with cv::INTER_CUBIC (slow) or cv::INTER_LINEAR (faster but still looks OK).
sturkmen gravatar imagesturkmen ( 2016-05-13 08:26:00 -0500 )edit