SoFunction
Updated on 2024-11-21

Python-opencv Bilinear Interpolation Example

I'll cut to the chase and get right to the code!

#coding=utf-8
import cv2
import numpy as np
'''Bilinear interpolation'''
img = ('', cv2.CV_LOAD_IMAGE_GRAYSCALE) # load the gray image
('', img)
h, w = [:2]

# shrink to half of the original
a1 = ([[0.5, 0, 0], [0, 0.5, 0]], np.float32)
d1 = (img, a1, (w, h), borderValue=125)

# shrink to half of the original and move
a2 = ([[0.5, 0, w /4], [0, 0.5, h / 4]], np.float32)
d2 = (img, a2, (w, h),flags=cv2.INTER_NEAREST,borderValue=125)
# rotate based on d2
a3 = cv2.getRotationMatrix2D((w / 2, h / 2), 90, 1)
d3 = (d2, a3, (w, h),flags=cv2.INTER_LINEAR, borderValue=125)

('img',img)
('d1',d1)
('d2',d2)
('d3',d3)
(0)
()

This Python-opencv bilinear interpolation example above is all I have to share with you.