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, typically for efficient file format compression such as GIF.
  • 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:
  • Dithering Truewhether to use dithering
    Method Automaticquantization 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:

Wolfram Research (2008), ColorQuantize, Wolfram Language function, https://reference.wolfram.com/language/ref/ColorQuantize.html (updated 2019).

Text

Wolfram Research (2008), ColorQuantize, Wolfram Language function, https://reference.wolfram.com/language/ref/ColorQuantize.html (updated 2019).

CMS

Wolfram Language. 2008. "ColorQuantize." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2019. https://reference.wolfram.com/language/ref/ColorQuantize.html.

APA

Wolfram Language. (2008). ColorQuantize. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ColorQuantize.html

BibTeX

@misc{reference.wolfram_2023_colorquantize, author="Wolfram Research", title="{ColorQuantize}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/ColorQuantize.html}", note=[Accessed: 28-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_colorquantize, organization={Wolfram Research}, title={ColorQuantize}, year={2019}, url={https://reference.wolfram.com/language/ref/ColorQuantize.html}, note=[Accessed: 28-March-2024 ]}