具体的算法原理可以参考:

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 Difference(Mat& src1, Mat& src2, Mat& dst);

void Exclusion(Mat& src1, Mat& src2, Mat& dst);

void Dissolve(Mat& src1, Mat& src2, Mat& dst, double alpha);

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);

//Difference(Image_up, Image_down, Image_mix);

    //Exclusion(Image_up, Image_down, Image_mix);

    //Dissolve(Image_up, Image_down, Image_mix, 0.75);

namedWindow("Img", CV_WINDOW_AUTOSIZE);

    imshow("Img",Image_mix);

    waitKey();

    cvDestroyWindow("Img");

    cout<<"All is well."<<endl;

    return 0;

}

// Difference

void Difference(Mat& src1, Mat& src2, Mat& dst)

{

    float a=0;

    float b=0;

     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++)

            {

                a=src1.at<Vec3f>(index_row, index_col)[index_c];

                b=src2.at<Vec3f>(index_row, index_col)[index_c];

                dst.at<Vec3f>(index_row, index_col)[index_c]=abs(a-b);

            }

        }

    }

}



// Exclusion

void Exclusion(Mat& src1, Mat& src2, Mat& dst)

{

    float a=0;

    float b=0;

     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++)

            {

                a=src1.at<Vec3f>(index_row, index_col)[index_c];

                b=src2.at<Vec3f>(index_row, index_col)[index_c];

                dst.at<Vec3f>(index_row, index_col)[index_c]=a+b-2*a*b;

            }

        }

    }

}



// Dissolve

void Dissolve(Mat& src1, Mat& src2, Mat& dst, double alpha)

{

    dst=src1;

    Mat Rand_mat(src1.size(), CV_32FC1);

    cv::randu(Rand_mat, 0,1);

    float a=0;

    float b=0;

     for(int index_row=0; index_row<src1.rows; index_row++)

    {

        for(int index_col=0; index_col<src1.cols; index_col++)

        {

            b=Rand_mat.at<float>(index_row, index_col);

            if(b<alpha)

            {

                for(int index_c=0; index_c<3; index_c++)

               {

                   a=src2.at<Vec3f>(index_row, index_col)[index_c];

                   dst.at<Vec3f>(index_row, index_col)[index_c]=a;

               }

            }

        }

    }

}

OpenCV——PS图层混合算法(六)的更多相关文章

  1. OpenCV——PS 图层混合算法(一)

    详细的算法原理能够參考 PS图层混合算法之中的一个(不透明度,正片叠底,颜色加深,颜色减淡) // PS_Algorithm.h #ifndef PS_ALGORITHM_H_INCLUDED #de ...

  2. OpenCV——PS 图层混合算法 (三)

    具体的算法原理可以参考 PS图层混合算法之三(滤色, 叠加, 柔光, 强光) // PS_Algorithm.h #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ ...

  3. OpenCV——PS 图层混合算法 (二)

    具体的算法原理可以参考 PS图层混合算法之二(线性加深,线性减淡,变亮,变暗) // PS_Algorithm.h #ifndef PS_ALGORITHM_H_INCLUDED #define PS ...

  4. OpenCV——PS 图层混合算法 (四)

    具体的算法原理可以参考 PS图层混合算法之四(亮光, 点光, 线性光, 实色混合) // PS_Algorithm.h #ifndef PS_ALGORITHM_H_INCLUDED #define ...

  5. Python: PS 图层混合算法汇总

    本文用 Python 实现了PS 中的图层混合算法,把很多常见的图层混合算法都汇总到了一起,比起以前写的算法,就是用矩阵运算代替了很耗时的for 循环,运行效率有所提升.具体的代码如下: import ...

  6. PS图层混合算法之六(差值,溶解, 排除)

    差值模式: 查看每个通道中的颜色信息,比较底色和绘图色,用较亮的像素点的像素值减去较暗的像素点的像素值.与白色混合将使底色反相:与黑色混合则不产生变化. 排除模式可生成和差值模式相似的效果,但比差值模 ...

  7. PS图层混合算法之三(滤色, 叠加, 柔光, 强光)

    滤色模式: 作用结果和正片叠底刚好相反,它是将两个颜色的互补色的像素值相乘,然后除以255得到的最终色的像素值.通常执行滤色模式后的颜色都较浅.任何颜色和黑色执行滤色,原色不受影响;任何颜色和白色执行 ...

  8. PS图层混合算法之二(线性加深,线性减淡,变亮,变暗)

    线性加深模式: 查看每个通道的颜色信息,通过降低"亮度"使底色的颜色变暗来反映绘图色,和白色混合没变化. Linear Burn 线形加深 C=A+B-1 如果上下层的像素值之和小 ...

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

    下列公式中,A代表了上面图层像素的色彩值(A=像素值/255),B代表下面图层像素的色彩值(B=像素值/255),C代表了混合像素的色彩值(真实的结果像素值应该为255*C).该公式也应用于层蒙板. ...

随机推荐

  1. 集合框架之Collection接口

    Collection 层次结构中的根接口.Collection表示一组对象,这些对象也称为 collection 的元素.一些 collection 允许有重复的元素,而另一些则不允许.一些 coll ...

  2. 安卓自定义View实现钟表

    转载请注明出处:http://blog.csdn.net/baiyuliang2013/article/details/45535227 之前实现过html5版的钟表,html5也有一个画板属性Can ...

  3. UNIX网络编程——利用recv和readn函数实现readline函数

    在前面的文章中,我们为了避免粘包问题,实现了一个readn函数读取固定字节的数据.如果应用层协议的各字段长度固定,用readn来读是非常方便的.例如设计一种客户端上传文件的协议,规定前12字节表示文件 ...

  4. How to Find the Self Service Related File Location and Versions

     How to Find the Self Service Related File Location and Versions (文档 ID 781385.1) In this Document ...

  5. JQuery实战--可以编辑的表格

    廊坊下雪了,15年的第二场雪,比14的来的稍晚一些,停靠在11教门前的自行车,成了廊坊师范学院最美丽的风景线.还记得以前学习css的时候,就曾经接触过如何编写设计一些表格和表单的样式,例如如何设计表格 ...

  6. Linux_Oracle命令大全

     一,启动 1.#su - oracle              切换到oracle用户且切换到它的环境 2.$lsnrctl status           查看监听及数据库状态 3.$ls ...

  7. Android的DataBinding原理介绍

    Activity在inflate layout时,通过DataBindingUtil来生成绑定,从代码看,是遍历contentView得到View数组对象,然后通过数据绑定library生成对应的Bi ...

  8. UNIX环境高级编程——管道读写规则和pipe Capacity、PIPE_BUF

    一.当没有数据可读时O_NONBLOCK disable:read调用阻塞,即进程暂停执行,一直等到有数据来到为止. O_NONBLOCK enable:read调用返回-1,errno值为EAGAI ...

  9. 我眼中的Linux设备树(五 根节点)

    五 根节点一个最简单的设备树必须包含根节点,cpus节点,memory节点.根节点的名字及全路径都是"/",至少需要包含model和compatible两个属性.model属性我们 ...

  10. 多层界面之间显示与隐藏tabBar

    IOS中多层界面之间显示与隐藏tabBar? 在做项目的时候,遇到了一个难题,使用hidesBottomWhenPushed=YES属性设置,可以让本级界面及其以后界面都隐藏,但是根据项目 需求,在第 ...