简体   繁体   中英

How to create thumbnails using opencv-python?

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM