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.

10self-contained modules, all unit-tested
100 %Python — NumPy, OpenCV, Pillow
0GPU dependencies, runs on any CPU
8×8block size in which every region picks its representation

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.

01

Color transform

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

02

Segmentation & classification

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

03

Transform (DCT / PLANE)

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

04

Quantization

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

05

Learned models

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

06

Context & entropy

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

07

Rate control

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

08

Bitstream format

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

09

Integration

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

10

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

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.

container.karc — schematic
// .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

Try the codec yourself

Upload your own image and measure KARC against JPEG.