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 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 图层混合算法 (二)

时间: 2024-07-29 06:26:23

Opencv——PS 图层混合算法 (二)的相关文章

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

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"

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&qu

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

滤色模式: 作用结果和正片叠底刚好相反,它是将两个颜色的互补色的像素值相乘,然后除以255得到的最终色的像素值.通常执行滤色模式后的颜色都较浅.任何颜色和黑色执行滤色,原色不受影响;任何颜色和白色执行滤色得到的是白色:而与其他颜色执行滤色会产生漂白的效果. Screen 滤色 C=1-(1-A)*(1-B)也可以写成 1-C=(1-A)*(1-B) 该模式和上一个模式刚好相反,上下层像素的标准色彩值反相后相乘后输出,输出结果比两者的像素值都将要亮(就好像两台投影机分别对其中一个图层进行投影后,然

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

PS图层混合的作用有哪些?会出现怎样的效果

PS图层混合的作用有哪些?我们所熟悉的滤色和正片叠底你是否还记得他们的作用,如果将一黑一白的两个图片进行混合,并去除黑色,你是用滤色还是正片叠底?没关系,笔者整理了一下资料,用户可以看看. 混合模式在PS应用中非常广泛,大多数绘画工具或编辑调整工具都可以使用混合模式,所以正确.灵活使用各种混合模式,可以为图像的效果锦上添花. 单击图层混合模式的下拉组合框,将弹出25种混合模式命令的下拉列表菜单,选择不同的混合模式命令,就可以创建不同的混合效果: 图层的混合模式是用于控制上下图层的混合效果,在设置

Python下opencv使用笔记(十二)(k均值算法之图像分割)

k均值(kmeans)聚类是一种最为简单的聚类方法,直接根据数据点之间的距离(欧氏距离,几何距离等等)来划分数据是属于哪一类的,当所有数据点所属的类别不在变化的时候,聚类也就完成了.详细原理可索引下面一个博客: 聚类分析笔记-K均值matlab算法(一) 关于kmeans再谈几点认识: 重要的一点:聚类数目的问题.有的聚类.分类问题已经限制好了要聚类成几类,也就是聚类数目一定,那么这种聚类通常简单些,直接规定聚类数就好了.而有的聚类问题不知道分成几类才好,这个时候怎么办?那么就需要找到一种评价指

图像滤镜艺术---PS图层混合模式之明度模式

本文将介绍PS图层混合模式中比较复杂 的"明度"模式的算法原理及代码实现内容. 说到PS的图层混合模式,计算公式都有,具体代码实现也能找到,但是,都没有完整介绍所有图层混合模式的代码,比如"明度"模式,公式如下: 假设两张图的HSY颜色模式分别为: Hb,Sb,Yb---Hm,Sm,Ym 明度混合结果HSY = HbSbYm 这个公式很简单,无非就是原图的H,S分量+混合图的Y分量而已,但是具体代码如何实现,却很少有人分享,今天,我将给大家分享本人的代码. HSY模

RGBA alpha 透明度混合算法

RGBA alpha 透明度混合算法 .分类: 图像处理 Ps技术 2011-05-25 09:11 1112人阅读 评论(0) 收藏 举报 Alpha 透明度混合算法,网上收集整理,分成以下三种: 一. R1,G1,B1,Alpha1 为前景颜色值,R2,G2,B2,Alpha2 为背景颜色值,则 前景色 R = R1 * Alpha1 + R2 * Alpha2 * (1-Alpha1) : G = G1 * Alpha1 + G2 * Alpha2 * (1-Alpha1) : B = B