-
Notifications
You must be signed in to change notification settings - Fork 36
Quantization
The viewer supports 4 different methods of image colour quantization. These methods are implemented in the Tacent library that Tacent View is backed by. Quantization is the process of selecting a subset of colours (N) from a space of colours (K) where N < K. Basically an attempt to create a good palette. This is a hard problem as it relates to human perception and how the human eye responds to different frequencies. The 4 algorithms in use by Tacent are:
- Fixed. This is only here for completeness. It is simply a fixed palette. It is not adaptive since it does not attempt to inspect the image pixels to generate the best palette.
- NeuQuant. This is a high quality quantizer that uses a neural net (Anthony Dekker, 1994). It works best on higher numbers of palette colours.
- Scolorq/Spatial. This is a slow but very high quality quantizer when choosing a small number of colours. This is the best choice when quantizing to 32 colours or fewer. It has dithering built-in giving it an advantage for fewer colours. (Derrick Coetzee, 2006).
- Wu. Another high-quality quantiler for larger colour sets (128 and larger). Greedy orthogonal bipartition of RGB space. this algorithm is both fast and gives good results (Xiaolin Wu, 1995).
Overall I'm really surprised how much fidelity you get with these algorithms, sometimes at very low palette sizes. Who needs 4 billion colours! Below are some tests quantizing the same source image using the different methods. Fixed (non-adaptive) will always produce inferior results since it doesn't inspect the image pixels.
Original Image |
---|
The next 4 images are the results of quantizing to 256 colours (the maximum palette size for the quantizers). Neu and Wu both did a great job. Wu looks like it spead the blue banding out a bit more, while Neu has a smoother gradient except where the sky gets brighter. It is unclear to me which one looks better. SColorQ produced the most banding (of the 3 adaptive methods) and took a really (really) long time to run.
Neu Quant 256 Colour | Wu 256 Colour |
---|---|
SColorQ 256 Colour | Fixed 256 Colour |
---|---|
The story changes a bit when we reduce the number colours to 32. Below you can see SColorQ producing the best results, although Wu still does a really good job.
Neu Quant 32 Colour | Wu 32 Colour |
---|---|
SColorQ 32 Colour | Fixed 32 Colour |
---|---|
The following 4 animated pngs show how the different algorithms converge over the first 100 colours. They all start at 2 colours and end at 100. Animations are running at 10 FPS with a 3 second pause on the first and last frame. On the final frame SColorQ is still producing better results than both Neu and Wu, however it's very slow -- you get to choose between quality and speed up to ~200 colours -- at least with this test image. After that mark Wu looks, to me, like it pulls ahead (unfortunately a 256-colour progression produced filesizes too big for the wiki).
Neu Quant Progression | Wu Progression |
---|---|
SColorQ Progression | Fixed Progression |
---|---|
Tacent View is a fast immediate-mode GUI texture and image viewer.