Python的图像缩放(resize)方法
双线性差值方法的详细过程,
推荐博客:三十分钟理解:线性插值,双线性插值Bilinear Interpolation算法。
接下来,展示的是基于Python、cv2和skimage实现双线性差值的图像缩放。
#! python
#
import os
import sys
import time
# Matplotlib.
import matplotlib.pyplot as plt
# PIL.
from PIL import Image
# Numpy.
import numpy as np
# OpenCV.
import cv2
# Skimage.
import skimage
from skimage import transform
# TODO: Resize.
dst_width, dst_height = 192, 108
# py_Resize.
def py_Resize(src, shape):
# Shape.
height, width, channels = src.shape
dst_width, dst_height = shape
if ((dst_height == height) and (dst_width == width)):
return src
# Object.
dst_Image = np.zeros((dst_height, dst_width, channels), np.uint8)
# Resize.
# Scale for resize.
scale_x = float(width)/dst_width