暂时不知道OpenCV本身有没有更好的方法支持混合 ,于是自己简单的实现了一下,现提供给大伙看看

#include "stdafx.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <windows.h> #define ChannelBlend_Normal(A,B)     ((uchar)(A))
#define ChannelBlend_Lighten(A,B)    ((uchar)((B > A) ? B:A))
#define ChannelBlend_Darken(A,B)     ((uchar)((B > A) ? A:B))
#define ChannelBlend_Multiply(A,B)   ((uchar)((A * B) / 255))
#define ChannelBlend_Average(A,B)    ((uchar)((A + B) / 2))
#define ChannelBlend_Add(A,B)        ((uchar)(min(255, (A + B))))
#define ChannelBlend_Subtract(A,B)   ((uchar)((A + B < 255) ? 0:(A + B - 255)))
#define ChannelBlend_Difference(A,B) ((uchar)(abs(A - B)))
#define ChannelBlend_Negation(A,B)   ((uchar)(255 - abs(255 - A - B)))
#define ChannelBlend_Screen(A,B)     ((uchar)(255 - (((255 - A) * (255 - B)) >> 8)))
#define ChannelBlend_Exclusion(A,B)  ((uchar)(A + B - 2 * A * B / 255))
#define ChannelBlend_Overlay(A,B)    ((uchar)((B < 128) ? (2 * A * B / 255):(255 - 2 * (255 - A) * (255 - B) / 255)))
#define ChannelBlend_SoftLight(A,B)  ((uchar)((B < 128)?(2*((A>>1)+64))*((float)B/255):(255-(2*(255-((A>>1)+64))*(float)(255-B)/255))))
#define ChannelBlend_HardLight(A,B)  (ChannelBlend_Overlay(B,A))
#define ChannelBlend_ColorDodge(A,B) ((uchar)((B == 255) ? B:min(255, ((A << 8 ) / (255 - B)))))
#define ChannelBlend_ColorBurn(A,B)  ((uchar)((B == 0) ? B:max(0, (255 - ((255 - A) << 8 ) / B))))
#define ChannelBlend_LinearDodge(A,B)(ChannelBlend_Add(A,B))
#define ChannelBlend_LinearBurn(A,B) (ChannelBlend_Subtract(A,B))
#define ChannelBlend_LinearLight(A,B)((uchar)(B < 128)?ChannelBlend_LinearBurn(A,(2 * B)):ChannelBlend_LinearDodge(A,(2 * (B - 128))))
#define ChannelBlend_VividLight(A,B) ((uchar)(B < 128)?ChannelBlend_ColorBurn(A,(2 * B)):ChannelBlend_ColorDodge(A,(2 * (B - 128))))
#define ChannelBlend_PinLight(A,B)   ((uchar)(B < 128)?ChannelBlend_Darken(A,(2 * B)):ChannelBlend_Lighten(A,(2 * (B - 128))))
#define ChannelBlend_HardMix(A,B)    ((uchar)((ChannelBlend_VividLight(A,B) < 128) ? 0:255))
#define ChannelBlend_Reflect(A,B)    ((uchar)((B == 255) ? B:min(255, (A * A / (255 - B)))))
#define ChannelBlend_Glow(A,B)       (ChannelBlend_Reflect(B,A))
#define ChannelBlend_Phoenix(A,B)    ((uchar)(min(A,B) - max(A,B) + 255))
#define ChannelBlend_Alpha(A,B,O)    ((uchar)(O * A + (1 - O) * B))
#define ChannelBlend_AlphaF(A,B,F,O) (ChannelBlend_Alpha(F(A,B),A,O))using namespace cv;
using namespace std;int blendX_ = 0;
int blendY_ = 0;
int blendWidth_ = 400;
int blendHeight_ = 400;int _tmain(int argc, _TCHAR* argv[])
{Mat srcImg = imread("srcImg.jpg");Mat blendImg = imread("blendImg.jpg");Mat outputImg ;//check?if (srcImg.rows < blendX_ + blendWidth_||blendImg.rows < blendX_ + blendWidth_||srcImg.cols < blendY_ + blendHeight_||blendImg.cols < blendY_ + blendHeight_){exit(1);}// create vector of 3 imagesvector<Mat> srcImgPlanes;// split 1 3-channel image into 3 1-channel imagessplit(srcImg,srcImgPlanes);// create vector of 3 imagesvector<Mat> blendImgPlanes;// split 1 3-channel image into 3 1-channel imagessplit(blendImg,blendImgPlanes);//check plane size?for (int i=0;i<3;i++){Mat src = srcImgPlanes[i];Mat blend = blendImgPlanes[i];for (int row = blendX_; row < blendX_ + blendWidth_; row++){// get the address of row uchar* srcdata= src.ptr<uchar>(row);uchar* blenddata= blend.ptr<uchar>(row);for (int col = blendY_; col < blendY_ + blendHeight_; col++){// process each pixel ---------------------srcdata[col] = ChannelBlend_Darken(blenddata[col],srcdata[col]);}}}merge(srcImgPlanes,outputImg);namedWindow("Image");imshow("Image",outputImg);waitKey(50000);destroyAllWindows();return 0;
}

