mixChannels
Copies specified channels from input arrays to the specified channels of output arrays.
從輸入中拷貝某通道到輸出中特定的通道。
C++: void mixChannels(const Mat*src, size_t nsrcs, Mat* dst, size_t ndsts, const int* fromTo, size_t npairs)
C++: void mixChannels(const vector<Mat>&src, vector<Mat>&dst, const int*fromTo, size_t npairs)
參數
src– Input array or vector of matrices. All the matrices must have the same size and the same depth.
輸入矩陣的向量(可以理解成一隊矩陣),所有矩陣必須有相同的大小和深度。
nsrcs– Number of matrices in src.
輸入矩陣的個數。
dst– Output array or vector of matrices. All the matrices must be allocated. Their size and depth must be the same as in src[0].
輸出矩陣的向量。所有的矩陣必須事先分配空間(如用create),大小和深度須與輸入矩陣等同。
ndsts– Number of matrices in dst.
輸出矩陣的個數。
fromTo – Array of index pairs specifying which channels are copied and where.
序號對向量,用來決定哪個通道被拷貝,拷貝到哪個通道。
fromTo[k*2] is a 0-based index of the input channel in src.
fromTo[k*2+1] is an index of the output channel in dst. The continuous channel numbering is used: the first input image channels are indexed from 0 to src[0].channels()-1 , the second
input image channels are indexed from src[0].channels() to src[0].channels() + src[1].channels()-1, and so on. The same scheme is used for the output image channels. As a special case, when fromTo[k*2] is negative, the corresponding output channel is filled with zero .
上面的大體含義是:偶數下標的用來標識輸入矩陣,奇數下標的用來標識輸出矩陣。如果偶數下標為負數,那么相應的輸出矩陣為零矩陣。
npairs– Number of index pairs in fromTo.
fromTo中的序號對數(兩個算1對)。
Mat rgba( 3, 4, CV_8UC4, Scalar(1,2,3,4) ); Mat bgr( rgba.rows, rgba.cols, CV_8UC3 ); Mat alpha( rgba.rows, rgba.cols, CV_8UC1 ); // forming an array of matrices is a quite efficient operation, // because the matrix data is not copied, only the headers Mat out[] = { bgr, alpha }; // rgba[0] -> bgr[2], rgba[1] -> bgr[1], // rgba[2] -> bgr[0], rgba[3] -> alpha[0] int from_to[] = { 0,2, 1,1, 2,0, 3,3 }; mixChannels( &rgba, 1, out, 2, from_to, 4 );
mat grav0;
for( int c = 0; c < 2; c++ ) { int ch[] = {c, 0}; mixChannels(&timg, 1, &gray0, 1, ch, 1);
}