r/compression • u/AbiesFew6464 • 28d ago
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!
1
u/oscardssmith 28d ago
HOw does it compare to QOI+zstd?
1
u/AbiesFew6464 28d ago
We actually benchmarked this directly against QOI and QOI+zstd. On continuous-tone 3D renders (585 KB raw), CMNT + MANIAC produces a 215.8 KB file, outperforming QOI+zstd (294.3 KB) by 26.7% (saving 78.5 KB) and beating standard PNG (306.8 KB) by 29.7%.
Here is why QOI + zstd cannot compete with a dedicated 2D predictive tree:
3
u/Patient-Midnight-664 28d ago
If you replace the ternary tree with binary Huffman or rANS while leaving everything else unchanged, does compression get better or worse?
3
28d ago
[removed] — view removed comment
2
28d ago
[removed] — view removed comment
1
u/AbiesFew6464 28d ago
really how??
3
28d ago
[removed] — view removed comment
0
u/AbiesFew6464 28d ago
ik sir am highschool graduate trying to join university but i get u and to solve both our problem what if we build custom hardware that treats numbers additional to 0 and 1
1
u/AbiesFew6464 28d ago
We actually benchmarked this directly against QOI and QOI+zstd. On continuous-tone 3D renders (585 KB raw), CMNT + MANIAC produces a 215.8 KB file, outperforming QOI+zstd (294.3 KB) by 26.7% (saving 78.5 KB) and beating standard PNG (306.8 KB) by 29.7%.
Here is why QOI + zstd cannot compete with a dedicated 2D predictive tree:
3
u/thenormaluser35 27d ago edited 26d ago
Lmfao "18 year old independent researcher"
The tech you're using is old and next time maybe tell Claude how to format for Reddit.