具体的算法原理可以参考

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

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

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

void Darken(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);

//Linear_Burn(Image_up, Image_down, Image_mix);

    //Linear_Dodge(Image_up, Image_down, Image_mix);

    //Lighten(Image_up, Image_down, Image_mix);

    //Darken(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;

}

// linear Burn

void Linear_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]=max(

                         src1.at<Vec3f>(index_row, index_col)[index_c]+

                         src2.at<Vec3f>(index_row, index_col)[index_c]-1, (float)0.0);

        }

    }

}



// linear dodge

void Linear_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]=min(

                         src1.at<Vec3f>(index_row, index_col)[index_c]+

                         src2.at<Vec3f>(index_row, index_col)[index_c], (float)1.0);

        }

    }

}



// Lighten

void Lighten(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]=max(

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

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

        }

    }

}



// Darken

void Darken(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]=min(

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

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

        }

    }

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_ALGO ...

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Erlang的常驻模块与功能模块

    Erlang的常驻模块与功能模块Residence moduleThe module where a process has its tail-recursive loop function(s).I ...

  2. Protobuf-net判断字段是否有值

    Protobuf-net判断字段是否有值Unity3d使用Protobuf-net序列化数据与服务器通信,但是发现默认情况下,Protobuf-net生成的cs文件中没有接口判断可选参数是否有值.需有 ...

  3. GC垃圾回收算法

    什么是GC垃圾回收呢.日常生活中我们去餐厅吃饭吃完饭,吃完饭走了餐具不用管,服务员在把餐具拿走,这是一种方式,服务员怎么知道他要来把餐具拿走呢,因为你走了,这个位置空了.服务员什么时候拿走餐具很重要, ...

  4. 详解EBS接口开发之库存事务处理采购接收--补充

    除了可以用  详解EBS接口开发之库存事务处理采购接收的方法还可以用一下方法,不同之处在于带有批次和序列控制的时候实现方式不同 The script will load records into ...

  5. HttpClient4.5.2调用示例(转载+原创)

    操作HttpClient时的一个工具类,使用是HttpClient4.5.2 package com.xxxx.charactercheck.utils; import java.io.File; i ...

  6. jquery实战---标签页效果

    在前面的博客中,小编主要简单的介绍了jquery的一些基本知识,今天这篇博文,小编继续来学习jquery的相关知识,今天我们来学习一个标签页的小例子,相关源码小编已经上传,有需要的小伙伴可以自己去下载 ...

  7. AngularJS进阶(四十)创建模块、服务

    AngularJS进阶(四十)创建模块.服务 学习要点 使用模块构架应用 创建和使用服务 为什么要使用和创建服务与模块? 服务允许你打包可重用的功能,使之能在此应用中使用. 模块允许你打包可重用的功能 ...

  8. Android 中与 so 有关的一个大坑

    Android 应用开发中不可避免的会引入第三方的代码.如果是开源项目风险相对可控,如果引入商用的 SDK 那就要谨慎了,难免会有这样或那样的问题.比如我们今天要说的这一个. 对集成过第三方 SDK ...

  9. FilterDispatcher is depredated!plesae use the new filters

    一些struts2的教程都是比较早的,当我们基于较新版本的struts2来实现代码的时候,往往会出现一些问题.比如这个警告:FilterDispatcher isdeprecated! 在web.xm ...

  10. (NO.00003)iOS游戏简单的机器人投射游戏成形记(三)

    接下来我们建立机器人对象. 在Sprites文件夹中新建Robot.ccb文件,类型为Node. 打开SpriteBuilder的Tileless View将机器人身体和手臂拖入根节点,调整好相对的位 ...