Interactive laboratory · Algebra and dynamical systems

Baker’s transformation

Stretch, compress and reassemble an image: watch the mixing step by step

Read the introductory article →

Dough made of pixels

Imagine stretching dough, folding it and repeating. The baker’s transformation does something similar to the points of a square. Start with the four colored quadrants on the 8×8 grid, press “1 forward iteration” and watch what changes; then increase the resolution to see the mixing in finer detail.

Try the transformation

Choose a demo image or upload your own. The default is four quadrants on an 8×8 grid.

Demo images

The image is cropped centrally if not square and adapted to the chosen grid. At the end of the cycle it returns exactly to this gridded version, not to the full-resolution original file. Your file stays in your browser and is not sent to the server. Up to 32 iterations are kept.

Starting image

Click the image to follow a point.

Transformed

“Run N iterations” computes all selected steps immediately. Every intermediate image appears in the gallery below, where you can open it individually. “1 inverse iteration” runs the map backwards.

Starting image0

All transformed images

Each thumbnail is an actual computed state. Select one to revisit it and continue from there. The six panels below explain just one step.

How it works

The six panels explain the stages of just one iteration: they are not six iterations and do not show the return to the starting image. The first five are schematic; the sixth is the exact result of the first step on the chosen grid. Use the lab button to see the return.

The schematic drawing illustrates the continuous map. On a finite grid we use a pixel permutation: it keeps N×N cells and neither invents nor removes colors after the initial crop.

Orbit of a point

Click the original image to see the point’s coordinates after every computed iteration and a schematic path in the square. The point follows the continuous formula, not the permutation of pixel centers.

No point selected.

    Why does it mix?

    What it is and why it has this name

    This transformation of a square resembles a baker’s action: stretching dough, compressing it and stacking the parts. Repeated many times, a region that was initially compact is distributed into ever thinner strips.

    Stretching, compression and area

    Each half is stretched horizontally by a factor of 2 and compressed vertically by a factor of 1/2. The product of these factors is 1, so the continuous map preserves area. The halves fill the upper and lower parts of the square without overlap.

    Deterministic chaos

    The rule uses no randomness: every point has a precisely determined next position. Nevertheless, two points with very close initial x coordinates can separate quickly, because their horizontal distance doubles until folding intervenes. This is sensitivity to initial conditions.

    Binary digits and the Bernoulli shift

    If x is written in base 2 as 0.b₁b₂b₃…, multiplying by 2 and removing any integer part produces 0.b₂b₃…: a binary shift, or Bernoulli shift. The first digit b₁ determines whether the point enters the upper or lower band and is recorded in the y coordinate.

    A finite grid is not a continuum

    A digital image contains finitely many pixels. Our discrete version is a reversible permutation: it preserves every pixel and must eventually revisit a previous state. Visual mixing is instructive, but it is neither encryption nor genuine randomness.

    The mathematical rule

    B(x,y) = (2x, y/2)   if x < 1/2

    B(x,y) = (2x−1, (y+1)/2)   if x ≥ 1/2

    Example: applying the rule to (0.3, 0.4) three times gives:

    (0.3, 0.4) → (0.6, 0.2) → (0.2, 0.6) → (0.4, 0.3)