• 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 
    ";
    
    }
    
    
    </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());
    }
    



    
    


    原图: 



    效果图:



  • 相关阅读:
    python 正则表达式练习题
    python2与Python3的区别
    Python :生成一个1到50的大字符串,每个数字之间有个空格 1 2 3 4 ..........50
    关于实现今天到一年中任意一天两者之间的天数差的计算
    Window下pip的安装
    Pycharm中Git、Github的简单使用和配置
    Python中字符串操作函数string.split('str1')和string.join(ls)
    实现无密码远程登陆另一台机器
    我的第一篇博客
    String类型转List<Integer>
  • 原文地址:https://www.cnblogs.com/muyuge/p/6152364.html
Copyright © 2020-2023  润新知