OpenCV简单实现PhotoShop图层混合相关推荐

  1. uniapp动态修改样式_掌握Photoshop图层样式技术

    凹凸贴图效果 "等等,什么?" 您会惊叹:""图层样式"菜单中没有凹凸贴图效果!" 的确如此,但是通过将"图案覆盖"和& ...

  2. 《点睛:ActionScript3.0游戏互动编程》——第2章 融会贯通—大话图层样式与滤镜2.1 Photoshop图层样式初体验...

    本节书摘来自异步社区<点睛:ActionScript3.0游戏互动编程>一书中的第2章,第2.1节,作者:游志德 , 彭文波 更多章节内容可以访问云栖社区"异步社区"公 ...

  3. 如何将Photoshop图层复制到其他文档

    如何在Photoshop中复制文档?Photoshop在文档之间复制图层时有几个选项,因此您可以轻松地将图像或徽标添加到不同的文件中,而无需从头开始重新创建. 1.复制粘贴 复制和粘贴是移动Photo ...

  4. html制作象棋教程入门教程,photoshop图层样式制作象棋棋子教程

    教你如何使用photoshop图层样式制作象棋棋子?作者主要通过利用Photoshop图层样式的"斜面与浮雕"功能,生成象棋棋子,方法很简单,只要几步即可快速完成!好了,话不多说, ...

  5. C++实现Photoshop图层颜色混合模式

    注:改进后的实现代码见<C++实现Photoshop图层颜色混合模式(续)>. Photoshop提供了丰富的图象图层混合模式,其中的颜色混合模式是用下图层图象的亮度与上图层填充颜色或者图 ...

  6. 输出ps输出html怎么实现特效,CSS3Ps -Photoshop图层特效转CSS3

    一款可以将Photoshop图层特效转为CSS3代码的免费PS扩展插件. 目前各种浏览器对HTML5.CSS3支持表现程度略有不同,但并没有影响越来越多的HTML5.CSS3技术被应用到实际中,在自己 ...

  7. 《Photoshop图层调整深度剖析》—第1章什么是调整图层?

    本节书摘来自异步社区<Photoshop图层调整深度剖析>一书中的第1章什么是调整图层?,作者[美]Scott Valentine,更多章节内容可以访问云栖社区"异步社区&quo ...

  8. OpenCV简单的过滤器平滑的实例(附完整代码)

    OpenCV简单的过滤器平滑的实例 OpenCV简单的过滤器平滑的实例 OpenCV简单的过滤器平滑的实例 #include <iostream> #include "openc ...

  9. OpenCV简单的几何绘图的实例(附完整代码)

    OpenCV简单的几何绘图的实例 OpenCV简单的几何绘图的实例 OpenCV简单的几何绘图的实例 #include <opencv2/core.hpp> #include <op ...

最新文章

  1. Python与Cisco的事儿之四
  2. JQuery获取元素文档大小、偏移和位置和滚动条位置的方法集合
  3. 误删oracle数据库文件,误删Oracle数据文件导致数据库无法打开
  4. wireshark在win8.1上抓包的问题解决
  5. python dict批量选择_这一定是你见过最全面的python重点
  6. Ruby eventmachine install
  7. 安装APK时弹窗提示“Detected problems with app native libraries”
  8. python编写交互界面设计_第16 p,PYthon中的用户交互,Python GUI编程
  9. StarUML接口视图修改为类的形式
  10. 时间片轮转调度算法的模拟时间片轮转调度算法(RR算法)(队尾C++实现)
  11. XYplorer v17.60.01
  12. python 通达信公式函数_通达信zig函数的python实现
  13. 微信小程序使用canvas绘制分享海报
  14. char类型的取值范围
  15. 国产机们的高端梦:OV保守、米耀激进
  16. 鲍尔默离开后,微软还能东山再起吗?
  17. 快乐Chrismahanakwanzika 2007
  18. 高考+考研,如何选择人工智能相关专业?
  19. 动态修改legend属性
  20. sys/type.h

热门文章

  1. cc2530 按键中断实验——按键控制LED灯的亮灭
  2. 设计模式C++描述----01.单例(Singleton)模式
  3. 八大排序算法--堆排序
  4. ZT:【ROOT教程】S7/S7E 8890版root及替换recovery中文教程
  5. 在国内外市场均遭遇挫折的OPPO和vivo该反思了
  6. ubuntu 强制退出_强制在Ubuntu中退出无响应的图形应用程序
  7. 萧瑜 第一次博客随笔
  8. 仿爱奇艺加载dialog
  9. 数学:定积分和数列和互相转化
  10. Revit二次开发——自动标注钢筋思路(3)