详细的算法原理能够參考

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

        }

    }

}

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

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

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

  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. UVA 11045-My T-shirt suits me(二分图匹配)

    题意:有N件T恤,N是6的倍数,因为有6种型号,每种件数相同,有M个人,每个人有两种型号的T恤适合他,每个人可以挑其中的一种,问能否所有的人都能分配到T恤. 解析:典型的二分图匹配,每N/6为同种T恤 ...

  2. poj1001(高精度)

                                                               Exponentiation Time Limit: 500MS   Memory ...

  3. PHP 表单验证 - 必填字段

    -------------------------------------------------------------------------- 本节展示如何制作必填输入字段,并创建需要时所用的错 ...

  4. JavaScript 运行机制详解:深入理解Event Loop

    Philip Roberts的演讲<Help, I'm stuck in an event-loop>,详细.完整.正确地描述JavaScript引擎的内部运行机制. 一.为什么JavaS ...

  5. 【设计模式:单例模式】使用单例模式载入properties文件

    先准备測试程序: package org.jediael.util; import static org.junit.Assert.*; import org.junit.Test; public c ...

  6. Linux SSH 远程操作与传送文件

    操作系统:centos 6.5 x64 一.远程连接:在进行linux 的 ssh远程操作前,一定要确认linux 是否安装了 openssh-clients,为了方便起见,一般用yum安装即可:# ...

  7. 第五章 Logistic回归

    第五章 Logistic回归 假设现在有一些数据点,我们利用一条直线对这些点进行拟合(该线称为最佳拟合直线),这个拟合过程就称作回归. 为了实现Logistic回归分类器,我们可以在每个特征上都乘以一 ...

  8. .net 链接oracle

    虽然EF6都快要出来了,但是对于Oracle数据库,仍然只能用DB first和Model First来编程,不能用Code First真是一个很大的遗憾啊. 好了,废话少说,我们来看看EF中是如何用 ...

  9. Entity Framework with MySQL

    Get Entity Framework: http://msdn.microsoft.com/en-us/data/ee712906 Entity Framework 6 Tools for Vis ...

  10. ios 文字图标

    如何使用自定义字体 在讲icon font之前,首先先来看看普通自定义字体是如何在ios中使用的,两个原理是一样的.这里以KaushanScript-Regular为例: Step 1: 导入字体文件 ...