openCV equivalent of a PIL resize ANTIALIAS?

alfredox picture alfredox · Nov 7, 2015 · Viewed 9.1k times · Source

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?

Answer

chembrad picture chembrad · Nov 7, 2015

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.