Core Concepts
Understanding these concepts will help you get the best results from Img2Num.
Color Spaces
Img2Num supports two color spaces for k-means clustering:
| Space | ID | Description | Use when… |
|---|---|---|---|
| CIE LAB | 0 | Perceptually uniform — distances match human color perception. | Accurate color matching matters more than speed. |
| sRGB | 1 | Faster computation in the native display space. | You need speed and color accuracy is secondary. |
Bilateral Filtering
The bilateral filter applies two Gaussian kernels:
Spatial Kernel
Typical value: 3
(sigma_spatial) is the parameter that controls neighbor pixel smoothing in the image plane.
Neighbors are pixels that are close to each other.
Range Kernel
Typical value: 50
(sigma_range) is the parameter that controls smoothing of pixels with similar intensity values.
For example, a pixel with value rgba(213,13,67) and another with rgba(195,17,87) may be considered similar
and get smoothed together.
K-Means Clustering
K-means groups pixels into k clusters based on color distance in the chosen color space.
k(num_colors): How many colors the output should contain.max_iter: Maximum iterations allowed before forcing termination.
k and max_iter are not guarantees.
kcannot force new colors: if the image only has2colors and , the image cannot gain more color.max_iteris an upper limit only: if and it only takes50iterations to cluster the image, the function will return early (before the 999th iteration).
kLarger images benefit from more colors (k), but too many will produce noisy contours.