Python-OpenCV 图像叠加or图像混合加权(cv2.addWeighted)
2017-09-15 15:49
567 查看
Python-OpenCV 图像叠加or图像混合加权实现
函数说明
参数说明
代码示范
图示
alpha – weight of the first array elements.
src2 – second input array of the
beta – weight of the second array elements.
dst – output array that has the
gamma – scalar added to each sum.
dtype – optional depth of the output array; when both input arrays have the same depth,
此函数可以用一下矩阵表达式来代替:
dst = src1 * alpha + src2 * beta + gamma;
注意:由参数说明可以看出,被叠加的两幅图像必须是尺寸相同、类型相同的;并且,当输出图像array的深度为CV_32S时,这个函数就不适用了,这时候就会内存溢出或者算出的结果压根不对。
CV_32S is a signed 32bit integer value for each pixel
原图2:
叠加后结果:
(1)图1的权重为0.7,图二的权重为0.3, gamma为0 的结果:
(2)图1的权重为0.7,图二的权重为0.3, gamma为100 的结果:
(3)图1的权重为0.3,图二的权重为0.7, gamma为0 的结果:
函数说明
参数说明
代码示范
图示
Python-OpenCV 图像叠加or图像混合加权实现
函数说明
cv2.addWeighted(src1, alpha, src2, beta, gamma[, dst[, dtype]]) → dst
参数说明
src1 – first input array.alpha – weight of the first array elements.
src2 – second input array of the
same size and channelnumber as
src1.
beta – weight of the second array elements.
dst – output array that has the
same size and number of channelsas the input arrays.
gamma – scalar added to each sum.
dtype – optional depth of the output array; when both input arrays have the same depth,
dtypecan be set to
-1, which will be equivalent to
src1.depth().
此函数可以用一下矩阵表达式来代替:
dst = src1 * alpha + src2 * beta + gamma;
注意:由参数说明可以看出,被叠加的两幅图像必须是尺寸相同、类型相同的;并且,当输出图像array的深度为CV_32S时,这个函数就不适用了,这时候就会内存溢出或者算出的结果压根不对。
CV_32S is a signed 32bit integer value for each pixel
代码示范
def addImage(img1_path, img2_path): img1 = cv2.imread(img1_path) img = cv2.imread(img2_path) h, w, _ = img1.shape # 函数要求两张图必须是同一个size img2 = cv2.resize(img, (w,h), interpolation=cv2.INTER_AREA) #print img1.shape, img2.shape #alpha,beta,gamma可调 alpha = 0.7 beta = 1-alpha gamma = 0 img_add = cv2.addWeighted(img1, alpha, img2, beta, gamma) cv2.namedWindow('addImage') cv2.imshow('img_add',img_add) cv2.waitKey() cv2.destroyAllWindows()
图示
原图1:原图2:
叠加后结果:
(1)图1的权重为0.7,图二的权重为0.3, gamma为0 的结果:
(2)图1的权重为0.7,图二的权重为0.3, gamma为100 的结果:
(3)图1的权重为0.3,图二的权重为0.7, gamma为0 的结果:
相关文章推荐
- 【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- 【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- opencv 图像叠加ROI & 图像混合
- 【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- 【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- 【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- 【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- 【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- 【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- Opencv ---- ROI区域图像叠加 & 初级图像混合
- 【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- opencv学习(八)之ROI区域和图像混合叠加
- [转]【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- OpenCV 学习记录4 ROI区域图像叠加及线性图像混合
- 【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- 【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- OpenCV入门,线性混合 使用addWeight函数将两幅图像叠加
- 【OpenCV入门教程之四】 ROI区域图像叠加&初级图像混合 全剖析
- 【OpenCV学习笔记】2.1图像混合和叠加
- opencv学习笔记-图像叠加、混合