10月8日——图像处理

 图片的读取

import cv2
# 1 load 2 info 3 resize 4 check
img = cv2.imread('330.jpg',1)
imgInfo = img.shape
print(imgInfo)

height = imgInfo[0]
width = imgInfo[1]
mode = imgInfo[2]
# 等比例放大,非等比例放大

dstHeight = int(height*0.4)
dstWidth = int(width*0.4)
# resize方法有四种,
# 最近邻域插值, 双线性插值(默认) , 像素关系重采样,  立方插值 
dst = cv2.resize(img,(dstWidth,dstHeight))
cv2.imshow('image',dst)

cv2.waitKey(0)

 最近邻域插值的原理
 src(原图像)10*20  dst 5*10
 dst <- src
 (1,2)  <-  (2,4)
 逆向寻找 : newX = x*(src的行 / 目标的行) newX = 1*(10/5) = 2 
       newY 寻找的方法也是如此
 小数取整 12.3 = 12

双线性插值(默认)的原理

A1 = 0.2上 + 0.8下 ,A2,B1,B2同理

最终点 = A1 * 0.3 + A2 * 0.7

猜你喜欢

转载自blog.csdn.net/Pierce_KK/article/details/82966549