C19 · Recovering information
Energies, diffusion and contours
Replace make-it-better with an explicit objective: stay close to measurements while limiting a chosen kind of complexity.
Theory
Diffusion exchanges differences between neighbors
The discrete Laplacian is four neighbors minus four times the center. An explicit heat step adds dt times it. On a unit 2D grid, dt≤1/4 keeps mixing weights nonnegative; larger steps can create growing oscillations. The console caps dt at 0.24.
The continuous heat equation relates to Gaussian smoothing. A finite grid, boundaries and time steps give a numerical approximation. Repeated edge values imply no outward flux. Long smoothing removes useful contrast along with disturbance.
One diffusion step
Neighbor exchange smooths small differences. Compare zero and one iteration before increasing the count.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Inspect the selected point
What the plot shows
At steps no greater than 1/4, the new value is a nonnegative weighted sum of the center and four neighbors. Smoothing cannot distinguish noise from a useful thin line.
- MSE
- 0.001
- RMSE
- 0.0324
- PSNR (range 0–1)
- 29.8018 dB
Parameters and details
Heat: explicit four-neighbor scheme, dt≤0.24, repeated boundaries. TV: ½||u−f||² + λΣ(√(dx²+dy²+ε²)−ε); backtracking enforces nonincreasing energy. This is smoothed convex TV, not Perona–Malik or exact nonsmooth ROF.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
Two energy terms compete over the result
Quadratic fidelity penalizes moving u away from observation f. Total variation penalizes the sum of spatial change magnitudes, not the sum of absolute intensities. Here smooths the magnitude for ordinary gradient steps. Larger λ makes spatial changes more expensive.
At each cell, dx is the right value minus the center and dy is the lower value minus the center. Compute r = √(dx² + dy² + ε²), then normalized contributions qₓ = λ·dx/r and qᵧ = λ·dy/r. Neighboring pairs also affect the selected center: the TV gradient adds qₓ from the left and qᵧ from above, then subtracts its own qₓ and qᵧ. Boundary fluxes are zero. These are the four numbers shown in the update trace.
Every iteration computes the gradient of this exact energy. If a trial step increases it, the step shrinks. The plot shows computed history, not an illustrative convergence curve. Lower energy does not guarantee minimum reference error or better texture preservation.
Data fit and image simplicity
Increase smoothness weight and follow actual energy over iterations. Compare edges and small oscillations.
Exact values are in the point inspector
Grayscale 0…1: black to white.
- Data gradient: previous value − observation
- TV gradient: left q + upper q − right q − lower q
- Add both gradients
- Value − accepted step × gradient
Exact values are in the point inspector
Grayscale 0…1: black to white.
Inspect the selected point
What the plot shows
Total energy combines disagreement with the observation and a penalty on brightness changes. Changing λ changes the objective itself: heights from different settings are not comparable quality scores.
- Total E(u)
- Data disagreement
- Variation penalty × λ
- Displayed iteration: 8
Energy decreases through checked backtracking. This belongs to the chosen convex smoothed model, not a promise of perfect restoration.
- MSE
- 0.0006
- RMSE
- 0.0255
- PSNR (range 0–1)
- 31.8805 dB
Parameters and details
Heat: explicit four-neighbor scheme, dt≤0.24, repeated boundaries. TV: ½||u−f||² + λΣ(√(dx²+dy²+ε²)−ε); backtracking enforces nonincreasing energy. This is smoothed convex TV, not Perona–Malik or exact nonsmooth ROF.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
A different energy changes the algorithm and guarantees
Reference and further methods
Nonsmooth ROF needs specialized optimization, such as dual or proximal methods. Perona–Malik changes diffusion with gradient and does not automatically inherit convex TV guarantees. TV can create staircasing; quadratic smoothing can blur edges.
Mumford–Shah describes smooth regions and boundaries together. A level set stores a contour as the zero level of a scalar field, allowing topology changes; Chan–Vese connects this representation to region energies. Euler–Lagrange equations provide stationarity conditions under assumptions, not a ready stable browser solver.
Practice
Test the idea under another condition. Follow the task above the images; point inspection helps explain the result. This exploration is not scored.
Lower energy does not necessarily recover the scene
Begin at zero iterations, then try 1, 5 and 20 steps at fixed λ. Compare the image and both energy terms: agreement with the observation and the variation penalty.
Exact values are in the point inspector
Grayscale 0…1: black to white.
- Data gradient: previous value − observation
- TV gradient: left q + upper q − right q − lower q
- Add both gradients
- Before the first update: τ = 0
Exact values are in the point inspector
Grayscale 0…1: black to white.
Inspect the selected point
What the plot shows
Total energy combines disagreement with the observation and a penalty on brightness changes. Changing λ changes the objective itself: heights from different settings are not comparable quality scores.
- Total E(u)
- Data disagreement
- Variation penalty × λ
- Displayed iteration: 0
The total objective can decrease even when error against the clean scene increases. The plot explains optimization of the chosen task; it does not prove recovery of truth.
- MSE
- 0.0026
- RMSE
- 0.0507
- PSNR (range 0–1)
- 25.8994 dB
Parameters and details
Heat: explicit four-neighbor scheme, dt≤0.24, repeated boundaries. TV: ½||u−f||² + λΣ(√(dx²+dy²+ε²)−ε); backtracking enforces nonincreasing energy. This is smoothed convex TV, not Perona–Malik or exact nonsmooth ROF.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
Games
Test your explanation
Question 1 of 5
Why limit the explicit heat step?
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Choose one answer. It is checked immediately.
Limitations and references
Limits of this example
Finite heat and smoothed-TV steps with backtracking are executed. This is not a Chambolle/ROF, Perona–Malik or evolving-level-set implementation; those are explained as distinct methods.
Mathematical reference
- Derivatives and vector fields
- Optimization and inverse problems
- Numerical computation
- Variations and function spaces