ColorQuantize

ColorQuantize[image]

gives an approximation to image by quantizing to distinct colors.

ColorQuantize[image,n]

uses at most n distinct colors.

ColorQuantize[image,{col1,,coln}]

represents an image using only the n specified colors coli.

Details and Options

  • Color quantization is the process of reducing the number of colors used to represent an image.
  • ColorQuantize works with arbitrary 2D and 3D images.
  • Quantization for color images is performed in the original color space. For images with Automatic color space, quantization is performed on pixel intensities by averaging over all channels.
  • The following options can be given:
  • DitheringTruewhether to use dithering
    MethodAutomaticquantization method to use
  • Possible settings for Method include:
  • "MedianCut"recursively split the color space based on median pixel values
    "MinVariance"recursively split the color space so that the sum of variances in new subregions is minimal (Wu's algorithm)
    "Octree"create an octree from all image pixels and merge leaves until the n most representative remain

Examples

open allclose all

Basic Examples  (1)

Quantize an image:

Quantize to four colors:

Quantize using a specific list of colors:

Scope  (2)

Quantize a grayscale image:

Five discrete color values in a 3D image:

Options  (4)

Dithering  (2)

By default, a quantized image is created with some dithering:

Turn off the dithering:

Quantizing a 3D image with dithering:

No dithering:

Method  (2)

Compare three different methods:

Comparison of three different methods using different numbers of colors:

Applications  (5)

Create a binary image with dithering:

Create a duotone image:

Create a quantized version of an image:

Use more colors for better representation of the original image:

Create a posterization effect:

Create an effect by quantizing the colors and highlighting the edges:

Properties & Relations  (3)

Quantize the colors using the "Posterization" effect:

This is equivalent to quantizing each color channel individually:

Colors in the quantized image are also typically dominant colors of the image:

Compare with DominantColors:

Quantize an image using dominant colors given by DominantColors:

Quantize using the same number of colors, using all colors present in the image:

Possible Issues  (1)

For images with Automatic color space, quantization is performed on pixel intensities by averaging over all channels:

Check the color space and number of channels of the result:

Introduced in 2008
 (7.0)
 |
Updated in 2012
 (9.0)
2017
 (11.2)
2019
 (12.0)