This section is all about image resizing. Resizing using OpenCV can be performed by using cv2.resize(). The preferred interpolation methods are cv.INTER_AREA for shrinking and cv.INTER_CUBIC for zooming. By default, the interpolation method used is cv.INTER_LINEAR for all resizing purposes:
- First, we will import the numpy, openCV, and matplotlib (mpimg and pyplot) libraries:
In[1]: import cv2
In[2]: import numpy as np
In[3]: import matplotlib.image as mpimg
In[4]: from matplotlib import pyplot as plt
In[5]: %matplotlib inline
- Then we read in the input image:
In[6]: image = cv2.imread('test_image.jpg')
In[7]: cv2.imshow('Original Image', image)
In[8]: cv2.waitKey()
In[9]: cv2.destroyAllWindows()
The input image looks like this:
Fig 4.59: Input image
- The height and width of the image are as follows:
In[10]: height, width = image.shape[:2]
In[11]: height
579
In[12]: width
530
- Next, we perform the resize using OpenCV:
In...