本文介绍了使用Open CV和C ++将彩色图像分成三个通道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Open CV的新手,所以如果我的问题听起来很愚蠢,请原谅我。因此,我正在研究使用拆分功能将BGR通道分割到各个通道的新概念。我正在阅读这个程序,我无法理解代码。所以,任何人都可以向我解释以下代码行,因为我真的很想理解这个概念。



我根本不理解创建蓝色通道部分。请有人能解释一下吗?



src = imread(pic.png);



vector< mat> spl(3);

split(src,spl);



Mat empty_image = Mat :: zeros(src.rows,src。 cols,CV_8UC1);

Mat result_blue(src.rows,src.cols,CV_8UC3); //注意这里的3个频道!



//创建蓝色频道



Mat in1 [] = {spl [0],empty_image,empty_image};

int from_to1 [] = {0,0,1,1,2,2};

mixChannels(in1, 3,& result_blue,1,from_to1,3);



imshow(blue image,result_blue);

I am new to Open CV, so please forgive me if my question sounds stupid. So, i was studying about this new concept of splitting a BGR channel to individual channels using the split function. I was reading this program and i could not understand the code. So, please can anyone explain me the following line of code as i am really wanted to understand the concept.

I did not understand the create blue channel part at all. Please can anyone explain me a bit?

src = imread("pic.png");

vector<mat> spl(3);
split(src,spl);

Mat empty_image = Mat::zeros(src.rows, src.cols, CV_8UC1);
Mat result_blue(src.rows, src.cols, CV_8UC3); // notice the 3 channels here!

// Create blue channel

Mat in1[] = { spl[0], empty_image, empty_image };
int from_to1[] = { 0,0, 1,1, 2,2 };
mixChannels( in1, 3, &result_blue, 1, from_to1, 3 );

imshow("blue image", result_blue);

推荐答案

src = imread("pic.png");
	// . read image file 'pic.png' and save data to variable 'src'
	// . at this time, 'src' will have all informations about
	// . 'pic.png' such as bit count, width, height, plane count,
	// . all pixel values
	// . pixel values will be stored as 3-dimensions array, i.e
	// . src[x][y][i] = i th channel pixel-value for coordinate (x,y)
	// . here 0 : R, 1 : G, 2 : B, or inversely
	// . 0 : B, 1 : G, 2 : R
	
vector spl(3);
	// . vector is array that has N columns and one row.
	// . above means spl is array that has N columns and 3 rows.
	
split(src,spl);
	// . split src into spl
	// . this resuls spl[0] = B space
	// . 			 spl[1] = G space
	// .			 spl[2] = R space

Mat empty_image = Mat::zeros(src.rows, src.cols, CV_8UC1);
	// . initialize empty_image as one channel image which size is
	// . [ src.rows * src.cols ]
	// . here CV_8UC1 is opencv definition value and means that
	// . empty_image will be created as 1 channel matrix.
	// . CV_8UC3 that can be found below line menas that
	// . result_blue will be created as 3 channel matrix.
	
Mat result_blue(src.rows, src.cols, CV_8UC3); // notice the 3 channels here!

// Create blue channel

Mat in1[] = { spl[0], empty_image, empty_image };
	// . in1[] is 3 channel image
	// . channel 1 - B space
	// . channel 2, 3 - zeros
	
int from_to1[] = { 0,0, 1,1, 2,2 };
	// . color-space convertion mapping
	
mixChannels( in1, 3, &result_blue, 1, from_to1, 3 );
	// . here from_to1 is mapping that means that there are no color-space
	// . convertion because from_to1[] is equal-value-mapping.
	// . result_blue[0] = in1[0] = spl[0] = B space
	// . result_blue[1] = in1[1] = zero
	// . result_blue[2] = in1[2] = zero

imshow("blue image", result_blue);
	// . show image on window named "blue image"





我希望我的话能帮到你。



I wish my words would help you.


这篇关于使用Open CV和C ++将彩色图像分成三个通道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:34