[bogs 算法原理]图层混合

// mix.cpp : 图像mix

//

#include "stdafx.h"

#include <iostream>

#include "opencv2/core/core.hpp"

#include "opencv2/highgui/highgui.hpp"

#include "opencv2/imgproc/imgproc.hpp"

using namespace std;

using namespace cv;

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

}

}

}

// 线性增强

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

}

}

}

int _tmain(int argc, _TCHAR* argv[])

{

//首先做灰度的mix

Mat src = imread("1.jpg");

Mat mask = imread("mask2.jpg");

Mat maskF(src.size(),CV_32FC3);

Mat srcF(src.size(),CV_32FC3);

Mat dstF(src.size(),CV_32FC3);

src.convertTo(srcF,CV_32FC3);

mask.convertTo(maskF,CV_32FC3);

srcF = srcF /255;

maskF = maskF/255;

Mat dst(srcF);

//正片叠底

Multiply(srcF,maskF,dstF);

dstF = dstF *255;

dstF.convertTo(dst,CV_8UC3);

imwrite("正片叠底.jpg",dst);

// Color_Burn 颜色加深

Color_Burn(srcF,maskF,dstF);

dstF = dstF *255;

dstF.convertTo(dst,CV_8UC3);

imwrite("颜色加深.jpg",dst);

// 线性增强

Linear_Burn(srcF,maskF,dstF);

dstF = dstF *255;

dstF.convertTo(dst,CV_8UC3);

imwrite("线性增强.jpg",dst);

waitKey();

return 0;

}

来自为知笔记(Wiz)

时间: 2024-08-29 19:11:42

[bogs 算法原理]图层混合的相关文章

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

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

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

由Photoshop高反差保留算法原理联想到的一些图像增强算法。

原地址:http://blog.csdn.net/laviewpbt/article/details/20577683 关于高反差保留的用处说明呢,从百度里复制了一段文字,我觉得写得蛮好的: 高反差保留就是保留图像的高反差部分,再说得真白些,就是保留图像上像素与周围反差比较大的部分,其它的部分都变为灰色.拿一个人物照片来举例,反差比较大的部分有人的眼睛,嘴,以及身体轮廓.如果执行了就反差保留,这些信息将留下来(与灰色形成鲜明对比).它的主要作用就是加强图像中高反差部分.还以人物照片为例子,一般为

微博URL短网址生成算法原理及(java版、php版实现实例)

短网址(Short URL),顾名思义就是在形式上比较短的网址.通常用的是asp或者php转向,在Web 2.0的今天,不得不说,这是一个潮流.目前已经有许多类似服务,借助短网址您可以用简短的网址替代原来冗长的网址,让使用者可以更容易的分享链接. 例如:http://t.cn/SzjPjA 短网址服务,可能很多朋友都已经不再陌生,现在大部分微博.手机邮件提醒等地方已经有很多应用模式了,并占据了一定的市场.估计很多朋友现在也正在使用. 看过新浪的短连接服务,发现后面主要有6个字符串组成,于是第一个

iOS开发笔记15:地图坐标转换那些事、block引用循环、UICollectionviewLayout及瀑布流、图层混合

1.地图坐标转换那些事 (1)投影坐标系与地理坐标系 地理坐标系使用三维球面来定义地球上的位置,单位即经纬度.但经纬度无法精确测量距离戒面积,也难以在平面地图戒计算机屏幕上显示数据.通过投影的方式可以将其转换成平面的投影坐标系,不同的投影方式可能会带来不同的变形及误差,类似于把一个橘子的橘子皮剥开摊平到桌面. GPS以及iOS系统定位获得的坐标是地理坐标系WGS1984,Web地图一般用的坐标细是投影坐标系WGS 1984 Web Mercator,国内出于相关法律法规要求,对国内所有GPS设备

Adaboost算法原理分析和实例+代码(简明易懂)

Adaboost算法原理分析和实例+代码(简明易懂) [尊重原创,转载请注明出处] http://blog.csdn.net/guyuealian/article/details/70995333     本人最初了解AdaBoost算法着实是花了几天时间,才明白他的基本原理.也许是自己能力有限吧,很多资料也是看得懵懵懂懂.网上找了一下关于Adaboost算法原理分析,大都是你复制我,我摘抄你,反正我也搞不清谁是原创.有些资料给出的Adaboost实例,要么是没有代码,要么省略很多步骤,让初学者