In 1952, in The Chemical Basis of Morphogenesis, Alan Turing proposed a mechanism for how structure can emerge spontaneously in a developing embryo, the same math later used to explain skin patterns
. If you have two chemicals which react with each other while diffusing at different rates (an activator that amplifies itself while spreading slowly, and an inhibitor that suppresses it while spreading fast), a uniform mixture will spontaneously break into spots or stripes. Turns out that with an image, if you blur a little, sharpen a lot, and repeat a bunch of times, you can generate these patterns.
Images as waves
A grayscale image can be written as a sum of overlapping waves. This is Fourier's theorem. In an image of random noise, you have waves of every size in roughly equal amounts.
Waves are the right lens to understand this, because blur and sharpen act on each wave independently. So if we understand how the whole loop impacts one wave, we can understand how it affects the whole image.
We can define a single wave of frequency as the function
which repeats every pixels. Small means broad waves, large means fine detail.
Everything here is one-dimensional, but in 2D the explanation still holds, you just have as the length of the wave vector. So, what do blur and sharpen do to a single wave?
Blur and sharpen are volume knobs
Blur gives you back the same wave tuned down, and it quiets small waves more than big ones. When you blur a photo, the small details are washed out first, and only a heavy blur wipes out large regions.
Specifically, you can blur an image with a Gaussian of width which replaces each pixel with a bell-curve-weighted average (a convolution) of its neighborhood:
With:
- , the image value a distance of from
- , how much that pixel counts (most at , almost nothing past a few ).
Multiply the pair, add up the results for every , and the total is the new value at .
With our image as a single wave, , the integral becomes:
If you expand the cosine with the addition formula, then pull everything that doesn't depend on out of the integral:
The second integral cancels out, because the bell curve is symmetric while the sine is antisymmetric, so every contribution at cancels its mirror at , hence:
Knowing that the Fourier transform of a Gaussian is a Gaussian:
Put both back:
A frequency of means a flat wave, all one brightness. There , so the wave comes back unchanged. On the other hand, a big means fine detail, and as grows, collapses toward zero. The finer the detail, the more completely the blur erases it.
Sharpening is the opposite knob. Unsharp masking (the standard sharpen), with radius and strength , takes the image, subtracts a blurred copy (the difference between the two is basically the small details), and adds times the detail back:
With our single wave and the previous blur result for the inner term:
Since a flat wave is identical to its own blurred copy, leaves it unchanged. However, fine details don't survive blurring and the difference is the wave itself, so rises to its ceiling of .
Blur then sharpen
Both operations are linear: applied to a sum of waves, they act on each wave individually. So one round of blur-then-sharpen multiplies each wave's amplitude by a single number , the transfer function of one round.
We can see three regimes as varies in the following curve:
Near , with :
The curve rises above as we leave exactly when
In other words, when the sharpen reaches further than the blur destroys. eventually falls to zero at large , as the blur's exponential beats the sharpen's bounded . So the curve rises above 1, peaks, and falls.
Which wave wins? We can maximize (same peak as , easier derivative):
Setting the derivative to zero, and with :
Solving for :
In words: the winning wavelength is set by the sharpen radius , adjusted by a logarithm of how decisively the sharpen beats the blur. With our concrete setting , , , we get , with peak gain . The predicted pattern wavelength is pixels.
Fifty rounds of this
Each round multiplies by the same , so after rounds the amplitude becomes . Fifty rounds at our settings:
- The winner at grows by .
- Fine detail at , where shrinks by .
- A broad wave at , where reaches only .
Even the winner's near-neighbors lose. A ripple growing at per round instead of ends up times quieter.
Whether a pattern appears depends on three parameters: the blur radius , the sharpen radius , and the sharpen strength , specifically if . The final spot size is decided by these parameters, not by the input. Once again, since this is the crux: the spot size is a property of the filters, not the original photo.
You can try changing the parameters here to get a better feel for it:
α·σs² = 9.00 > σb² = 1.00: there is a hump. Its peak is at k* ≈ 0.60, so the winning ripple is about 10.5 px across, and it gains ×1.51 per round (a thousandfold in ≈ 17 rounds).
Clamping
Increasing the amplitude per round forever would turn brightness up to infinity, so each round ends by clipping every pixel to :
This stops the growth of the winning ripple when its crests are white and its troughs are black with feature size throughout.
What about color photos?
If you ran a color image through the loop, you may have seen spots come out in reds, cyans, and magentas that weren't in the original photo.
A color image has a red, green, and blue channel. Blur, sharpen, and clamp all act on each channel separately. So what we've described for gray images runs three times in parallel, with the same gain curve for the three colors:
Same means same winning wavelength, which is why the spots are the same size for every color. But it doesn't mean same pattern, because the channels are different at the start.
With the clamp, each channel independently saturates at or , so you get outcomes: the corners of the RGB cube.
Back to Turing
In his original paper, Turing talks about two substances, reacting and diffusing at different rates. Our loop contains only one thing: the image. So where is the second substance?
It's actually inside the sharpen. If we look at the formula again:
There are two pictures in that formula: the image itself, and a blurred copy of it. The operation subtracts the blurred one from the sharp one. The sharp image is the activator. The blurred copy is the inhibitor; created, used, and thrown away at each step. Unlike a real chemical, this inhibitor has no life of its own so the analogy is more structural than literal.
A round is one blur and one sharpen, but we can rewrite using the fact that sharpen contains a blur inside it too. Two blurs in a row is actually one wider blur, since Gaussian widths add in quadrature: . Collect terms:
So the round can be written as one convolution, with a single kernel . It's a narrow positive bell minus a wide negative one: a difference of Gaussians, the classic Mexican-hat shape. Each pixel will reinforce its close neighbors and suppress a wider surrounding. In other words, short-range activation, long-range inhibition, which is Turing's proposal.
And we get the same output using two successive blurs:
I find it interesting that the type and size of the patterns that appear, the chemical wave-length as Turing called it, is determined by the dynamics of the system and not the starting conditions. In his paper he uses an oscillator analogy: the circuit fixes the frequency, amplitude, and waveform, while "the phase of the oscillation alone is determined by the disturbance." If we swap phase with position we have our image case, where the original image only explains the position of the patterns.
Another cool instance of this loop runs inside your head. Your visual cortex is wired like : each patch of neurons excites its close neighbours and inhibits a wider ring. Ermentrout and Cowan showed in 1979 what happens when that patch's gain is pushed up, by certain drugs or even flickering light: the blank state loses to a preferred wavelength, and stripes and hexagons of activity grow out of neural noise. People see tunnels and spirals rather than stripes because the cortex lays the image out in its own coordinates. So cortical stripes viewed back through that warp look like tunnels, funnels, and spirals, the classic geometry of hallucinations.
I find it interesting that this kind of thing doesn't depend on the substrate. Chemicals, neurons, pixels, they're different stuff but when short-range activation meets long-range inhibition, the same spots and stripes emerge, at a scale set by the dynamics. Maybe the pattern lives somewhere upstream of the systems that instantiate it, and each of them merely tunes in. Or maybe the three systems just share a mechanism, and math is how we describe mechanisms, so the same description was bound to show up. I wonder.