Click here to Skip to main content
15,846,145 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
Posted
Updated 2-Apr-15 6:48am
v6

1 solution

I can explain for you.

C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900