color-quantization
Color quantization zoo.
This is a repository for exploring various color quantization methods. Algorithm implementations are in src/
, with great help from numpy
.
Table of Contents
- Otsu's Method
- Median Cut
- Kmeans++
- Octree
- Floyd-Steinberg Dithering
Otsu's method - binarization
Otsu's method is an algorithm for color binarization. See src/otsu/
.
Colored | Otsu's method | Median threshold |
---|---|---|
Median cut - quantization
Median cut is an algorithm for color quantization of images into 2n colors. See src/median_cut/
.
Original | 2 color |
---|---|
4 color | 8 color |
16 color | 32 color |
64 color | 128 color |
K-means++ - quantization
K-means++ is an improved K-means algorithm with better initialization. Initializing with sparser centroids (though more computationally expensive) can lead to faster convergence. Note that this algorithm can quantize an image to arbitrary number of colors. See src/kmeans/
.
Original | 2 color |
---|---|
3 color | 5 color |
10 color | 20 color |
50 color | 100 color |
Octree - quantization
Octrees are trees which each node has (at most) eight children. It is an effective data structure for partitioning 3-dimensional spaces. A great post on octree implementations (in JavaScript) for color quantization can be found here.
Floyd-Steinberg Dithering
Dither is an intentionally applied form of noise used to randomize quantization error, preventing large-scale patterns such as color banding in images. See src/dithering/
.
Original | 64-colored | Dithered |
---|---|---|