Click or drag to resize
Accord.NET (logo)

ColorImageQuantizerReduceColors Method (UnmanagedImage, Int32)

Create an image with reduced number of colors.

Namespace:  Accord.Imaging.ColorReduction
Assembly:  Accord.Imaging (in Accord.Imaging.dll) Version: 3.8.0
Syntax
public Bitmap ReduceColors(
	UnmanagedImage image,
	int paletteSize
)
Request Example View Source

Parameters

image
Type: Accord.ImagingUnmanagedImage
Source image to process.
paletteSize
Type: SystemInt32
Number of colors to get in the output image, [2, 256].

Return Value

Type: Bitmap
Returns image with reduced number of colors.
Exceptions
ExceptionCondition
UnsupportedImageFormatExceptionUnsupported format of the source image - it must 24 or 32 bpp color image.
ArgumentExceptionInvalid size of the target color palette.
Remarks

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, Int32) 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.

Note Note
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.

See Also