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

时间: 2024-08-08 07:05:55

Opencv— — Color Gradient的相关文章

OpenCV——颜色均匀渐变

参考来源: 利用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&quo

SVG.js Mask覆盖和ClipPath裁剪

一.SVG.Mask 覆盖物设置 1. var draw = SVG('svg1').size(300, 300); //SVG.Mask 覆盖物设置 var ellipse = draw.ellipse(80, 40).move(10, 10).fill('#fff'); var mask = draw.mask().add(ellipse); //添加到矩形 maskWith() var rect = draw.rect(100, 100); rect.maskWith(mask); //获

Qt4.7文档翻译:Qt样式单参考,Qt Style Sheets Reference(超长,超全)

内容目录 Qt样式单参考 可进行样式设置的部件列表 属性列表 图标列表 属性类型列表 伪状态列表 子控件列表 Qt样式单参考 Qt样式单支持各种属性.伪状态和子控件,这样使得妳能够自行设计部件的外观. 可进行样式设置的部件列表 下表列出的是可使用样式单来自定义其外观的Qt 部件: 部件 如何设置样式 QAbstractScrollArea 支持盒状模型. QAbstractScrollArea的所有继承类,包括QTextEdit和QAbstractItemView(所有的条目视图(item vi

前端开发利器-Brackets IDE

是什么? http://brackets.io/ A modern, open source text editor that understands web design. 现代, 开源的文本编辑器, 最懂得web设计. With focused visual tools and preprocessor support, Brackets is a modern text editor that makes it easy to design in the browser. 专注可视化工具

code实现透明度渐变和颜色渐变的view

最近用code写了些view上的渐变效果,使得app的UI特效不必全部依赖美工出的图片. 效果如下: 主要用到了Layer上的渐变层,核心代码如下,关于CALaer的使用可参考 //Transparent Gradient Layer - (void) insertTransparentGradient { UIColor *colorOne = [UIColor colorWithRed:(33/255.0) green:(33/255.0) blue:(33/255.0) alpha:0.0

dmytrodanylyk/circular-progress-button源码解析(一)

转载请注明出处http://blog.csdn.net/crazy__chen/article/details/46278423 源码下载http://download.csdn.net/detail/kangaroo835127729/8755815 dmytrodanylyk/circular-progress-button是github上一个开源的按钮控件,这个是链接https://github.com/dmytrodanylyk/circular-progress-button 下面是示

Canvas 笔记(持续更新中)

1.从线条开始 HTML <canvas id="canvas"></canvas> Javascript var canvas=document.getElementById("canvas"); var context=canvas.getContext("2d") canvas.width canvas.height canvas.getContext("3d") moveTo(x,y) line

The Amazing ProgressBar Control(转)

好久没写博客了,今天就先转一篇,随后可以再写些~~~ 直接把原文粘过来,就不再进行翻译和个人说明了,因为效果很COOL~ The Amazing ProgressBar Control A progress bar which displays progress as passage through a simple maze. Download AmazingProgressBar_111_Demo.zip Download AmazingProgressBar_111_Library.zip

---JS canvas学习笔记

context的fillStyle属性 fillStyle=color | gradient | image | canvas |video strokeStyle也有上述属性. 1.color:#ffffff | #362 | rgba(100,100,100,0.8) | red css可以使用的格式在此都可以使用 2.gradient Linear Gradient var grd=context.createLinearGradient(xstart,ystart,xend,yend);