Skip to main content
BVDART Logo
← All guidesDithering & palettes

Color quantization

Color quantization replaces a large set of input colors with a smaller palette. The palette and assignment method determine what detail and relationships survive.

Separate a print poster into a few inks

DUNE · the original printclick · arrow keys

Start with four chosen print inks: paper, pine, sage and terracotta. Pick a pixel to inspect its assignment, then edit an ink or extract a new palette size.

Every pixel chooses a representative4 palette colors
Image assigned to the editable palette
Edit a representative

Changing one swatch can move many assignment boundaries at once. No spatial dithering is applied, so the palette decision stays visible.

Nearest in encoded RGB · 239, 146, 60
165.9
210.4
117.8
36.6 ←
Selected representative4 · #e07137
Channel RMSE (0–255)18.16

Nearest means smallest Euclidean RGB distance here. This is an assignment demonstration, not a claim that RGB distance is perceptually uniform or that the browser exported an indexed file.

Change one poster ink while holding the sampled pixel; nearest-color assignments and distances update together. Use any control to take over.

What to try
  1. Inspect the sunset, pale paper or dark lettering and compare distances to the editable ink palette.
  2. Edit a palette color, then reduce the extracted palette size.
Open in the Lab ↗

What to look for: The nearest RGB representative wins. One changed swatch can reassign many pixels; the counts and channel error measure that change.

How it works

Median-cut repeatedly divides a sampled color population into boxes and chooses representatives. Popularity favors frequent colors. A uniform palette samples a regular color grid. Each answers a different question: represent the distribution, keep the most common colors, or impose a fixed structure.

After choosing a palette, each pixel is assigned a representative. Error diffusion can distribute the mismatch to later pixels, exchanging flat banding for spatial texture. Posterization is different: it reduces levels independently in each channel rather than choosing a total image palette.

Use it in the Lab

Use Indexed palette for a limited image palette and Posterize for discrete channel levels. Judge important accents and small details as well as average similarity. Quantization can follow a color adjustment to emphasize the values you want the palette to preserve.

Limits & distinctions

The rendered Lab layer remains RGBA even when its colors are quantized. Its PNG export is not promised to use an indexed PNG encoding.

Further reading

Reducing the Palette

[ LOADING VIS ]
Before/after indexed palette conversion

Color quantization reduces a full-color image (up to 16,777,216 colors) to a small palette — typically 2 to 256 colors. The challenge lies in choosing which colors to keep and how to map every original color to its nearest palette entry.

Algorithms

[ LOADING VIS ]
Error distribution with dithering tradeoff

Quantization Methods

Median-cut: splits color space along longest axis recursively. Fast and produces good results. K-means: iteratively refines cluster centers. Slower but more accurate. Octree: uses a tree data structure. Memory-efficient, good for real-time. Neu-quant: neural network approach. Best quality, slowest.

median-cut.ts
// Median-cut quantization (simplified)
function medianCut(colors: RGB[], depth: number): RGB[] {
  if (depth === 0) return [average(colors)];
  const axis = longestAxis(colors); // R, G, or B
  colors.sort((a, b) => a[axis] - b[axis]);
  const mid = Math.floor(colors.length / 2);
  return [
    ...medianCut(colors.slice(0, mid), depth - 1),
    ...medianCut(colors.slice(mid), depth - 1),
  ];
}
typescript

The Aesthetic Power of Constraint

[ LOADING VIS ]
Intentional palette constraints as a stylistic choice

Combined with dithering, quantization becomes a powerful aesthetic tool. The restricted palette creates a distinctive retro look — evoking CGA, EGA, and Game Boy eras — while dithering recovers the illusion of smooth gradients. The tension between limited means and rich results is central to the BVDART aesthetic.

For best results, quantize in a perceptually uniform color space like OKLCH rather than RGB. This ensures the selected palette colors are maximally distinguishable to the human eye.

Articles

Related artworks

Related Lab categories

Sources & references

Guide updated