AForge.NET

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

AForge.NET Framework
2.2.5 version is available!

Pixel filtering by color

AForge.NET framework provides number of image processing filters, which allow to filter pixels depending on their color values. These image processing filters may be used to keep pixels, which color falls inside or outside of specified range, and fill the rest of pixels with specified color.

Below is the list of implemented pixel filters and the result of their application to the below source image.

Source image
Source image

Color Filtering
The image processing filter filters pixels inside/outside of specified RGB color range - it keeps pixels with colors inside/outside of specified range and fills the rest with specified color.

// create filter
ColorFiltering filter = new ColorFiltering( );
// set color ranges to keep
filter.Red   = new IntRange( 100, 255 );
filter.Green = new IntRange( 0, 75 );
filter.Blue  = new IntRange( 0, 75 );
// apply the filter
filter.ApplyInPlace( image );
RGB Color Filtering

Channel Filtering
The channel filtering filter is similar to the above color filtering. It also operates in RGB color space, but does filtering of not entire pixels, but their RGB values. This means that pixel itself may not be filtered (will be kept), but one of its RGB values may be filtered if they are inside/outside of specified range.

// create filter
ChannelFiltering filter = new ChannelFiltering( );
// set channels' ranges to keep
filter.Red   = new IntRange(   0, 255 );
filter.Green = new IntRange( 100, 255 );
filter.Blue  = new IntRange( 100, 255 );
// apply the filter
filter.ApplyInPlace( image );
RGB Channel Filtering

HSL Filtering
The image processing filter operates in HSL color space and filters pixels, which color is inside/outside of the specified HSL range - it keeps pixels with colors inside/outside of the specified range and fills the rest with specified color.

// create filter
HSLFiltering filter = new HSLFiltering( );
// set color ranges to keep
filter.Hue = new IntRange( 335, 0 );
filter.Saturation = new Range( 0.6f, 1 );
filter.Luminance  = new Range( 0.1f, 1 );
// apply the filter
filter.ApplyInPlace( image );
HSL Color Filtering

YCbCr Filtering
The image processing filter operates in YCbCr color space and filters pixels, which color is inside/outside of the specified YCbCr range - it keeps pixels with colors inside/outside of the specified range and fills the rest with specified color.

// create filter
YCbCrFiltering filter = new YCbCrFiltering( );
// set color ranges to keep
filter.Cb = new Range( -0.2f, 0 );
filter.Cr = new Range( 0.26f, 0.5 );
// apply the filter
filter.ApplyInPlace( image );
YCbCr Color Filtering

Euclidean Color Filtering
The image processing filter filters pixels, which color is inside/outside of RGB sphere with specified center and radius - it keeps pixels with colors inside/outside of the specified sphere and fills the rest with specified color.

// create filter
EuclideanColorFiltering filter = new EuclideanColorFiltering( );
// set center colol and radius
filter.CenterColor = Color.FromArgb( 215, 30, 30 );
filter.Radius = 100;
// apply the filter
filter.ApplyInPlace( image );
Euclidean Color Filtering