python resize 双线性插值

# -*- coding: utf-8 -

 

#import datetime
#t1 = datetime.datetime(2017,10,10,21,40)
#t2 = datetime.datetime(2017,10,8,23,40)
#tt1 = datetime.timedelta(seconds = 1200)
#tt2 = datetime.timedelta(weeks = 3)
#print(t1 - t2)

import cv2
import numpy as np
from math import ceil

img = cv2.imread("data/00001.jpg", 0)

re_cv = cv2.resize(img, (30, 20))

def resize_self(img, new_shape):
    im = img.astype(float)
    m, n = im.shape
    nw = new_shape[0]
    nh = new_shape[1]
    new_im = np.zeros((nw, nh))
    for x in range(0, nw):
        for y in range(0, nh):
            
            srcx = (x+0.5)*(m/nw)-0.5
            srcy = (y+0.5)*(n/nh)-0.5
            
            if srcx<0: srcx = 0
            if srcy<0: srcy = 0
         

你可能感兴趣的:(python,图像处理)