ColorQuantize

ColorQuantize[image,n]

gives an approximation to image that 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  (3)

Approximate a true color image with 5 discrete color values:

In[3]:=
Click for copyable input
Out[3]=

Quantize to the four dominant colors:

In[1]:=
Click for copyable input
Out[1]=

Quantize using a specific list of colors:

In[2]:=
Click for copyable input
Out[2]=

Five discrete color values in a 3D image:

In[1]:=
Click for copyable input
Out[1]=

Options  (4)

Applications  (4)

Properties & Relations  (2)

Possible Issues  (1)

See Also

DominantColors  ImageLevels  Binarize  ColorSeparate  ImageAdjust  ImageEffect  ImageType  FindClusters

Tutorials

Introduced in 2008
(7.0)
| Updated in 2017
(11.2)