Image fusion of OpenCV study notes

1. Linear fusion operation

 Linear blending operation  is also a typical binary (two input)  pixel operation  :

g(x) = (1 - \alpha)f_{0}(x) + \alpha f_{1}(x)

Range by  0 \rightarrow 1 changing the inside  \alpha , this operation can be used to generate two images on two or video time  picture of the stack  (cross-dissolve) effect, as in the slide show and film production as in

2. Operational Practice

#include <QCoreApplication>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <QDebug>
#include <QDir>
#include <QFile>
#include "iostream"

using namespace std;
using namespace cv;

int main()
{
    double alpha = 0.5; double beta;
    Mat src1, src2, dst;
    //! 读取图片
    src1 = imread("C:/2.png");
    src2 = imread("C:/3.png");

    if( !src1.data ) { qDebug("Error loading src1 \n"); return -1; }
    if( !src2.data ) { qDebug("Error loading src2 \n"); return -1; }

    //! 调整两幅图片保持一致,否则会出错
    resize(src2, src2, Size(src1.cols, src1.rows));

    beta = ( 1.0 - alpha );
    addWeighted( src1, alpha, src2, beta, 0.0, dst);

    imshow( "Linear Blend", dst );
    waitKey(0);
    return 0;
}

  

src1 src2 dst

Reference materials:

Appendix 1: addWeighted() function realizes linear blending of images

void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype=-1);  
第一个参数,InputArray类型的src1,表示需要加权的第一个数组,常常填一个Mat。
第二个参数,alpha,表示第一个数组的权重
第三个参数,src2,表示第二个数组,它需要和第一个数组拥有相同的尺寸和通道数。
第四个参数,beta,表示第二个数组的权重值。
第五个参数,dst,输出的数组,它和输入的两个数组拥有相同的尺寸和通道数。
第六个参数,gamma,一个加到权重总和上的标量值。看下面的式子自然会理解。
第七个参数,dtype,输出阵列的可选深度,有默认值-1。;当两个输入数组具有相同的深度时,这个参数设置为-1(默认值),即等同于src1.depth()。

 

Guess you like

Origin blog.csdn.net/a8039974/article/details/104862121