Learning Sparse Masks for Diffusion-Based Image Inpainting

Tobias Alt, Pascal Peter, Joachim Weickert

This paper, presented at PRIA 2021, introduces a novel deep learning approach to a classic problem in image processing: finding the best "mask" (a sparse set of pixels) to reconstruct an image using diffusion-based inpainting.

TL;DR

The authors developed a dual-network architecture that learns to generate optimal sparse inpainting masks in milliseconds. By using a neural "surrogate solver" to emulate complex physics-based inpainting during training, they achieve reconstruction quality comparable to slow stochastic optimization methods while being up to four orders of magnitude faster.

What Problem Does This Paper Address?

Diffusion-based inpainting is a technique that restores an image by solving a Partial Differential Equation (PDE). It "spreads" information from a small set of known pixels (the mask) into the missing regions. This is highly effective for applications like image compression, where you only want to store a tiny fraction of the original data.

The "holy grail" of this field is finding the optimal spatial location for these mask pixels. Currently, researchers face a trade-off:

  1. Analytic Approaches: These are nearly instantaneous (based on image features like the Laplacian) but produce mediocre reconstruction quality.
  2. Stochastic Approaches: Methods like Probabilistic Sparsification (PS) produce high-quality masks but are incredibly slow, often requiring thousands of inpainting iterations to "evolve" a good mask.

The authors aim to bridge this gap: getting the high quality of stochastic optimization with the real-time speed of a neural network.

Methods

The authors propose a hybrid architecture consisting of two equally shaped U-Nets trained jointly:

  • The Mask Network: This network takes the original image and outputs a non-binary mask. To make the process differentiable, the mask values are kept between 0 and 1. A specific regularization term is added to prevent the network from taking the "easy way out" (producing a flat, uniform mask) by penalizing low variance.
  • The Inpainting Network (Surrogate Solver): This is the core innovation. Instead of using a traditional numerical PDE solver during training—which is computationally expensive and difficult to backpropagate through—they train a second U-Net to act as the solver. It learns to produce the reconstruction that the PDE would have created.

The Workflow: During training, the Mask Network proposes a mask, and the Inpainting Network evaluates it. The system is optimized using two losses: an inpainting loss (how close is the reconstruction to the original?) and a residual loss (how well does the reconstruction satisfy the actual diffusion PDE?).

At inference time, the Mask Network generates a mask, which is then binarized and fed into a standard, high-precision numerical solver for the final reconstruction.

Datasets

  • Training: The model was trained on the BSDS500 dataset, using 200 cropped greyscale images of size 256 × 256.
  • Evaluation: Performance was tested on five classic image processing benchmarks: boat, cameraman, house, trui, and peppers.

Key Insights and Ideas

  • The Surrogate Solver Concept: By emulating the PDE solver with a neural network, the authors bypass the "computational bottleneck" of traditional optimization. This allows the mask generator to "see" the consequences of its pixel choices instantly during training.
  • Density Control: The model can be trained for specific mask densities (e.g., only keeping 5% of pixels). The authors found that for very sparse masks (1–2% density), their learned approach is particularly dominant.
  • Structural Similarity: Visually, the learned masks look remarkably similar to those produced by the most advanced (and slow) stochastic methods, capturing sharp edges and contours rather than just random noise.

Key Results

  • Massive Speedup: Generating a mask with the learned model takes approximately 85 milliseconds on a CPU. In contrast, the high-quality stochastic method (PS+NLPE) takes over 3 minutes. This represents a speedup of roughly 4,000x to 10,000x.
  • Competitive Quality: In terms of Peak Signal-to-Noise Ratio (PSNR), the learned masks consistently outperform analytic methods. For very low densities (under 5%), the model is on par with or even slightly better than the "gold standard" stochastic methods.
  • Efficiency: Unlike stochastic methods, the time required to generate a mask with this model does not increase as the desired mask becomes sparser.

Limitations and Future Work

  • PDE Complexity: This study focused on homogeneous diffusion, which is the simplest form of PDE-based inpainting. The authors note that extending this to more sophisticated "anisotropic" diffusion (which handles edges even better) is a logical next step.
  • Tonal Optimization: The paper only optimizes the location of pixels, not their values. In high-end image compression, researchers often tweak the color values of the mask pixels to further improve results. The authors suggest their framework could be extended to include this "tonal optimization" in the future.
  • Binarization: The transition from a continuous neural network output to a binary (0 or 1) mask currently relies on a "weighted coin flip" (probabilistic dithering), which might introduce slight sub-optimality.

Summary updated

BibTeX
@inproceedings{alt2022learning,
  author = {Tobias Alt and Pascal Peter and Joachim Weickert},
  title = {{Learning Sparse Masks for Diffusion-Based Image Inpainting}},
  booktitle = {IbPRIA},
  year = {2022},
  doi = {10.1007/978-3-031-04881-4\_42},
}
Figure