参考来源:

利用OpenCV生成关于某点的颜色径向均匀渐变图像

// define head function
#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"
#include "math.h"using namespace std;
using namespace cv;void Show_Image(Mat&, const string &);#endif // PS_ALGORITHM_H_INCLUDED/*
This program will generate
color gradient mapping*/#include "PS_Algorithm.h"
#include <time.h>using namespace std;
using namespace cv;int main(void)
{Mat Img(600, 800, CV_32FC3);Scalar a(255.0, 255.0, 255.0);Scalar b(0.0, 0.0, 0.0);Img.setTo(a);int width, height;width=Img.cols;height=Img.rows;Point2f origin(0.0, 0.0);Point2f Cen(Img.cols/2.0, Img.rows/2.0);float dis;if (origin.x<=Cen.x && origin.y<=Cen.y){dis=sqrt((width-1-origin.x)*(width-1-origin.x)+(height-1-origin.y)*(height-1-origin.y));}else if (origin.x<=Cen.x && origin.y>Cen.y){dis=sqrt((width-1-origin.x)*(width-1-origin.x)+origin.y*origin.y);}else if (origin.x>Cen.x && origin.y>Cen.y){dis=sqrt(origin.x*origin.x+(origin.y)*(origin.y));}else{dis=sqrt(origin.x*origin.x+(height-1-origin.y)*(height-1-origin.y));}float weightB=(b[0]-a[0])/dis;float weightG=(b[1]-a[1])/dis;float weightR=(b[2]-a[2])/dis;float dis2;for (int i=0; i<Img.rows; i++){for (int j=0; j<Img.cols; j++){dis2=sqrt((i-origin.x)*(i-origin.x)+(j-origin.y)*(j-origin.y));Img.at<Vec3f>(i,j)[0]=Img.at<Vec3f>(i,j)[0]+weightB*dis2;Img.at<Vec3f>(i,j)[1]=Img.at<Vec3f>(i,j)[1]+weightG*dis2;Img.at<Vec3f>(i,j)[2]=Img.at<Vec3f>(i,j)[2]+weightR*dis2;}}Img=Img/255.0;Show_Image(Img, "img");imwrite("Out.jpg", Img*255);waitKey();cout<<"All is well."<<endl;}// define the show image
#include "PS_Algorithm.h"
#include <iostream>
#include <string>using namespace std;
using namespace cv;void Show_Image(Mat& Image, const string& str)
{namedWindow(str.c_str(),CV_WINDOW_AUTOSIZE);imshow(str.c_str(), Image);}

转载于:https://www.cnblogs.com/mtcnn/p/9412596.html

OpenCV——颜色均匀渐变相关推荐

  1. opencv 图片边缘渐变_OpenCV——颜色均匀渐变

    参考来源: // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #inclu ...

  2. Android项目120项

    1.一个APP只需要一个Activity //片段fragmentimplementation 'me.yokeyword:fragmentation:1.3.6'implementation 'me ...

  3. Android项目必备技术

    1.一个APP只需要一个Activity //片段fragmentimplementation 'me.yokeyword:fragmentation:1.3.6'implementation 'me ...

  4. python打出由边框包围的_python opencv 图像边框(填充)添加及图像混合的实现方法(末尾实现类似幻灯片渐变的效果)...

    图像边框的实现 图像边框设计的主要函数 cv.copyMakeBorder()--实现边框填充 主要参数如下: 参数一:源图像--如:读取的img 参数二--参数五分别是:上下左右边的宽度--单位:像 ...

  5. 【OpenCV 例程200篇】17. 两张图像的渐变切换

    [OpenCV 例程200篇]17. 两张图像的渐变切换 欢迎关注 『OpenCV 例程200篇』 系列,持续更新中 欢迎关注 『Python小白的OpenCV学习课』 系列,持续更新中 函数 cv2 ...

  6. opencv 图片边缘渐变_基于OpenCV的图像卡通化

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本期将创建一个类似于Adobe Lightroom的Web应用程序 ...

  7. opencv 图片边缘渐变_opencv滤镜-PS羽化特效

    羽化特效羽化是ps术语,羽化原理是令选区内外衔接部分虚化,起到渐变的作用从而达到自然衔接的效果,是ps及其其它版本中的处理图片的重要工具.羽化可使像素选区的边缘变得模糊,有助于所选区域与周围的像素混合 ...

  8. opencv 去除玻璃蒙版_在opencv python中混合渐变蒙版

    我想,也许你想这样的事情. 这是源图像: 的源所迷离-对: 的掩模alphablened-对: 在代码注释中带有描述的代码. #!/usr/bin/python3 # 2018.01.16 13:07 ...

  9. Python,OpenCV中的图像修复——cv2.inpaint()

    Python,OpenCV中的图像修复--cv2.inpaint 1. 效果图 2. 原理 3. 源码 参考 image inpainting 图像修改 这篇博客将介绍如何通过OpenCV中图像修复的 ...

  10. 使用Python和OpenCV检测图像中的条形码

    使用Python和OpenCV检测图像中的条形码 1. 效果图 2. 算法的步骤 3. 源码 参考 这篇博客将介绍使用计算机视觉和图像处理技术进行条形码检测的必要步骤,并演示使用Python编程语言和 ...

最新文章

  1. linux分区模型,linux设备驱动模型详解.pdf
  2. CharSequence和String的区别
  3. Leetcode51 n皇后 DFS+回溯(模板题)
  4. mysql查询更新时的锁表机制分析
  5. 配置 yum 源的两种方法
  6. ubuntu没有声音-只有类比立体声输入
  7. 英国电信云服务直连Salesforce
  8. JavaScript Dom编程艺术
  9. 局部描述符表LDT的作用+定义+初始化+跳转相关
  10. android imageview图片旋转动画,Android 安卓动画 属性动画 - 旋转动画
  11. azure云数据库_在Azure Cosmos DB中使用PowerShell创建和删除数据库
  12. mysql c接口_mysql C语言API接口及实例
  13. 同一个页面多个ajax提交,速度缓慢
  14. Newtonsoft 反序列化字符串
  15. 真实场景下如何解决类别不平衡问题
  16. Eclipse ADT 进行android应用签名打包详解
  17. 服务器 cpu系列 至强系列那个好,至强系列 intel至强和酷睿I系列,到底哪个好
  18. C++ 常函数和常对象
  19. 从零开始搭建公司后台技术栈
  20. DDS之DCPS Subscription模块

热门文章

  1. 订阅个人Blog最新评论的方法
  2. php 图形用户界面GUI 开发
  3. 02_javaSE面试题:单例设计模式
  4. Struts2.3使用Sitemesh如何配置web.xml?
  5. 关于二分限制最短路的题的总结
  6. python中的特殊函数__call__
  7. [BZOJ3124]直径
  8. python 把list中的所有元素串起来变为字符串
  9. linux的jdk、tomcat、tomcat安装等
  10. Hadoop教程(一)