[][src]Function opencv::core::mix_channels

pub fn mix_channels(
    src: &dyn ToInputArray,
    dst: &mut dyn ToInputOutputArray,
    from_to: &[i32]
) -> Result<()>

Copies specified channels from input arrays to the specified channels of output arrays.

The function cv::mixChannels provides an advanced mechanism for shuffling image channels.

cv::split,cv::merge,cv::extractChannel,cv::insertChannel and some forms of cv::cvtColor are partial cases of cv::mixChannels.

In the example below, the code splits a 4-channel BGRA image into a 3-channel BGR (with B and R channels swapped) and a separate alpha-channel image:

   Mat bgra( 100, 100, CV_8UC4, Scalar(255,0,0,255) );
   Mat bgr( bgra.rows, bgra.cols, CV_8UC3 );
   Mat alpha( bgra.rows, bgra.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 };
   // bgra[0] -> bgr[2], bgra[1] -> bgr[1],
   // bgra[2] -> bgr[0], bgra[3] -> alpha[0]
   int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
   mixChannels( &bgra, 1, out, 2, from_to, 4 );

Note: Unlike many other new-style C++ functions in OpenCV (see the introduction section and Mat::create ), cv::mixChannels requires the output arrays to be pre-allocated before calling the function.

Parameters

  • src: input array or vector of matrices; all of 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].
  • 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.

See also

split, merge, extractChannel, insertChannel, cvtColor

Overloaded parameters

  • src: input array or vector of matrices; all of the matrices must have the same size and the same depth.
  • 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].
  • 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.