Variance Image Quantizer

A C# RGBA quantizer that uses four-dimensional cumulative moments and variance-driven box splitting, then evaluates the actual encoded PNG size during iterative palette reduction.

This project treats palette reduction and encoded file size as related but not identical objectives. RGBA samples are accumulated in a fixed 33×33×33×33 histogram. Weight, channel sums and second moments are converted to cumulative moments, allowing statistics for a colour box to be queried without rescanning every pixel assigned to that region.

Palette construction repeatedly splits the boxes that carry the most variance. The resulting indices can be packed into 1-, 4- or 8-bit indexed output. A separate outer decision looks at the bytes produced by the PNG encoder: another reduction is accepted only while the actual encoded representation continues to improve. That prevents “fewer colours” from being used as a proxy for “smaller file” when compression behaviour says otherwise.

The repository explicitly records the provenance of the Wu/nQuant.NET-style quantization core. Its contribution is framed around the RGBA adaptation and the encoded-size optimisation workflow rather than presenting an established algorithm as a new invention. For similarity search rather than palette optimisation, DCT Perceptual Hash provides a distinct representation.

Background article: Variance-Based Color Quantization Code: GitHub Zenodo archive: Zenodo DOI: DOI

QR code for this page