zoukankan      html  css  js  c++  java
  • 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);
    
    }
    



    原图 



    效果图


  • 相关阅读:
    ASP.NET Core 发布 centos7 配置守护进程
    AutoMapper在asp.netcore中的使用
    git忽略文件并删除git仓库中的文件
    Animate.css 一款牛逼的css3动画库
    URL中特殊符号的处理
    efcore 配置链接sqlserver
    简单抓取小程序大全,并展示。
    UEditor上传图片到七牛C#(后端实现)
    软件项目管理三国启示录01 群雄争霸之项目经理的自我修养
    【调侃】IOC前世今生
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9412659.html
Copyright © 2011-2022 走看看