In computer graphics, color quantization or color image quantization is quantization applied to color spaces; it is a process that reduces the number of distinct colors used in an image, usually with the intention that the new image should be as visually similar as possible to the original image. Computer algorithms to perform color quantization on bitmaps have been studied since the 1970s. Color quantization is critical for displaying images with many colors on devices that can only display a limited number of colors, usually due to memory limitations, and enables efficient compression of certain types of images. The name "color quantization" is primarily used in computer graphics research literature; in applications, terms such as optimized palette generation, optimal palette generation, or decreasing color depth are used. Some of these are misleading, as the palettes generated by standard algorithms are not necessarily the best possible.
Background Color quantization involves the generation of an indexed-color image and a palette chosen to maximize the visual similarity to the original image. In many cases it boils down to selecting a good palette followed by mapping the image onto the palette. If the palette is fixed, as is often the case in real-time color quantization systems such as those used in operating systems, the action may instead be called indexed color conversion, posterization, or palette mapping. This is usually done using the "straight-line distance" or "nearest color" algorithm, which simply takes each color in the original image and finds the closest palette entry, where distance is determined by the distance between the two corresponding points in three-dimensional space. In other words, if the colors are (r1,g1,b1) and (r2,g2,b2), we want to minimize the Euclidean distance:
(r1−r2)2+(g1−g2)2+(b1−b2)2. This effectively decomposes the color cube into a Voronoi diagram, where the palette entries are the points and a cell contains all colors mapping to a single palette entry. There are efficient algorithms from computational geometry for computing Voronoi diagrams and determining which region a given point falls in; in practice, indexed palettes are so small that these are usually overkill. (This principle could be applied to any other color space such as Lab.)
Algorithms Most standard techniques treat color quantization as a problem of clustering points in three-dimensional space, where the points represent colors found in the original image and the three axes represent the three color channels. Almost any three-dimensional clustering algorithm can be applied to color quantization, and vice versa. After the clusters are located, typically the points in each cluster are averaged to obtain the representative color that all colors in that cluster are mapped to. The three color channels are usually red, green, and blue, but another popular choice is the Lab color space, in which Euclidean distance is more consistent with perceptual difference. Color quantization is frequently combined with dithering, which can eliminate unpleasant artifacts such as banding that appear when quantizing smooth gradients and give the appearance of a larger number of colors. Some modern schemes for color quantization attempt to combine palette selection with dithering in one stage, rather than perform them independently.
Median cut The most popular algorithm by far for color quantization, developed by Paul Heckbert in his 1980 Bachelor's thesis and later published in a 1982 journal paper, is the median cut algorithm.
Many variations on this scheme are in use. Before this time, most color quantization was done using the population algorithm or population method, which essentially constructs a histogram of equal-sized ranges and assigns colors to the ranges containing the most points. A more modern popular method is clustering using octrees, first conceived by Gervautz and Purgathofer and improved by Xerox PARC researcher Dan Bloomberg.
K-means The Local K-means algorithm, conceived by Oleg Verevka in 1995, is designed for use in windowing systems where a core set of "reserved colors" is fixed for use by the system and many images with different color schemes might be displayed simultaneously. It is a post-clustering scheme that makes an initial guess at the palette and then iteratively refines it. In the early days of color quantization, the k-means clustering algorithm was deemed unsuitable because of its high computational requirements and sensitivity to initialization. In 2011, M. Emre Celebi reinvestigated the performance of k-means as a color quantizer. He demonstrated that an efficient implementation of k-means outperforms a large number of color quantization methods.
Other methods A number of other much less frequently used methods have been invented that use fairly different approaches. The high-quality but slow NeuQuant algorithm reduces images to 256 colors by training a self-organizing map (SOM) "which self-organises through learning to match the distribution of colours in an input image. Taking the position in RGB-space of each neuron gives a high-quality colour map in which adjacent colours are similar." It is particularly advantageous for images with gradients. (The SOM acts as a neural network that performs data clustering.)
Spatial color quantization (scolorq) by Puzicha, Held, Ketterer, Buhmann, and Fellner of the University of Bonn solves the joint problem of color quantization (palette generation followed by indexed color conversion) and dithering. It uses a simplified model of human perception to guide the error-compensating dithering (which is different from error diffusion in that compensations stay local). Due to the of dithering, it does not treat palette selection purely as a clustering problem, in that the colors of nearby pixels in the original image also affect the color of a pixel. It is obviously advantageous only for small color counts (up to 16). See sample images.
… excerpt ends here. Continue reading the full article.





