Search code examples
image-processingemgucv

how to separate the channels of an RGB image in emgu?


I need to separate an RGB image into 3 channels. In the other words i need a code to do the following.

Image<Bgr, Byte> imgBgr = CvInvoke.Imread("Im.jpg").ToImage<Bgr, Byte>();
Mat blue = imgBgr.BlueChannel;
Mat green = imgBgr.GreenChannel;
Mat red = imgBgr.RedChannel;

Thanks!


Solution

  • There are 2 ways to do that.

    1. Use imgBgr.Split(). It returns an array of 3 gray images that each image represents a single color channel of the original image.

    2. Use imgBgr.Sub(color). It will subtract the color from the original image. For example, if you want to get red color only, remove green and blue, imgBgr.Sub(new Rgb(0, 255, 255)) and so on.