图像处理之图像混合

c++图像处理之图像混合
1、图像混合原理

图像混合的原理如下:
以两张图像为例;
a a a 为权值参数, f 0 ( x ) f_0(x) f0(x)表示第一张图像, f 1 ( x ) f_1(x) f1(x)表示第二张图像。
g ( x ) g(x) g(x)表示权重融合后两张图像的形式。
原理
示例图:
img1
img2

结果图:
结果图

2、代码实现

图像混合:addWeight(src1, alpha, src2, alpha, beta, dst)

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** args)
{
	Mat img1 = imread("G:/testpic/img1.png");
	Mat img2 = imread("G:/testpic/img2.png");
	Mat dst;

	if(!img1.data)
	{
		printf("the image cannot load");
		return -1;
	}
	if(!img2.data)
	{
		printf("the image cannot load");
		return -1;
	}
	if(img1.rows == img2.rows && img1.cols == img2.cols && img1.type() == img2.type())
	{
		double alpha = 0.5;
		addWeight(img1, alpha, img2, 1.0-alpha, 0.0, dst);
		imshow("img1", img1);
		imshow("img2", img2);
		namedWindow("output", WINDOW_AUTOSIZE);
		imshow("output", dst);
		imwrite("G:/testpic/result/imgresult.png", dst);
	}
	else
	{
		printf("these images not the sanme");
		return -1;
	}
	waitKey(0);
	return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值