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);
}