opencv 通道分离(split)与合并(merge)

通道分离

void cv::split(
	const cv::Mat& mtx, //输入图像
	vector& mv // 输出的多通道序列(n个单通道序列)
);

通道合并

void cv::split(
	const cv::Mat& mtx, //输入图像
	vector& mv // 输出的多通道序列(n个单通道序列)
);

demo

#include   
#include   
#include   
#include 


using namespace cv;
int main() {

	cv::Mat blank_ch,fin_img;
	cv::Mat src = cv::imread("E:\\Windowstest\\ConsoleApplication4\\ycy.jpg", 1);

	blank_ch = cv::Mat::zeros(cv::Size(src.cols, src.rows), CV_8UC1);
	std::vector rgbChannels(3);
	split(src, rgbChannels);//分为三个通道

    //R通道
	std::vector channels_r;
	channels_r.push_back(blank_ch);
	channels_r.push_back(blank_ch);
	channels_r.push_back(rgbChannels[2]);
	merge(channels_r,fin_img);
	cv::namedWindow("t1", 0);
	cv::imshow("t1", fin_img);

    //G通道
	std::vector channels_g;
	channels_g.push_back(blank_ch);
	channels_g.push_back(rgbChannels[1]);
	channels_g.push_back(blank_ch);
	merge(channels_g, fin_img);
	namedWindow("t2",0);
	imshow("t2",fin_img);

    //B通道
	std::vector channels_b;
	channels_b.push_back(rgbChannels[0]);
	channels_b.push_back(blank_ch);
	channels_b.push_back(blank_ch);
	merge(channels_b,fin_img);
	namedWindow("t3", 0);
	imshow("t3", fin_img);

	cv:namedWindow("result", 0);
	cv::imshow("result", src);
	cv::waitKey(0);

	return 0;
}


你可能感兴趣的:(opencv)