Opencv— — Color Gradient
// 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
#include "PS_Algorithm.h"
#include <time.h>
using namespace std;
using namespace cv;
#define pi 3.1415926
int main()
{
string Img_name("4.jpg");
Mat Img;
Img=imread(Img_name);
Mat Img_out(Img.size(), CV_8UC3);
int width=Img.cols;
int height=Img.rows;
float rNW=1.0; float gNW=0.0; float bNW=0.0;
float rNE=1.0; float gNE=1.0; float bNE=0.0;
float rSW=0.0; float gSW=0; float bSW=1.0;
float rSE=0.0; float gSE=1.0; float bSE=0.0;
float fx, fy;
float p, q, r, g, b;
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
fx=(float)(x)/width;
fy=(float)(y)/height;
p = rNW + (rNE - rNW) * fx;
q = rSW + (rSE - rSW) * fx;
r = ( p + (q - p) * fy );
r = min(max(r, 0.0f), 1.0f);
p = gNW + (gNE - gNW) * fx;
q = gSW + (gSE - gSW) * fx;
g = ( p + (q - p) * fy );
g = min(max(g, 0.0f) ,1.0f);
p = bNW + (bNE - bNW) * fx;
q = bSW + (bSE - bSW) * fx;
b = ( p + (q - p) * fy );
b = min(max(b, 0.0f), 1.0f);
Img_out.at<Vec3b>(y, x)[0]=b*255.0;
Img_out.at<Vec3b>(y, x)[1]=g*255.0;
Img_out.at<Vec3b>(y, x)[2]=r*255.0;
}
}
Show_Image(Img_out, "out");
cout<<"All is well"<<endl;
// imwrite("Out.jpg", Img_out);
waitKey();
}
// 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);
}
图像效果可以参考:
http://blog.csdn.net/matrix_space/article/details/46906849
Opencv— — Color Gradient的更多相关文章
- 图像处理------颜色梯度变化 (Color Gradient)
有过UI设计经验的一定对2D图形渲染中的Color Gradient 或多或少有些接触,很多编程 语言也提供了Gradient的接口,但是想知道它是怎么实现的嘛? 本文介绍三种简单的颜色梯度变化算法, ...
- Color gradient in Delphi FireMonkey
Introduction to color gradients in Delphi FireMonkey. Video This video covers the basics of color gr ...
- OpenCV——颜色均匀渐变
参考来源: 利用OpenCV生成关于某点的颜色径向均匀渐变图像 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_A ...
- 基于qml创建最简单的图像处理程序(1)-基于qml创建界面
<基于qml创建最简单的图像处理程序>系列课程及配套代码基于qml创建最简单的图像处理程序(1)-基于qml创建界面http://www.cnblogs.com/jsxyhelu/p/83 ...
- HTML5- Canvas入门(二)
上篇文章我们了解了canvas的定义.获取和基础的绘图操作,其中的绘图功能我们讲解了线段绘制.上色.描边等方面知识点. 今天我们来讲讲矩形(Rectangle)和多边形的绘制. 矩形的绘制一共有两个口 ...
- HTML5- Canvas入门(一)
周老虎落网的时候,网易跟腾讯都推出了牛逼轰轰的HTML5页面来展示其关系网(网易http://news.163.com/special/data_zyk/ ,腾讯http://news.qq.com ...
- Atitit 图像处理知识点体系知识图谱 路线图attilax总结 v4 qcb.xlsx
Atitit 图像处理知识点体系知识图谱 路线图attilax总结 v4 qcb.xlsx 分类 图像处理知识点体系 v2 qb24.xlsx 分类 分类 理论知识 图像金字塔 常用底层操作 卷积扫描 ...
- fillStyle图片填充
图片自找 <!DOCTYPE HTML> <head> <meta charset = "utf-8"> <title>canvas ...
- flot - jQuery 图表插件(jquery.flot)使用
Flot是纯Javascript实现的基于jQuery的图表插件,主要支持线状图和柱状图的绘制(通过插件也可以支持饼状图). 特别注意Flot使用的是UTC时间,最好修改flot.js去掉所有的UTC ...
随机推荐
- 邁向IT專家成功之路的三十則鐵律 鐵律二十一:IT人用才之道-穿透
在以道德為基礎的企業主管之人,其最根本的能力除了須要有洞悉事物的敏捷思維之外,眼光還必要有像水柱般一樣的穿山引石之能,如此不僅能夠為企業找到適才之人,更能為企業的永續經營奠定有如泰山般的基石.只可惜大 ...
- 【GitHub】删除GitHub上的文件
想要删除已经提交上GitHub上的文件, 删除之后,如果这个文件夹下没有文件了,这个文件夹也会被删除! 并且在它的上层文件夹后面 有提示删除了这个文件的信息!!
- cocos2d-x-3.x bringToFront & sendToBack实现
void Node::bringToFront(void) { auto parent = this->getParent(); if (parent != nullptr && ...
- jsp中获取spring 管理的bean(通过config)
WebApplicationContext wac = (WebApplicationContext)config.getServletContext().getAttribute(WebApplic ...
- vue2.0 自定义过滤器
2.0中已经废弃了过滤器,需要我们自定义 <div id="app"> {{message|uppercase}} </div> //过滤器 Vue.fil ...
- [ssh新闻公布系统三]存储新闻
一.存储新闻dao方法 在NewsDao.java中新增存储新闻的saveOrupdate方法 public void saveOrupdate(News news){ getSession().sa ...
- JobClient
/** * <code>JobClient</code> is the primary interface for the user-job to interact * wit ...
- UE-9260使用说明2
生成镜像 1. U-boot 生成u-boot.bin文件 (1) Makefile ifeq ($(ARCH),arm) CROSS_COMPILE = endif 改动为 ifeq ($(ARCH ...
- 怎样创建.NET Web Service http://blog.csdn.net/xiaoxiaohai123/article/details/1546941
为什么需要Web Service 在通过internet网购买商品后,你可能对配送方式感到迷惑不解.经常的情况是因配送问题找配送公司而消耗你的大量时间,对于配送公司而言这也不是一项增值服务. 为了解决 ...
- WPF3.5 使用BINDINGGROUP进行实体类和集合验证
前文介绍了自定义或系统自带的ValidationRule进行验证,这种方法对于单个元素的验证不错.很多时候,我们需要对表单(Form)进行验证,也就是对一个实体类进行验证,或者对一个集合的每项进行验证 ...