具体的算法原理可以参考

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

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

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

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

//Screen(Image_up, Image_down, Image_mix);

    //Add_Color(Image_up, Image_down, Image_mix);

    //Soft_Lighten(Image_up, Image_down, Image_mix);

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

}

// Screen

void Screen(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])*

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

        }

    }

}



// Add color

void Add_Color(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];

                if(b>0.5)

                {

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

                }

                else

                {

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

                }

            }

        }

    }

}



// Soft Lighten

void Soft_Lighten(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];

                if(a<=0.5)

                {

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

                }

                else

                {

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

                }

            }

        }

    }

}

// Strong Lighten

void Strong_Lighten(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];

                if(a<=0.5)

                {

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

                }

                else

                {

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

                }

            }

        }

    }

}

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图层混合算法之六(差值,溶解, 排除)

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

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

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

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

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

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

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

随机推荐

  1. Android监听屏幕解锁和判断屏幕状态

    开发后台服务的时候经常需要对屏幕状态进行判断,如果是想要监听屏幕解锁事件,可以在配置里面注册action为 android.intent.action.USER_PRESENT的广播,则可以监听解锁事 ...

  2. Latex居中

    居中文本 环境:\begin{center} 第一行\\第二行\\...第n行 \end{center}.可以用\\[长度]来插入可以省略的额外行间距.在一个环境内部,可以用命令\centering来 ...

  3. UE4联机多人游戏基本设置

    UE4自带网络联机功能,但是似乎只有蓝图接口,而真正写功能的时候不能用C++,让人感觉相当诡异 还是作一个简单记录 1.建一个第三人称模板,为什么会用他呢,因为它自带模板的很多组件,直接支持联机功能, ...

  4. GDAL不支持创建PCIDSK的面状矢量格式

    最近在使用GDAL创建PCIDSK格式的矢量数据,发现创建点和线的矢量数据都没问题,创建面状的只有属性表没有图形.在GDAL官网说明也写的是支持的,地址为:http://www.gdal.org/fr ...

  5. python在windows下使用setuptools安装egg文件

    最近和同学做个东西,需要安装python的第三方函数库,看了网上的介绍,很是麻烦,这是我实践总结出来的,希望对大家有用. 以安装第三方库networkx 为例,其余函数库都是一个套路,看完就会滴. 1 ...

  6. 安卓服务Service详解

    service(服务)是安卓中的四大组件之一,它通常用作在后台处理耗时的逻辑,与Activity一样,它存在自己的生命周期,也需要在清单文件中配置相关信息,本博客将对Service的各个知识点进行详细 ...

  7. dbms_lob使用之-基础

     在Oracle中,存储在LOB中数据称为LOB的值,如使用Select   对某一LOB字段进行选择,则返回的不是LOB的值,而是该LOB字段的定位器(可以理解为指向LOB值的指针).如执行如下 ...

  8. ROS(indigo)使用Qt Creator Plug in即ros_qtc_plugin

    更为详细版本请参考: http://blog.csdn.net/zhangrelay/article/details/52214411 结合看更为具体. 首先,先上原版参考: 1 http://wik ...

  9. 如何在Cocos2D游戏中实现A*寻路算法(五)

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 免责申明:本博客提供的所有翻译文章原稿均来自互联网,仅供学习交流 ...

  10. java同步synchronized

    java同步synchronized volatile仅仅用来保证该变量对所有线程的可见性,但不保证原子性. 看下面的这段代码: /** * * @author InJavaWeTrust * */ ...