Image Interpolation using OpenCV | Python OpenCV bilinear interpolation
Inthepreviousblogs,wediscussedthealgorithmbehindthenearestneighbor [1]bilinear[2]andbicubic[3]interpolationmethodsusinga2×2image.Now,let’sdothesameusingOpenCVonarealimage.First,let’stakeanimage,eitheryoucan loadone[4] orcan makeownimage[5].Loadinganimagefromthedevicelookslikethisimportcv2importnumpyasnpimg=cv2.imread(C:/Newfolder/apple.jpg)importcv2importnumpyasnp img=cv2.imread(C:/Newfolder/apple.jpg)Thisisa20×22appleimagethatlookslikethis.Now,let’szoomit10timesusingeachinterpolationmethod....
In the previous blogs, we discussed the algorithm behind the
nearest neighbor [1] bilinear[2] and bicubic[3] interpolation methods using a 2×2 image.Now, let’s do the same using OpenCV on a real image. First, let’s take an image, either you can load one[4] or can make own image[5]. Loading an image from the device looks like this
import cv2 import numpy as np img = cv2.imread(C:/New folder/apple.jpg)
import cv2
import numpy as np
img = cv2.imread(C:/New folder/apple.jpg)
This is a 20×22 apple image that looks like this.
Now, let’s zoom it 10 times using each interpolation method. The OpenCV command for doing this is
dst = cv2.resize(src, dsize[, fx[, fy[, interpolation]]]])
dst = cv2.resize(src, dsize[, fx[, fy[, interpolation]]]])
where fx and fy are scale factors along x and y, dsize refers to the output image size and the interpolation flag refers to which method we are go...