AForge.NET

Testimonials
Features
Samples
Tools
Documentation
License
Downloads
Sources
Discussions
Partners
Projects
Members
Donate

AForge.NET Framework
2.2.5 version is available!

Color channels manipulations

AForge.NET framework provides different filters for extraction and replacement of images' color channels. This may be useful in some computer vision tasks, for example when it is required to analyze separately blue channel of RGB image. Also these filters may be useful in other different tasks, when it is required to extract certain $channel, process it somehow and then put it back into the original image.

Source image
Source image

RGB color space
For RGB color space the framework provides ExtractChannel and ReplaceChannel filters, which allow to extract/replace R, G or B channel of specified image. As an example, below is a sample, which extracts red channel, does processing with it and then puts it back:

// extract red channel
ExtractChannel extractFilter = new ExtractChannel( RGB.R );
Bitmap channel = extractFilter.Apply( image );
// threshold channel
Threshold thresholdFilter = new Threshold( 230 );
thresholdFilter.ApplyInPlace( channel );            
// put the channel back
ReplaceChannel replaceFilter = new ReplaceChannel( RGB.R, channel );
replaceFilter.ApplyInPlace( image );
RGB channel extract/replace

YCbCr color space
For YCbCr color space the framework provides YCbCrExtractChannel and YCbCrReplaceChannel filters, which allow to extract/replace Y, Cb or Cr channel of specified image. As an example, below is a sample, which extracts Cb channel, does processing with it and then puts it back:

// create YCbCrExtractChannel filter for channel extracting
YCbCrExtractChannel extractFilter = new YCbCrExtractChannel(
                                    YCbCr.CbIndex );
// extract Cb channel
Bitmap cbChannel = extractFilter.Apply( image );
// invert the channel
Invert invertFilter = new Invert( );
invertFilter.ApplyInPlace( cbChannel );
// put the channel back into the source image
YCbCrReplaceChannel replaceFilter = new YCbCrReplaceChannel(
                                    YCbCr.CbIndex, cbChannel );
replaceFilter.ApplyInPlace( image );
YCbCr channel extract/replace