Diffusion in Image Processing
Treat an image's brightness like temperature and let it diffuse: that's a Gaussian blur, with radius growing as you run it longer. Fine noise fades first, but edges blur too, so edge-preserving versions slow the flow across strong edges and keep outlines sharp.
What the symbols mean
- Image brightness
A function of position (and of time as it diffuses).
- Gaussian kernel
The bell-shaped blur filter.
- Blur radius
The kernel's standard deviation, in pixels.
What the symbols mean
- Edge-stopping function
Near 0 where the gradient is large, so edges barely diffuse.
Explanation
Diffusion is simply stuff spreading out from where there's a lot of it to where there's less, like heat through metal or dye through water, and here the "stuff" is brightness in a photo, with bright pixels "hot" and dark ones "cold." The fancier version later on is called anisotropic diffusion, which just means it doesn't spread equally in every direction. It's good for cleaning up noisy photos and scans, and for spotting features at different sizes. The formula looks dense, but it's two ways of saying one thing: on the left, (how fast a pixel's brightness changes) equals (how different it is from its neighbors); on the right, the result is (the original photo) smeared by (a bell-shaped blur) of radius (how far each pixel's brightness has spread). It's the heat kernel from two lessons back, wearing a camera; bear with it.
Images as functions. A grayscale image is a grid of brightness values . That's just a temperature on a grid, so everything from finite differences carries over. The discrete Laplacian at a pixel is the sum of its four neighbors minus four times its own value, so one explicit heat step moves each pixel toward the average of its neighbors.
Why it removes noise. Noise is pixel-to-pixel flicker, which is the highest frequency an image can have. From the Fourier transform lesson, a wave of frequency fades like , so the flicker is the first thing to go while broad shapes barely change. Diffusion is a low-pass filter.
Scale space. Diffusing for longer blurs more: running the heat equation produces the whole family of blurred images at once, a standard tool for finding features at different sizes.
Blurs compose. Two Gaussian blurs with radii and equal one blur of radius . Think about why: blurring for time and then is the same as blurring for , and since , adding times means adding the 's.
A common mistake. It's tempting to think two blurs of radius 3 and 4 make a blur of radius 7, because blurs pile up. They don't add like that. The squares add, so the total is , the same rule that makes variances add in statistics.
Anisotropic diffusion. The plain heat equation can't tell noise from an edge: both are sharp changes in brightness, so both get smoothed. Perona and Malik fixed this by making the conductivity depend on the gradient: flat regions with small noisy wiggles diffuse freely, while strong edges, where the gradient is big, hardly diffuse at all. The result denoises without blurring outlines.
See it
Worked examples
Diffusing with , how long until the blur radius is 3 pixels?
- 1
Square the blur radius to get rid of the root: . With and that's , so .
Practice
Type your answer and check it. Solve them all to complete the lesson.
Find the blur radius for , .
With , how long until the blur radius is 3?
A pixel of brightness 10 has neighbors 12, 8, 11 and 9. Find the discrete Laplacian.
Why does Perona–Malik diffusion keep edges sharp?
Blurs of radius 3 and then 4 equal a single blur of what radius?
A camera's sensor noise is mostly a pixel-to-pixel flicker, frequency per pixel. Diffusing with px² per unit time, that flicker fades like . How much diffusion time brings it down to 1%?
A Gaussian blur's radius is . To double the blur radius, by what factor must the diffusion time grow?
The hardest one here. Get it, and you've got this lesson.
A phone applies a Gaussian blur of px to denoise a photo. How much more blur, , brings the total to px? (Blurs combine like running the heat equation for longer: the times add, so the 's add.)
Where it's used
Photo editors, medical image denoising, computer vision feature detectors (SIFT) and the diffusion models that generate images all rely on diffusion equations.