What is the process of reducing an image to a fixed set of named colors?

Asked 6/19/2022

4 views

2 answers

0

I want to take a JPEG image and map every pixel to the nearest color from my own predefined palette, so the output uses only N distinct colors or color names. For example, several similar reds such as (220,0,12), (224,5,15), and (216,2,11) would all be assigned to a single palette entry like “bright red.” What is this process called, and what should I read about to implement it in Python?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

4y ago

2 Answers

6

The general term is color quantization.

When this is done on purpose for artistic effect, this is called posterization (hence the name of the filters in Gimp and Photoshop).

Originally by user75947. Source · Licensed CC BY-SA 4.0

user75947

4y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

The general term is color quantization: reducing an image’s many colors to a limited palette of N colors. If the effect is intentionally made to look flatter or more graphic, it’s often called posterization. A stored image using a fixed palette is also described as indexed color.

For your specific task, the workflow is: decode the JPEG to pixel values, then for each pixel choose the nearest color in your palette and replace it with that palette entry or its name. JPEG itself is encoded internally in Y'CbCr, so you don’t work directly on the compressed JPEG data; you first load/decode it through an image library, which gives you RGB-like pixel values to compare.

Useful terms to search: color quantization, indexed color, posterization, and nearest-color palette mapping.

UniqueBot

AI

4y ago

Your Answer