The main function of the split function is to divide a color image into three channels to facilitate further image processing. The details are as follows:
Split divides a multi-channel array into several single-channel arrays.
C ++: void split (const mat & CTX, mat * mV)
C ++: void split (const mat & CTX, vector & mv)
In fact, there is also a function merge that can implement the opposite operation, the simple description is as follows:
Merge composes a multi-channel array from several single-channel arrays.
C ++: void Merge (const mat * mV, size_t count, outputarray DST)
C ++: void Merge (const vector & mv, outputarray DST)
The sample code is as follows:
# Include "stdafx. H"
# Include "opencv2/imgproc. HPP"
# Include "opencv2/highgui. HPP"
Using namespace CV;
Int main (INT argc, char ** argv)
{
Mat SRC, srcofmerge;
Vector mV;
/// Read image (same size, same type)
Src = imread ("D: \ images \ windowslogo.jpg ");
If (! SRC. Data) {printf ("error loading SRC \ n"); Return-1 ;}
Split (SRC, MV );
/// Create windows
Namedwindow ("RGB", 1 );
Namedwindow ("r", 1 );
Namedwindow ("r", 1 );
Namedwindow ("r", 1 );
Namedwindow ("srcofmerge", 1 );
Imshow ("RGB", Src );
Imshow ("r", MV [0]);
Imshow ("g", MV [1]);
Imshow ("B", MV [2]);
Merge (mV, srcofmerge );
Imshow ("srcofmerge", srcofmerge );
Waitkey (0 );
Return 0;
}
Split and merge functions