通道的分离与合并

代码

    class Program
    {
        static void Main(String[] args)
        {
            Mat img = CvInvoke.Imread(@"C:\Users\dell\Pictures\mach.jpg");
            Mat pic = new Mat();
            int ch=img.NumberOfChannels;


            VectorOfMat dst = new VectorOfMat(ch);
            CvInvoke.Split(img,dst);
            CvInvoke.Imshow("hello", img);
            Mat blue = dst[0];
            Mat green = dst[1];
            Mat red = dst[2];

            CvInvoke.Threshold(blue, blue, 200, 255, ThresholdType.Binary);
            CvInvoke.Threshold(green, green, 200, 255, ThresholdType.Binary);
            CvInvoke.Threshold(red, red, 200, 255, ThresholdType.Binary);
            CvInvoke.Merge(dst, pic);
            
            CvInvoke.Imshow("b", blue);
            CvInvoke.Imshow("g", green);
            CvInvoke.Imshow("r", red);

            CvInvoke.Imshow("m", pic);
            CvInvoke.WaitKey(0);
        }

    }

效果如下:

猜你喜欢

转载自www.cnblogs.com/noigel/p/10941709.html