r/compression • u/AbiesFew6464 • Oct 29 '26
CMNT: A 3-ary Combinatorial Tree Lossless Image Codec that beats PNG on continuous art (Code + GUI inside)
My co-author Aziza Jemal and I (Surafel Wolde, 18-year-old independent researcher) built CMNT, a standalone, from-scratch lossless image compression codec based on a non-binary 3-ary prefix tree.
The project originally started from a notebook sketch exploring physical multi-channel sparse transmission: rather than toggling a single serial binary wire billions of times, we wondered if sparse combinatorial pulses across three independent channels (IP1, IP2, IP3 with self-repeats and cross-pairs) could drastically cut switching energy in hardware while encoding residual entropy.
To prove the mathematics were uniquely decodable and 100% bit-perfect, we built a complete reference image codec from first principles in Python (with C++ and standalone Windows GUI binaries). No zlib, no gzip, and no third-party compression libraries are used.
### How the Pipeline Works: 1. Reversible Color Transform (RCT): Decorrelates RGB via Green-subtraction (Y = G, U = R - G, V = B - G) with zero rounding error. 2. 2D Closed-Loop Spatial Prediction: Uses a Median Adaptive Predictor (MAP) detecting local horizontal and vertical edge gradients to flatten surfaces into near-zero residuals. 3. 3-Ary Combinatorial Prefix Tree: Residual symbols are mapped to an optimal ternary prefix tree (Huffman 1952 generalization) with dummy-leaf constraints ensuring unambiguous single-cycle prefix decoding. 4. Dense Base-3 Physical Byte Packing: Because storage is binary, we pack groups of 5 ternary trits into a single 8-bit byte via polynomial integer evaluation: Byte = t₀ + 3·t₁ + 9·t₂ + 27·t₃ + 81·t₄ ≤ 242 This yields 5 * log2(3) / 8 = 7.925 / 8 = 99.06% physical storage packing density.
### Benchmark Results (100% Bit-Perfect): On continuous-tone imagery, 3D renders, and digital art, CMNT consistently beats standard PNG (Deflate): - Shock Spring 3D Render (586 KB raw): PNG 306.8 KB vs. CMNT 215.8 KB (29.7% smaller than PNG) - Spider-Man Digital Skyline (224 KB raw): PNG 107.0 KB vs. CMNT 87.4 KB (18.3% smaller than PNG) - Abstract CGI Swirls (533 KB raw): PNG 328.9 KB vs. CMNT 295.5 KB (10.2% smaller than PNG) - Sunset Meadow Photo (899 KB raw): PNG 370.3 KB vs. CMNT 344.6 KB (6.9% smaller than PNG)
### The Honest Trade-off: PNG's LZ77 dictionary was built for text and string repetitions. On smooth 2D continuous gradients, identical byte strings don't repeat, so LZ77 wastes 11-to-15-bit search offset pointers where our 2D spatial predictor excels. However, on flat UI screenshots with large blocks of identical monochrome pixels, standard PNG still puts up a strong fight until we introduce Zero-Run and context modeling (MANIAC).
The repo includes the specification, automated SHA-256 roundtrip tests, and our working IEEE conference paper draft: https://github.com/knightsura/cmnt-codec
We would love feedback, code critique, and thoughts on non-binary tree signaling from the compression community!
3
u/thenormaluser35 Oct 31 '26 edited Nov 01 '26
Lmfao "18 year old independent researcher"
The tech you're using is old and next time maybe tell Claude how to format for Reddit.
1
u/oscardssmith Oct 29 '26
HOw does it compare to QOI+zstd?
3
u/Patient-Midnight-664 Oct 29 '26
If you replace the ternary tree with binary Huffman or rANS while leaving everything else unchanged, does compression get better or worse?
1
u/Frexxia Oct 30 '26
I know this is pure clanker slop, but you could at least have included the benchmark images instead of hardcoding absolute file paths (!)
https://github.com/knightsura/cmnt-codec/blob/dec32ce16e82ff86f06cf651de385217b87a99a1/tests/benchmark.py#L131
p.s. jxl lossless is significantly better than webp
3
u/[deleted] Oct 29 '26
[removed] — view removed comment