import cv2
import numpy as np
img = cv2.imread('car.jpg', 1)
imgInfo = img.shape
print(imgInfo)
height = imgInfo[0]
width = imgInfo[1]
mode = imgInfo[2]
dstHeight = int(height*0.5)
dstWidth = int(width*0.5)
#缩放方法:双线性差值、最近邻域差值,像素关系重采样,立方差值。默认为双线性差值
######方法一
#dst = cv2.resize(img, (dstWidth, dstHeight))
#cv2.imshow('image', dst)
#######方法二
dstImage = np.zeros((dstHeight, dstWidth,3), np.uint8)#0-255
for i in range(0, dstHeight): #行
for j in range(0, dstWidth): #列
iNew = int(i * (height * 1.0/dstHeight))
jNew = int(j *(width*1.0/dstWidth))
dstImage[i,j] = img[iNew, jNew]
cv2.imshow('dst',dstImage)
cv2.waitKey(0)
cv2.waitKey(0)
"""
最近邻域差值原理:
目标图像上的点都是来自原图像,
关系是:Xnew = x * (原图像的行/目标图像的行)
Ynew = y * (原图像的列/目标图像的列)
双线性差值:
A1 = 20% * 上 + 80% * 下
B1 = 30% * 左 + 70% * 右
1 终点 = A1 * 30% + A2 * 70%
2 终点 = B1 * 20% + B2 * 80%
"""