openCV——split和merge的使用

Posted by XushengLee on July 20, 2016

大图为红绿色道的无名酱_(:зゝ∠)_

惯例,来一个传送门 浅墨的csdn 详细声明说明等,请各位膜法师自行传送.

##本次代码

#include<cv.h>
#include<highgui.h>
#include <iostream>
#include <vector>   //用于接收分离的多个单通道

using namespace cv;
using namespace std;

int main(){
    Mat logo1 = imread("/Users/mac/Pictures/pixiv-dasktop/noname.jpg");
    vector<Mat> channels;
    split(logo1, channels);
    Mat outcome;
    vector<Mat> test;
    test.push_back(channels[2]);
    test.push_back(channels[1]);
   test.push_back(channels[2]);
 //   test.push_back(channels[1]);
    merge(test, outcome); //merge只能merge 1,3,4通道,所以只能凑数了...
    namedWindow("1");
    imshow("1", outcome);
    imwrite("/Users/mac/Pictures/noname-purple.jpg",outcome);//保存文件
    waitKey();
//    namedWindow("2");
//    imshow("2",channels.at(0)); //显示单个通道
//    waitKey();
    return 0;
}

下面分析下rgb色彩通道

imageBlueChannel = channels.at(0);  
imageGreenChannel = channels.at(1);  
imageRedChannel = channels.at(2); 

也就是说,rgb, red -> 2, green -> 1, blue -> 0;