具体的算法原理可以参考

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. iOS开发之Xcode8推出的WKWebView与UIWebView的使用

    一.整体介绍 UIWebView自iOS2就有,WKWebView从iOS8才有,毫无疑问WKWebView将逐步取代笨重的UIWebView.通过简单的测试即可发现UIWebView占用过多内存,且 ...

  2. ThreadLocal的使用[代码片段]

    1.ThreadLocal定义,在一个类中定义: 在类A中: private static ThreadLocal<String> kcsHtmlPath = new ThreadLoca ...

  3. 7.0、Android Studio命令行工具

    命令行工具分成SDK工具和平台工具. SDK工具 SDK工具跟随SDK安装包安装并随时更新. Virtual Device 工具 1. Android Virtual Device Manager 提 ...

  4. 排列熵算法简介及c#实现

    一.   排列熵算法简介: 排列熵算法(Permutation Entroy)为度量时间序列复杂性的一种方法,算法描述如下: 设一维时间序列: 采用相空间重构延迟坐标法对X中任一元素x(i)进行相空间 ...

  5. android PakageManagerService启动流程分析

    PakageManagerService的启动流程图 1.PakageManagerService概述 PakageManagerService是android系统中一个核心的服务,它负责系统中Pac ...

  6. Aandroid TV 基于Leanback支持最新MD设计的TV开发框架

    原文地址:http://blog.csdn.net/sk719887916 作者:skay 基于6.0最新的API 支持TV的框架 Android 6.0已完美支持TV开发,之前的5.0后Recycl ...

  7. 如何让 jQuery Mobile 不显示讨厌的 loading 界面

    jQuery Mobile 的一个BUG: 当不采用 ajax 以及 他自己的 back 返回的时候,即: 点击浏览器后退按钮时,将会从缓存之中加载页面,此时,讨厌的 loading 动画出来了,而且 ...

  8. x264 编码器选项分析 (x264 Codec Strong and Weak Points) 2

    文章目录: x264 编码器选项分析 (x264 Codec Strong and Weak Points) 1 x264 编码器选项分析 (x264 Codec Strong and Weak Po ...

  9. pig中查询top k,返回每个hour和ad_network_id下最大两个记录(SUBSTRING,order,COUNT_STAR,limit)

    pig里面是有TOP函数,不知道为什么用不了.有时间要去看看pig源码了. SET job.name 'top_k'; SET job.priority HIGH; --REGISTER piggyb ...

  10. c# 单元测试工程如何取得当前项目路径

    前言: C#工程项目中有些配置文件,数据文件等不是C#工程文件,但是程序中需要访问,如果写成绝对路径不利于程序的迁移,所以必须写成相对路径.取得相对路径的方法很多,网上的例子也很多,基本上是七种吧,这 ...