image processing图像处理
文章目录
1 image transfomations图像变换
1.1 translation平移
# 格式为[1,0,tx]和[0,1,ty],其中tx和ty分别为横向和纵向,正数表示向下和向右
# 负数表示向上和向左
M = np.float32([[1, 0, 25], [0, 1, 50]])
shifted = cv2.warpAffine(image, M, (image.shape[1], image.shape
[0]))
cv2.imshow("Shifted Down and Right", shifted)
封装成一个函数的写法
# 子函数的写法
import numpy as np
import cv2
def translate(image, x, y):
# 定义平移矩阵
M = np.float32([[1, 0, x], [0, 1, y]])
# 使用warpAffine方法进行变换
shifted = cv2.warpAffine(image, M, (image.shape[1], image.
shape[0]))
return shifted
# 直接调用函数
shifted = imutils.translate(image, 0, 100)
cv2.imshow("Shifted Down", shifted)
cv2.waitKey(0)
1.2 rotation旋转
(height, width) = image.shape[:2]
center = (width//2, height//