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

OpenCV——色调映射

时间:2014-12-18 11:58:03      阅读:342      评论:0      收藏:0      [点我收藏+]

标签: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"

using namespace std;
using namespace cv;


void Show_Image(Mat&, const string &);


#endif // PS_ALGORITHM_H_INCLUDED

/*
This program will generate
 "Shade" effect.

*/

#include "PS_Algorithm.h"
#include <time.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);

    Mat Image_out(Image_in.size(), CV_32FC3);
    Image_in.convertTo(Image_out, CV_32FC3);

    Mat Map(50, 255, CV_32FC3);

    float val;

    Mat temp;

    // build the mapping talbe
    for (int i=0; i<Map.cols; i++)
    {
        val=i/255.0;
        temp=Map.col(i);
        temp.setTo(Scalar(3*val,3*val-1,3*val-2));
    }

    Show_Image(Map, "Map");

    MatIterator_<Vec3f> pixel_begin, pixel_end;
    pixel_begin=Image_out.begin<Vec3f>();
    pixel_end =Image_out.end<Vec3f>();

    // I=0.299*R+0.587*G+0.144*B

    for( ; pixel_begin!=pixel_end; pixel_begin++)
    {
        val=(*pixel_begin)[0]*0.144;
        val=val+(*pixel_begin)[1]*0.587;
        val=val+(*pixel_begin)[2]*0.299;
        val=val/255.0;
        (*pixel_begin)[0]=3*val;
        (*pixel_begin)[1]=3*val-1;
        (*pixel_begin)[2]=3*val-2;
    }

    Show_Image(Image_out, "out");

    imwrite("out.jpg", Image_out*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);

}



原图 

bubuko.com,布布扣


效果图

bubuko.com,布布扣

OpenCV——色调映射

标签:opencv   算法   应用   

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

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