Reconstruct a corrupted image by total-variation in-painting — a convex model that fills in missing pixels with no machine-learning training, just “match what you know and stay smooth.”
12.1 Repairing a damaged image
A grayscale image is just a matrix of pixel intensities. Suppose some pixels are corrupted (here, white text scrawled over the picture) and we know which ones. Can we fill them in? The total-variation in-painting model says: among all images that agree with the known pixels, choose the one with the smallest total variation — the least “jumpy” one. Total variation of \(U\) is
The model is a direct transcription of the math: minimize total variation subject to matching the known pixels.
U <-Variable(c(rows, cols))prob <-Problem(Minimize(total_variation(U)),list(known * U == known * u_corr))psolve(prob, solver ="SCS") # ~16k variables; a few seconds
Original, corrupted, and in-painted (the text is gone).
par(op)
The solver never “knew” it was looking at a face — it just found the smoothest image consistent with the surviving pixels. That is the power of a good convex model.
12.2 Takeaways
A convex model (total variation) reconstructs a damaged image with no machine-learning training — just “match the known pixels, stay smooth.”
The unknowns are the ~16,000 pixels of an entire image, yet the model is three lines of CVXR; the structure lives in the objective, not in bespoke code.
The same in-painting idea extends to denoising, deblurring, and compressed sensing — swap the data-fit term, keep the smoothness penalty.