Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openCV equivalent of a PIL resize ANTIALIAS?

In PIL the highest quality resize from what I've seen seems to be:

img = img.resize((n1, n2), Image.ANTIALIAS)

For openCV this seems to be the way to do it:

small = cv2.resize(image, (0,0), fx=0.5, fy=0.5) 

So my question is, is there an additional parameter needed or will this reduce the size with least quality lost?

like image 810
alfredox Avatar asked Nov 07 '15 00:11

alfredox


People also ask

What is resize in OpenCV?

OpenCV Python – Resize image. Resizing an image means changing the dimensions of it, be it width alone, height alone or changing both of them. Also, the aspect ratio of the original image could be preserved in the resized image.

Which function is used to resize an image in OpenCV?

dsize : It is the desired size of the output image, it can be a new height and width. fx : Scale factor along the horizontal axis. fy : Scale factor along the vertical axis. interpolation : It gives us the option of different methods of resizing the image.

What is FX and FY in cv2 resize?

INTER_CUBIC) , where fx is the scaling factor along the horizontal axis and fy along the vertical axis.


1 Answers

From the documentation:

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

The default for resize is CV_INTER_LINEAR. Change the interpolation to CV_INTER_AREA since you wish to shrink the image:

small = cv2.resize(image, (0,0), fx=0.5, fy=0.5, interpolation = cv2.INTER_AREA)

You may wish to compare the results of both interpolations for visual verification that you are getting the best quality.

like image 123
chembrad Avatar answered Sep 18 '22 12:09

chembrad