How to create thumbnails using opencv-python?

Question:

I’m trying to downsample my image(using anti-aliasing) using Python-Pillow's im.thumbnail() method.

My code looks like:

MAXSIZE = 1024
im.thumbnail(MAXSIZE, Image.ANTIALIAS)

Can you tell me some alternative in opencv-python to perform this re-sizing operation ?

Answers:

You can use cv2.resize . Documentation here: http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#resize

In your case, assuming the input image im is a numpy array:

maxsize = (1024,1024) 
imRes = cv2.resize(im,maxsize,interpolation=cv2.CV_INTER_AREA)

There are different types of interpolation available (INTER_CUBIC, INTER_NEAREST, INTER_AREA,…) but according to the documentation if you need to shrink the image, you should get better results with CV_INTER_AREA.

Answered By: Algold

I got error:
AttributeError: module ‘cv2’ has no attribute ‘CV_INTER_AREA’

Following is worked for me:

imRes = cv2.resize(im,maxsize,interpolation=cv2.INTER_AREA
Answered By: Oliver