Opencv-color operations

Source: Internet
Author: User

#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 computationon three channels respectively, and generatethe "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());}



 


Source image:



:



Opencv-color operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.