zoukankan      html  css  js  c++  java
  • OpenCV——PS 图层混合算法(一)

    详细的算法原理能够參考

    PS图层混合算法之中的一个(不透明度,正片叠底,颜色加深,颜色减淡)


    // PS_Algorithm.h

    #ifndef PS_ALGORITHM_H_INCLUDED

    #define PS_ALGORITHM_H_INCLUDED

    #include <iostream>
    #include <string>
    #include "cv.h"
    #include "highgui.h"
    #include "cxmat.hpp"

    #include "cxcore.hpp"


    using namespace std;
    using namespace cv;

    #endif // PS_ALGORITHM_H_INCLUDED


    // main function

    #include "PS_Algorithm.h"

    void Transparent(Mat& src1, Mat& src2, Mat& dst, double alpha);
    void Multiply(Mat& src1, Mat& src2, Mat& dst);
    void Color_Burn(Mat& src1, Mat& src2, Mat& dst);
    void Color_Dodge(Mat& src1, Mat& src2, Mat& dst);

    int main(void)
    {
        Mat Origin_Image1;
        Mat Origin_Image2;
        Origin_Image1=imread("2.jpg");
        Origin_Image2=imread("3.jpg");
        Mat Image_up(Origin_Image1.size(),CV_32FC3);
        Mat Image_down(Origin_Image2.size(), CV_32FC3);
        Origin_Image1.convertTo(Image_up,CV_32FC3);
        Origin_Image2.convertTo(Image_down,CV_32FC3);
        Image_up=Image_up/255;
        Image_down=Image_down/255;
        Mat Image_mix(Image_up);

        //double alpha=0.25;
        //Transparent(Image_up, Image_down, Image_mix, alpha);
        //Multiply(Image_up, Image_down, Image_mix);
        //Color_Burn(Image_up, Image_down, Image_mix);
        //Color_Dodge(Image_up, Image_down, Image_mix);
       
        namedWindow("Img", CV_WINDOW_AUTOSIZE);
        imshow("Img",Image_mix);
        waitKey();
        cvDestroyWindow("Img");
        cout<<"All is well."<<endl;
        return 0;
    }


    // Transparent 不透明度
    void Transparent(Mat& src1, Mat& src2, Mat& dst, double alpha)
    {
        dst=alpha*src1+(1-alpha)*src2;
    }


    // Multiply 正片叠底
    void Multiply(Mat& src1, Mat& src2, Mat& dst)
    {
        for(int index_row=0; index_row<src1.rows; index_row++)
        {
            for(int index_col=0; index_col<src1.cols; index_col++)
            {
                for(int index_c=0; index_c<3; index_c++)
                    dst.at<Vec3f>(index_row, index_col)[index_c]=
                             src1.at<Vec3f>(index_row, index_col)[index_c]*
                             src2.at<Vec3f>(index_row, index_col)[index_c];
            }
        }
    }


    // Color_Burn 颜色加深
    void Color_Burn(Mat& src1, Mat& src2, Mat& dst)
    {
        for(int index_row=0; index_row<src1.rows; index_row++)
        {
            for(int index_col=0; index_col<src1.cols; index_col++)
            {
                for(int index_c=0; index_c<3; index_c++)
                    dst.at<Vec3f>(index_row, index_col)[index_c]=1-
                             (1-src1.at<Vec3f>(index_row, index_col)[index_c])/
                             src2.at<Vec3f>(index_row, index_col)[index_c];
            }
        }
    }

    // Color_Dodge 颜色减淡
    void Color_Dodge(Mat& src1, Mat& src2, Mat& dst)
    {
        for(int index_row=0; index_row<src1.rows; index_row++)
        {
            for(int index_col=0; index_col<src1.cols; index_col++)
            {
                for(int index_c=0; index_c<3; index_c++)
                    dst.at<Vec3f>(index_row, index_col)[index_c]=
                              src2.at<Vec3f>(index_row, index_col)[index_c]/
                             (1-src1.at<Vec3f>(index_row, index_col)[index_c]);
            }
        }
    }


  • 相关阅读:
    Tomcat + Mysql高并发配置优化
    Qt Widget 利用 Qt4.5 实现酷炫透明窗体
    使用VC2005编译真正的静态Qt4.4.3程序 good
    详解 Qt 线程间共享数据(使用signal/slot传递数据,线程间传递信号会立刻返回,但也可通过connect改变)
    浅析在QtWidget中自定义Model(beginInsertRows()和endInsertRows()是空架子,类似于一种信号,用来通知底层)
    英国著名芯片厂商与苹果谈崩 中资收购机会来了!
    跨站脚本攻击(XSS)
    Kafka 协议实现中的内存优化
    读取配置信息
    英语面试准备
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5224743.html
Copyright © 2011-2022 走看看