Palette Programming:
A Modern Guide to Color Quantization

by Pekka R. H. Väänänen

Do you want to learn retro computer graphics? Are you also interested in machine learning or numerical programming? I’m writing a book just for you.

This textbook explains how to represent images using small color palettes. It’s an old computer graphics problem, and we apply lessons from statistics, computer science, and human biology to solve it.

For the first time, both the classic 90’s techniques and later developments are discussed and logically connected in the same book. Python code for all algorithms are included and published online for free.

The subjects include the median cut algorithm, k-means clustering and its variants, dithering, perceptual color spaces, plus derivations for some formulas not explained anywhere else. There’s also a guide to the NumPy library.

The book will be published in 2026 first as a digital edition PDF (including a smaller version for e-readers) followed by a self-published print edition.

Updates on the book

Are you interested in news on Palette Programming such as new sample chapters? Then subscribe to the book newsletter below.

Updates at most once per month. You can unsubscribe any time.

The book cover!
Release date 2026 (planned)
Format 200 pages, full-color,
ring-bound softcover, PDF, e-reader PDF.
Level Intermediate
Supplements Online code examples

Introduction

Part 1: Setting the Baseline

  • Image Processing in Python
  • The Trivial Median Cut
  • Refinement with K-means
  • Cut by Variance
  • Simple Ordered Dithering
  • Real-World Software Investigation

Part 2: Practical Improvements

  • Histograms & Bit Cuts
  • Ordered Dither Color Selection
  • Error Diffusion Dithering
  • Pixel Mapping Tricks
  • How to Deal with Transparency
  • On Usefulness of Perceptual Color Spaces

Part 3: Theoretical Advances

  • MSE vs SSIMULACRA
  • Optimized Variance Calculations
  • Locally Optimal Cuts
  • Wu’s Famous 1991 Technique
  • Going All In on K-Means
  • PSOATCQ is SOTA

This textbook is written in an accessible style (see the sample chapter) that grounds all theory in practical examples. While I assume a couple of years of programming experience and a reader brave enough to face an equation every once in a while, this is not aimed at experts. Instead, I try to serve readers who want to try out the methods themselves in practice.

The first third of the book is a step-by-step guide to writing a “baseline” algorithm that’s both simple and effective. I think it’s great project for anyone interested in developing their skill as a programmer. The rest of the book introduces both practical tricks and theoretical concepts to improve the results, but don’t culminate in a single program like in the beginning.

Why I am writing this book

First of all, I enjoy studying technical subjects in detail and explaining them as clearly as I can. I’ve been publishing such writing on my website at 30fps.net. My interests tend to gravitate towards retro computing so that’s what I’ve been writing about.

Back in 2013 I participated in Andrew Ng’s popular Machine Learning online course, and been playing with numerical programming ever since. That’s why the code in the book is in Python: it’s the standard machine learning tool. So in a way I’m writing a textbook on how to use modern tools to do retro graphics. It also happens to be my hobby.

But why should anyone study this old stuff? Didn’t we evolve beyond 256-color MS-DOS times for a reason? Sure, display technology has improved, but I sincerely believe we should use old computers for longer before they get declared e-waste and shipped to the other side of the globe for dismantling.

Real progress involves learning new ways to do old things better; not just relying on hardware advances for new capabilities. And when it comes color quantization, reconstructing images with limited palettes, there have been new developments that nobody talks about. I’ll be first to admit that the new techniques don’t always result better visual quality but they are simpler, either technically or conceptually. This makes them easier to apply, which I hope will lead to better art tooling for retro platforms, and thus to higher appreciation of aging hardware.

About me in third person

Pekka R. H. Väänänen is a software engineer and a writer. He has worked on 3D geometry optimization and robot simulations at Umbra Software, and with 3D reconstruction and VR headset tracking at Varjo. He also hacked on 2D graphics drivers when he was an intern at NVIDIA, a long time ago.

You can also find me on my website, Mastodon, Bluesky, and YouTube.



© 2025-2026 Pekka Väänänen