zoukankan      html  css  js  c++  java
  • Opencv— — mix channels

        // 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
        // The program will mix the color channels.
    
                #include "PS_Algorithm.h"
                int main()
                {
                    string  Image_name("4.jpg");
                    Mat Image=imread(Image_name.c_str());
                    Mat Image_test(Image.size(),CV_32FC3);
                    Image.convertTo(Image_test, CV_32FC3);
    
                    Mat New_img(Image_test.size(), CV_32FC3);
                    Mat r, g, b;
                    Mat bgr[]={b,g,r};
    
                    split(Image_test, bgr);
    
                    b=bgr[0];
                    g=bgr[1];
                    r=bgr[2];
    
                    float blueGreen, redBlue, greenRed;
                    blueGreen=0.5;
                    redBlue=0.5;
                    greenRed=0.5;
    
                    float intoR, intoG, intoB;
                    intoR=0.75;
                    intoG=0.25,
                    intoB=0.75;
    
                    Mat N_R(r.size(), CV_32FC1);
                    Mat N_G(r.size(), CV_32FC1);
                    Mat N_B(r.size(), CV_32FC1);
    
                    Mat new_bgr[]={N_B, N_G, N_R};
    
                    N_R=(intoR * (blueGreen*g+(1-blueGreen)*b) + (1-intoR)*r);
                    N_G=(intoG * (redBlue*b+(1-redBlue)*r) + (1-intoG)*g);
                    N_B=(intoB * (greenRed*r+(1-greenRed)*g) + (1-intoB)*b);
    
                    merge(new_bgr, 3, New_img);
    
                    New_img=New_img/255.0;
    
                    Show_Image(New_img, "New_img");
    
                    cout<<"All is well."<<endl;
                    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/46790129

  • 相关阅读:
    UVA-1595 Symmetry
    UVA-10763 Foreign Exchange
    剑指Offer
    剑指Offer
    剑指Offer
    剑指Offer
    剑指Offer
    剑指Offer
    剑指Offer
    剑指Offer
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9412530.html
Copyright © 2011-2022 走看看