OpenCV入门:(四:混合两张图片)

本文深入探讨了图像融合的概念,介绍了使用OpenCV中的AddWeight函数实现图像混合的方法,并通过实例展示了不同alpha值下的处理结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 原理

对两张图片使用如下公式可以得到两张图片的混合图片,

image

其中f0(x),f1(x)分别是图片1和图片2同一位置的像素点。

2. OpenCV中的AddWeight函数

函数和参数说明:
void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype=-1)
src1     – first input array.
alpha     – weight of the first array elements.
src2     – second input array of the same size and channel number as src1.
beta    – weight of the second array elements.
dst     – output array that has the same size and number of channels as the input arrays.
gamma     – scalar added to each sum.
dtype     – optional depth of the output array; when both input arrays have the same depth, dtype can be set to -1, which will be equivalent to src1.depth().

实现的转换公式为:

image

3. 实现代码

void Blend(const Mat& Src1,const Mat& Src2,double alpha,Mat& Dst)
{
    double beta = 1.0 - alpha;
    addWeighted(Src1,alpha,Src2,beta,0.0,Dst);
    namedWindow("原图1");
    imshow("原图1",Src1);
    waitKey(0);
    namedWindow("原图2");
    imshow("原图2",Src2);    
    waitKey(0);
    namedWindow("混合图");
    imshow("混合图",Dst);
    waitKey(0);
}

4. 结果

下图为设置alpha为0.5的处理结果:

image

5. 相关下载

图片下载

6. 结束

转载于:https://www.cnblogs.com/Reyzal/p/5015868.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值