In order to resize the image, OpenCV has a resize() function, which takes the image, dimensions, and interpolation algorithm as input. Various interpolation algorithms can be used to interpolate the new pixel values. The following are the interpolation algorithms, which can be used to resize the image:
- cv2.INTER_AREA: This algorithm is preferred for shrinking the image
- cv2.INTER_CUBIC: This algorithm is preferred for zooming (slow)
- cv2.INTER_LINEAR: This algorithm is preferred for zooming
- cv2.INTER_LINEAR: This is the default algorithm
The following is an example of resizing an image:
>>> import cv2>>> img = cv2.imread("image.jpg")>>> r,c = img.shape[:2]>>> new_img = cv2.resize(img, (2*r,2*c), interpolation = cv2.INTER_CUBIC)>>> ...