Palette Programming:
A Modern Guide to Color Quantization

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

Interested in retro computer graphics? How about machine learning on the side? Here’s a book that combines the two.

Palette Programming explains how to represent images using small color palettes. It’s an old computer graphics problem, but an educational one since it involves recursive algorithms, statistics, and color science.

If that sounds interesting and you are ready to take on a challenging Python programming project, then this book is for you.

You will learn about technical subjects such as:

  • top-down hierarchical clustering,
  • the k-means algorithm,
  • color dithering,
  • statistical variance, and
  • perceptual color spaces.

Still, it’s a practical book. There is some theory, but only what you need to understand the code.

This is not an academic reference work but an illustrated guide with real code.

The book will be published in 2026, first as a digital edition, followed by a printed physical version. The digital format is a PDF in both full-size and smaller e-reader form factors.

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. Unsubscribe any time.

How it’s structured

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

The book cover!
Release date 2026 (planned)
Format A5, full-color, 250 pp.
Ring-bound softcover, PDF, e-reader PDF.
Level Intermediate
Supplements Online code examples

Introduction

Part 1: Setting the Baseline

  • Image Processing in Python (PDF)
  • 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

The subject matter is visual, and so is the book. Carefully designed diagrams and graphs are included in each chapter to clarify the concepts or show example results. The code samples are presented a few lines at a time, interleaved with explanations. It looks like this:

An example spread from the book showing an illustration of a paletted Mona Lisa painting and some Python code snippets interleaved with prose.

From the author

Hello! My name is Pekka Väänänen and I’m a software engineer and a writer. This book started in spring 2025 with a broader graphics theme, but when working on a Nintendo 64 lighting experiment, I became obsessed with the color quantization problem. A lot of what I learned from reading open source code such as libimagequant and exoquant.c wasn’t mentioned in any textbook. I then initiated excavations in the academic literature, and discovered remains of even more techniques unknown to the general public. That’s how the book concept started to form.

I love programming and started trying out different color quantization algorithms myself, building the experimental VariQuant GUI tool in the process. Numerical programming has been my hobby since 2013 when I participated in Andrew Ng’s popular Machine Learning online course. That’s why the code in the book is in Python: it’s the standard tool in this field.

But why should anyone study this old stuff? Didn’t we evolve beyond 256-color GIFs for a reason? Sure, display technology has improved, but I sincerely believe we should use old computers for longer. Producing electronics takes a lot of energy and natural resources. Both are something we should conserve.

Real progress involves learning new ways to do old things better, and not just relying on hardware advances for new capabilities. I hope by popularizing the art of color quantization I’ll encourage others to work on better tooling for retro platforms, which should lead to a higher appreciation of aging hardware. The same techniques can also be applied in modern software, for example to optimize image sizes on the web to lower data transmission costs.

About me in third person

Pekka R. H. Väänänen (M.Sc. computer science) is a software engineer who writes about computer graphics on his website at 30fps.net. 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 Pekka on Mastodon, Bluesky, YouTube, and his website,




© 2025–2026 Pekka Väänänen