// 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的更多相关文章

  1. 图像处理------颜色梯度变化 (Color Gradient)

    有过UI设计经验的一定对2D图形渲染中的Color Gradient 或多或少有些接触,很多编程 语言也提供了Gradient的接口,但是想知道它是怎么实现的嘛? 本文介绍三种简单的颜色梯度变化算法, ...

  2. Color gradient in Delphi FireMonkey

    Introduction to color gradients in Delphi FireMonkey. Video This video covers the basics of color gr ...

  3. OpenCV——颜色均匀渐变

    参考来源: 利用OpenCV生成关于某点的颜色径向均匀渐变图像 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_A ...

  4. 基于qml创建最简单的图像处理程序(1)-基于qml创建界面

    <基于qml创建最简单的图像处理程序>系列课程及配套代码基于qml创建最简单的图像处理程序(1)-基于qml创建界面http://www.cnblogs.com/jsxyhelu/p/83 ...

  5. HTML5- Canvas入门(二)

    上篇文章我们了解了canvas的定义.获取和基础的绘图操作,其中的绘图功能我们讲解了线段绘制.上色.描边等方面知识点. 今天我们来讲讲矩形(Rectangle)和多边形的绘制. 矩形的绘制一共有两个口 ...

  6. HTML5- Canvas入门(一)

    周老虎落网的时候,网易跟腾讯都推出了牛逼轰轰的HTML5页面来展示其关系网(网易http://news.163.com/special/data_zyk/  ,腾讯http://news.qq.com ...

  7. Atitit 图像处理知识点体系知识图谱 路线图attilax总结 v4 qcb.xlsx

    Atitit 图像处理知识点体系知识图谱 路线图attilax总结 v4 qcb.xlsx 分类 图像处理知识点体系 v2 qb24.xlsx 分类 分类 理论知识 图像金字塔 常用底层操作 卷积扫描 ...

  8. fillStyle图片填充

    图片自找 <!DOCTYPE HTML> <head> <meta charset = "utf-8"> <title>canvas ...

  9. flot - jQuery 图表插件(jquery.flot)使用

    Flot是纯Javascript实现的基于jQuery的图表插件,主要支持线状图和柱状图的绘制(通过插件也可以支持饼状图). 特别注意Flot使用的是UTC时间,最好修改flot.js去掉所有的UTC ...

随机推荐

  1. cocos2d-x step by step(3) Doub le Kill简单的一些小动画

    在触控厮混了两年多,不过达到了自己的初衷以及目的. 目前从事cocos2d的更改和调优移植工作. 1 简单的一个图片放大和缩小 auto sprite = Sprite::create("l ...

  2. vue生命周期的栗子

    vue生命周期的栗子注意触发vue的created事件以后,this便指向vue实例,这点很重要 <!DOCTYPE html><html><head><me ...

  3. 使用c#訪问Access数据库时,提示找不到可安装的 ISAM

    使用c#訪问Access数据库时,提示找不到可安装的 ISAM.例如以下图: 代码例如以下: connectionString = "Provider=Microsoft.Jet.OLEDB ...

  4. mysql 数据迁移时遇到 外键限制

    禁用外键约束    SET FOREIGN_KEY_CHECKS=0; ......数据迁移........ 启动外键约束    SET FOREIGN_KEY_CHECKS=1;

  5. best-time-to-buy-and-sell-stock系列——先买入后卖出股票的最大值

    1. Say you have an array for which the i th element is the price of a given stock on day  i . If you ...

  6. java new一个接口到底要做什么

    转自:http://www.cnblogs.com/yjmyzz/p/3448330.html java中的匿名类有一个倍儿神奇的用法,见下面代码示例: 1 package contract; 2 3 ...

  7. linux查找文件夹下的全部文件里是否含有某个字符串

    查找文件夹下的全部文件里是否含有某个字符串  find .|xargs grep -ri "IBM"  查找文件夹下的全部文件里是否含有某个字符串,而且仅仅打印出文件名称  fin ...

  8. 【Sprint3冲刺之前】项目完成时间表

    Sprint2冲刺成果——项目完成时间表 项目完成时间表 经过Sprint2小组总结会议的探讨,我们决定一起约定项目alpha版本,beta版本,release版本的发布时间,发布形式及预计完成效果 ...

  9. idea安装plugin

    ---恢复内容开始--- ---恢复内容结束---

  10. ListView优化总结(二)--Android

    3.使用Activity和Delegate与适配器交互 这个内容是从书里看到的,通过托付模式帮助开发人员把全部的业务逻辑从适配器中移到Activity中. 以下是加入电话号码的样例,列表中每一行都有一 ...