码迷,mamicode.com
首页 > 其他好文 > 详细

OpenCV——颜色运算

时间:2014-10-27 19:39:20      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:应用   opencv   算法   

#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"

using namespace std;
using namespace cv;


void Show_Image(Mat&, const string &);

void Save_Image(Mat&, const string &);

#endif // PS_ALGORITHM_H_INCLUDED



/*
This program will do the computation
on three channels respectively, and generate
the "cast" effect.

*/

#include "PS_Algorithm.h"

using namespace std;
using namespace cv;

int main(void)
{

    string Img_name("4.jpg");

    Mat Image_in;
    Image_in=imread(Img_name);
    Show_Image(Image_in, Img_name);

    // split the three channels
    Mat Image_2(Image_in.size(), CV_32FC3);
    Image_in.convertTo( Image_2, CV_32FC3);

    Mat r(Image_in.rows, Image_in.cols, CV_32FC1);
    Mat g(Image_in.rows, Image_in.cols, CV_32FC1);
    Mat b(Image_in.rows, Image_in.cols, CV_32FC1);
    Mat out[]={b, g, r};

    split(Image_2, out);

    b=out[0]/255;
    g=out[1]/255;
    r=out[2]/255;

    // generate the new image
    Mat Image_new(Image_in.size(), CV_32FC3);
    Image_in.convertTo( Image_new, CV_32FC3);

    // generate new channels
    Mat r_new(Image_in.rows, Image_in.cols, CV_32FC1);
    Mat g_new(Image_in.rows, Image_in.cols, CV_32FC1);
    Mat b_new(Image_in.rows, Image_in.cols, CV_32FC1);

    float alpha;
    alpha=0.15;
    // cv::divide(r,(b+g+0.001),r_new, alpha);
    // cv::divide(g,(b+r+0.001),g_new, alpha);
    // cv::divide(b,(r+g+0.001),b_new, alpha);

    r_new=r*alpha/(b+g+0.001);
    g_new=g*alpha/(r+b+0.001);
    b_new=b*alpha/(r+g+0.001);

    Mat out_new[]={b_new, g_new, r_new};
    cv::merge(out_new, 3, Image_new);
    Show_Image(Image_new, "Img_out");
    waitKey();

    cout<<"All is well \n";

}

</pre><pre name="code" class="cpp">#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);
    // waitKey();
    // cvDestroyWindow(str.c_str());
}





原图: 

bubuko.com,布布扣


效果图:

bubuko.com,布布扣


OpenCV——颜色运算

标签:应用   opencv   算法   

原文地址:http://blog.csdn.net/matrix_space/article/details/40263809

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!