Image Interpolation using OpenCV-Python

Now, let’s do the same using OpenCV on a real image. First, let’s take an image, either you can load one or can make own image. Loading an image from the device looks like this

Python

1

2

3

4

importcv2

importnumpy asnp

img=cv2.imread('C:/New folder/apple.jpg')

This is a 20×22 apple image which looks like this.

Now, let’s zoom it 10 times using each interpolation method. The OpenCV command for doing this is

where fx and fy are scale factor along x and y and interpolation flag refers to which method we are going to use. Either you specify (fx, fy) or out_img.size(), OpenCV calculates the other automatically. Let’s see how to use this function

Nearest Neighbour: Use cv2.INTER_NEAREST as the interpolation flag as shown below