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!
There are 2 ways to do that.
Use imgBgr.Split()
. It returns an array of 3 gray images that each image represents a single color channel of the original image.
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.