mixChannels is to split the main image (or set of images) is input to a copy of some certain channels corresponding to the channel output image (or set of images), in which the correspondence relationship set by fromTo parameters.
Channel Copy: mixChannels function
void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, const int* fromTo, size_to npairs);
- the src, the input image or set of images, need to have the same size and depth.
- nsrcs, the number of the input image.
- dst, the output image, all images must be initialized, and the size and depth must src [0] same.
- ndsts, the number of output images.
- fromTo, correspondence relationship between input channels and output image of the image channel. For the input image, an index of the first channel of FIG selectable range [0, src [0] .channels () - 1], the channel index of the second web of FIG selectable range [src [0] .channels (), src [0] .channels () + src [1] .channels () - 1]. Output image also satisfy this rule. For example, assuming that the input and output images are three-channel image, the desired input channel of the first image of FIG. 3 is placed in the output image of the third channel of FIG. 2, the corresponding relationship src [2] [0] -> dst [1] [2], in the form of fromTo 6 -> 5.
- npairs, the index number fromTo, that there are several fromTo.
Code Example:
#include <opencv.hpp>
#include <the iostream>
the using namespace STD;
the using namespace CV;
Mat the src, hsvImg;
int main () {
the src = imread ( " C: / the Users / Qi Yang Ming / Desktop / passport / 1. JPG " );
imshow ( " the src " , the src);
// convert HSV channel image
cvtColor (the src, hsvImg, COLOR_BGR2HSV);
imshow ( " hsvImg " , hsvImg);
Mat HIMG = Mat (src.size (), CV_8UC1 );
Mat SiMg = Mat (src.size (), CV_8UC1);
Mat vimg= Mat (src.size (), CV_8UC1);
Mat dst [] = {HIMG, SiMg, vimg};
// hsvImg [0] -> HIMG [0] HIMG channel index of dst is: 0
// hsvImg [1] -> sImg [0 ] sImg dst channel index is from:. 1
// hsvImg [2] -> vimg [0] dst vimg channel index in the range: 2
int FromTo [] = { 0 , 0 , . 1 , . 1 , 2 , 2 };
mixChannels ( & hsvImg, . 1 , DST, . 3 , FromTo, . 3 );
imshow ( " HIMG " , HIMG);
imshow ( " SiMg", sImg);
imshow("vImg", vImg);
waitKey(0);
}
Demonstration effect:
Reference blog: https://www.cnblogs.com/ruic/archive/2015/10/31/4926254.html