C# Class AForge.Imaging.ColorReduction.ColorImageQuantizer

Color quantization tools.

The class contains methods aimed to simplify work with color quantization algorithms implementing IColorQuantizer interface. Using its methods it is possible to calculate reduced color palette for the specified image or reduce colors to the specified number.

Sample usage:

// instantiate the images' color quantization class ColorImageQuantizer ciq = new ColorImageQuantizer( new MedianCutQuantizer( ) ); // get 16 color palette for a given image Color[] colorTable = ciq.CalculatePalette( image, 16 ); // ... or just reduce color in the specified image Bitmap newImage = ciq.ReduceColors( image, 16 );

Initial image:

Result image:

Show file Open project: noxryan/Claro-Shader Class Usage Examples

Public Methods

Method Description
CalculatePalette ( Bitmap image, int paletteSize ) : Color[]

Calculate reduced color palette for the specified image.

See CalculatePalette(UnmanagedImage, int) for details.

CalculatePalette ( UnmanagedImage image, int paletteSize ) : Color[]

Calculate reduced color palette for the specified image.

The method processes the specified image and feeds color value of each pixel to the specified color quantization algorithm. Finally it returns color palette built by that algorithm.

ColorImageQuantizer ( IColorQuantizer quantizer ) : System

Initializes a new instance of the ColorImageQuantizer class.

ReduceColors ( Bitmap image, Color palette ) : Bitmap

Create an image with reduced number of colors using the specified palette.

See ReduceColors(UnmanagedImage, Color[]) for details.

ReduceColors ( Bitmap image, int paletteSize ) : Bitmap

Create an image with reduced number of colors.

See ReduceColors(UnmanagedImage, int) for details.

ReduceColors ( UnmanagedImage image, Color palette ) : Bitmap

Create an image with reduced number of colors using the specified palette.

The method creates an image, which looks similar to the specified image, but contains reduced number of colors. Is substitutes every pixel of the source image with the closest matching color in the specified paletter.

The output image has 4 bpp or 8 bpp indexed pixel format depending on the target palette size - 4 bpp for palette size 16 or less; 8 bpp otherwise.

ReduceColors ( UnmanagedImage image, int paletteSize ) : Bitmap

Create an image with reduced number of colors.

The method creates an image, which looks similar to the specified image, but contains reduced number of colors. First, target color palette is calculated using CalculatePalette(UnmanagedImage, int) method and then a new image is created, where pixels from the given source image are substituted by best matching colors from calculated color table.

The output image has 4 bpp or 8 bpp indexed pixel format depending on the target palette size - 4 bpp for palette size 16 or less; 8 bpp otherwise.

Private Methods

Method Description
GetClosestColor ( int red, int green, int blue ) : int

Method Details

CalculatePalette() public method

Calculate reduced color palette for the specified image.

See CalculatePalette(UnmanagedImage, int) for details.

public CalculatePalette ( Bitmap image, int paletteSize ) : Color[]
image System.Drawing.Bitmap Image to calculate palette for.
paletteSize int Palette size to calculate.
return Color[]

CalculatePalette() public method

Calculate reduced color palette for the specified image.

The method processes the specified image and feeds color value of each pixel to the specified color quantization algorithm. Finally it returns color palette built by that algorithm.

Unsupported format of the source image - it must 24 or 32 bpp color image.
public CalculatePalette ( UnmanagedImage image, int paletteSize ) : Color[]
image AForge.Imaging.UnmanagedImage Image to calculate palette for.
paletteSize int Palette size to calculate.
return Color[]

ColorImageQuantizer() public method

Initializes a new instance of the ColorImageQuantizer class.
public ColorImageQuantizer ( IColorQuantizer quantizer ) : System
quantizer IColorQuantizer Color quantization algorithm to use for processing images.
return System

ReduceColors() public method

Create an image with reduced number of colors using the specified palette.

See ReduceColors(UnmanagedImage, Color[]) for details.

public ReduceColors ( Bitmap image, Color palette ) : Bitmap
image System.Drawing.Bitmap Source image to process.
palette Color Target color palette. Must contatin 2-256 colors.
return System.Drawing.Bitmap

ReduceColors() public method

Create an image with reduced number of colors.

See ReduceColors(UnmanagedImage, int) for details.

public ReduceColors ( Bitmap image, int paletteSize ) : Bitmap
image System.Drawing.Bitmap Source image to process.
paletteSize int Number of colors to get in the output image, [2, 256].
return System.Drawing.Bitmap

ReduceColors() public method

Create an image with reduced number of colors using the specified palette.

The method creates an image, which looks similar to the specified image, but contains reduced number of colors. Is substitutes every pixel of the source image with the closest matching color in the specified paletter.

The output image has 4 bpp or 8 bpp indexed pixel format depending on the target palette size - 4 bpp for palette size 16 or less; 8 bpp otherwise.

Unsupported format of the source image - it must 24 or 32 bpp color image. Invalid size of the target color palette.
public ReduceColors ( UnmanagedImage image, Color palette ) : Bitmap
image AForge.Imaging.UnmanagedImage Source image to process.
palette Color Target color palette. Must contatin 2-256 colors.
return System.Drawing.Bitmap

ReduceColors() public method

Create an image with reduced number of colors.

The method creates an image, which looks similar to the specified image, but contains reduced number of colors. First, target color palette is calculated using CalculatePalette(UnmanagedImage, int) method and then a new image is created, where pixels from the given source image are substituted by best matching colors from calculated color table.

The output image has 4 bpp or 8 bpp indexed pixel format depending on the target palette size - 4 bpp for palette size 16 or less; 8 bpp otherwise.

Unsupported format of the source image - it must 24 or 32 bpp color image. Invalid size of the target color palette.
public ReduceColors ( UnmanagedImage image, int paletteSize ) : Bitmap
image AForge.Imaging.UnmanagedImage Source image to process.
paletteSize int Number of colors to get in the output image, [2, 256].
return System.Drawing.Bitmap