OpenCV——PS 图层混合算法 (三)
具体的算法原理可以参考
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 图层混合算法 (三)的更多相关文章
- OpenCV——PS 图层混合算法(一)
详细的算法原理能够參考 PS图层混合算法之中的一个(不透明度,正片叠底,颜色加深,颜色减淡) // PS_Algorithm.h #ifndef PS_ALGORITHM_H_INCLUDED #de ...
- OpenCV——PS 图层混合算法 (二)
具体的算法原理可以参考 PS图层混合算法之二(线性加深,线性减淡,变亮,变暗) // PS_Algorithm.h #ifndef PS_ALGORITHM_H_INCLUDED #define PS ...
- OpenCV——PS图层混合算法(六)
具体的算法原理可以参考: PS图层混合算法之六(差值,溶解, 排除) // PS_Algorithm.h #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGO ...
- OpenCV——PS 图层混合算法 (四)
具体的算法原理可以参考 PS图层混合算法之四(亮光, 点光, 线性光, 实色混合) // PS_Algorithm.h #ifndef PS_ALGORITHM_H_INCLUDED #define ...
- Python: PS 图层混合算法汇总
本文用 Python 实现了PS 中的图层混合算法,把很多常见的图层混合算法都汇总到了一起,比起以前写的算法,就是用矩阵运算代替了很耗时的for 循环,运行效率有所提升.具体的代码如下: import ...
- PS图层混合算法之六(差值,溶解, 排除)
差值模式: 查看每个通道中的颜色信息,比较底色和绘图色,用较亮的像素点的像素值减去较暗的像素点的像素值.与白色混合将使底色反相:与黑色混合则不产生变化. 排除模式可生成和差值模式相似的效果,但比差值模 ...
- PS图层混合算法之三(滤色, 叠加, 柔光, 强光)
滤色模式: 作用结果和正片叠底刚好相反,它是将两个颜色的互补色的像素值相乘,然后除以255得到的最终色的像素值.通常执行滤色模式后的颜色都较浅.任何颜色和黑色执行滤色,原色不受影响;任何颜色和白色执行 ...
- PS图层混合算法之二(线性加深,线性减淡,变亮,变暗)
线性加深模式: 查看每个通道的颜色信息,通过降低"亮度"使底色的颜色变暗来反映绘图色,和白色混合没变化. Linear Burn 线形加深 C=A+B-1 如果上下层的像素值之和小 ...
- PS图层混合算法之一(不透明度,正片叠底,颜色加深,颜色减淡)
下列公式中,A代表了上面图层像素的色彩值(A=像素值/255),B代表下面图层像素的色彩值(B=像素值/255),C代表了混合像素的色彩值(真实的结果像素值应该为255*C).该公式也应用于层蒙板. ...
随机推荐
- zookeeper分布式部署方案
版本:http://apache.fayea.com/zookeeper/zookeeper-3.4.8/环境:debian 7/8说明:最低配置3台步骤:1.下载zookeeper-3.4.8并解压 ...
- ORACLE数据库学习之数据库的优化
数据库的优化 概述 影响数据库性能的因素包括:系统.数据库.网络. 数据库的优化包括:优化数据库磁盘I/O.优化回滚段.优化Rrdo日志.优化系统全局区.优化数据库对象. 监控数据库的性能: 在 ...
- FORM中读取图片
1.创建ITEM 重要属性如下 item属性:图像 大小样式:调整 数据库项:否 2.读取触发器 在block级别,创建trigger READ_IMAGE_FILE('D:\'||:XX_EMOLY ...
- 【Android 系统开发】使用 Source InSight 阅读 Android 源码
1. 安装 Source Insight (1) Source Insight 相关资源 安装相关资源 : -- 下载地址 : http://www.sourceinsight.com/down35. ...
- 1081. Rational Sum (20) -最大公约数
题目如下: Given N rational numbers in the form "numerator/denominator", you are supposed to ca ...
- UNIX网络编程——名字与地址转换(gethostbyname,gethostbyaddr,getservbyname,getservbyport,getaddrinfo,getnameinfo函数)
名字和数值地址间进行转换的函数:gethostbyname和gethostbyaddr在主机名字与IPv4地址之间进行转换.getservbyname和getservbyport在服务器名字和端口号之 ...
- 【OpenGL】理解一些基本问题
写在前面 啦啦啦,搞了很久的Unity Shaders,越学越觉得基础知识很重要.学Unity Shader的时候,总会想,shader到底是什么呢?shader的pipeline是什么呢?它们是怎么 ...
- Android Studio科普篇——2.误区
1.删除一行是ctrl+x? 这是一个被谣传得很广泛的快捷键,但其实删除一行的快捷键不是ctrl+x,而是ctrl+y.ctrl+x在不选中内容的情况下,是剪切当前行,而ctrl+y才是删除当前行,它 ...
- (九十四)集成PKRevealController实现左右抽屉视图
使用PKRevealController可以实现类似于QQ等软件的左右抽屉视图,拖出的视图分为leftView和rightView,分别取自View的左半部分和右半部分,因此,根据不同的需求,可以选择 ...
- JSP标签JSTL(2)--流程控制
对于流程控制,单纯的用jsp脚本,显得很是繁琐,尤其是遇到if判断的时候,写代码的时候就需要特别的小心,因为极有可能会出现符号不匹配的状况.但是利用标签语言就会大大的改善这一状况. 流程控制 if标签 ...