python-opencv(2)图像运算
#%%图像的加法
import cv2
import numpy as np
img1 = cv2.imread(r"C:\Users\lihuanyu\Desktop\opencv\image\lena512.bmp")
img2 = img1
results1 = img1+img2
results2 = cv2.add(img1,img1)
cv2.imshow("results1",results1)
cv2.imshow("results2",results2)
cv2.waitKey(0)
cv2.destroyAllWindows()
将2张或2张以上的图像信息的融合到1张图像上,融合的图像含有更多的信息、能够更方便人来观察或者计算机处理。
函数为addWeighted
dst=cv.addWeighted(src1, alpha, src2, beta, gamma)
dst = src1*alpha + src2*beta + gamma;
其中参数gamma
不能省
#%%图像融合
import cv2
lena = cv2.imread(r"C:\Users\lihuanyu\Desktop\opencv\image\add\lena.bmp")
boat = cv2.imread(r"C:\Users\lihuanyu\Desktop\opencv\image\add\boat.bmp")
result=cv2.addWeighted(lena,1,boat,1,0)
cv2.imshow("lena",lena)
cv2.imshow("boat",boat)
cv2.imshow("result",result)
cv2.waitKey(0)
cv2.destroyAllWindows()
Python+OpenCV计算机视觉 - 李立宗