Interactive post

Fractal Compression

A fixed-point view of image compression, plus a browser demo that searches for domain and range block mappings and reconstructs the image by repeated iteration.

A self-contained interactive article in the site blog, with the full demo code living alongside the post.

Background

For the math, it is easiest to think about a single intensity channel modeled as a vector \(x \in [0, 1]^n\) with \(n = H \times W\), and to write \(\mathcal{I} = [0, 1]^n\) for the image space. A transform \(f : \mathcal{I} \to \mathcal{I}\) is a contraction when \(|f(x) - f(y)| \leq k |x - y|\) for some \(k < 1\). The Banach fixed-point theorem then guarantees a unique fixed point \(x^* \in \mathcal{I}\) satisfying \(f(x^*) = x^*\).

Once a contraction is found, iterating it from any seed image converges back to the same fixed point:

$$x_{t + 1} = f(x_t), \qquad f(x^*) = x^*, \qquad \lim_{t \to \infty} x_t = x^*.$$

Fractal compression tries to find a contraction whose fixed point approximates the target image closely enough that storing the parameters of \(f\) is cheaper than storing the pixels directly. In the block-based variant used here, the smaller target patches are range blocks and the larger source patches are domain blocks. In the RGB demo below, the block geometry is chosen from luminance and then separate affine fits are stored for the red, green, and blue channels.

Block mapping from a coarse 2x2 domain to a fine 4x4 range
The highlighted domain block is contracted onto a highlighted range block, which is the local building block of the global mapping.

The key idea is to search, for each range block, over many candidate domain blocks together with simple transformations. If every local mapping is contractive, the global system has a well-defined fixed point, and decompression becomes an iteration toward that fixed point rather than a direct pixel copy.

Implementation

This demo works on \(512 \times 512\) RGB images. For every \(4 \times 4\) range block, it inspects every candidate \(8 \times 8\) domain block, downsamples it, and evaluates the eight planar symmetries so that rotated and reflected variants are also available.

To keep compression practical, the search for the best domain block and symmetry is performed on luminance. Once that shared geometric mapping is chosen, the demo solves three tiny least-squares problems, one for each of the red, green, and blue channels, fitting a contrast \(c\) and offset \(d\) for each channel separately.

During decompression, the same domain-to-range geometry is applied to all three channels while the per-channel affine parameters restore color. Starting from random RGB noise, repeated application of the mapping converges toward the stored fixed point.

Demo

Choose an image, compress it into an RGB block mapping, and then iterate the decompressor from random color noise.

Compress

Original preview

Decompress

Iter 0 PSNR -