Engineering & architecture

Ten modules, built from scratch

KARC (Kotsch Adaptive Region Codec) is implemented 100 % in Python — NumPy, OpenCV and Pillow, CPU-only, no GPU. Each of the ten modules is self-contained and covered by unit tests.

Architecture

The ten modules

The pipeline is split into ten clearly bounded areas. Each has a tightly defined job and its own tests — color transform bit-exact, DCT identical to OpenCV, rANS bit-exact, codec roundtrip loss-controlled.

Color transform

YCoCg-R: a losslessly reversible color transform plus 4:2:0 chroma subsampling. Tested bit-exact against OpenCV.

Segmentation & classification

Splits the image into 8×8 blocks and classifies each block by content — the basis of the region-as-representation idea.

Transform (DCT / PLANE)

Per block either an affine PLANE (3 parameters, smooth areas) or a DCT (detail) — selected via rate-distortion.

Quantization

Frequency-weighted quantization with JPEG-style tables — finer steps for visible, coarser for inconspicuous frequencies.

Learned models

Pre-computed tables for quantization and entropy, coupled to the region classes — no runtime training steps required.

Context & entropy

rANS entropy coding with class-conditioned tables. The region class is the context — zero extra signalling bits.

Rate control

Drives the target bitrate or quality level and balances the bits-versus-error trade-off per block.

Bitstream format

Defines the .karc container format: a header with magic “KARC”, image parameters and context-separated rANS substreams.

Integration

Wires all stages into encoder and decoder and guarantees the loss-controlled roundtrip image → .karc → image.

Evaluation & tests

Benchmark harness (BD-rate, PSNR, SSIM) on 20 Kodak images plus unit tests for every module — all numbers reproducible.

Foundation

Tech stack

Deliberately lean and reproducible: pure Python, established numerics libraries and no GPU dependency whatsoever. KARC runs on any CPU.

Python 3 NumPy OpenCV Pillow CPU-only no GPU

By Arthur Kotsch with Claude (2026). Built from 30 research sources, a multi-agent design (111 agents) and a from-scratch implementation in ten modules.

Format

The .karc bitstream format

A .karc file starts with a compact header for identification (magic “KARC”) and geometry/parameters. The payload then follows as several context-separated rANS substreams — so each stream can be decoded with the table matching its region class.

// .karc container (schematic)
"KARC" // magic bytes — format identifier
version // version byte
width, height // image geometry
quant_profile // quantization / quality profile
// — context-separated rANS substreams —
stream[PLANE] // smooth regions
stream[DCT] // detail regions
stream[DC / AC] // DC-DPCM + AC run-lengths

Schematic representation. Separating by context enables class-conditioned rANS tables without extra signalling bits in the stream.