Image Inpainting using Partial Convolution

Harsh Patel, Amey Kulkarni, Shivam Sahni, Udit Vyas · DOI

Abstract

Image Inpainting is one of the very popular tasks in the field of image processing with broad applications in computer vision. In various practical applications, images are often deteriorated by noise due to the presence of corrupted, lost, or undesirable information. There have been various restoration techniques used in the past with both classical and deep learning approaches for handling such issues. Some traditional methods include image restoration by filling gap pixels using the nearby known pixels or using the moving average over the same. The aim of this paper is to perform image inpainting using robust deep learning methods that use partial convolution layers.

Introduction

Image inpainting is a fundamental challenge in computer vision: predicting the content of missing or corrupted regions within an image. Applications range from the restoration of historical photographs to the removal of unwanted objects or text from digital images.

Traditional "classical" approaches typically rely on local pixel propagation from surrounding unmasked areas. While effective for minor defects like small scratches, these methods fail on larger missing regions because they lack semantic understanding. They cannot infer that a missing patch on a face should be an eye; instead, they produce blurred or repetitive patterns. While standard deep learning models have improved upon this, standard convolutional layers often struggle with irregular holes. They treat masked (missing) pixels identically to valid ones, frequently resulting in color discrepancies and blurring artifacts.

Methodology

The proposed approach, inspired by Liu et al., introduces two primary innovations to address these limitations:

  1. Partial Convolutional Layers: Unlike standard convolutions that operate on all pixels in a sliding window, a partial convolution only computes output based on "available" (unmasked) pixels. The output is normalized by the ratio of valid pixels to the total window size, preventing "hole" pixels from polluting valid features in the early processing stages.
  2. Mask Update Step: Following each partial convolution, the mask is updated. If a convolution window contains at least one valid pixel, that location is marked as "valid" for subsequent layers. This mechanism allows the network to progressively "shrink" the holes as information propagates through the architecture.
Overview of the PConv UNet pipeline and its multi-component loss function.

The architecture utilizes a modified UNet backbone with seven encoding and seven decoding layers. To achieve realistic reconstructions, a multi-part loss function is employed:

  • Perceptual Loss: Utilizes a pre-trained VGG-16 network to ensure reconstructed features (edges, shapes) align with the ground truth.
  • Style Loss: Employs Gram matrices to maintain consistency in texture and color composition.
  • Total Variation (TV) Loss: Promotes spatial continuity and smoothness, mitigating "checkerboard" artifacts.
  • Pixel-wise Loss: Directly compares the output to the original image for both masked and unmasked regions.

Experimental Setup

The model was trained and evaluated on two benchmark datasets:

  • CelebA-HQ: Comprising 30,000 high-quality human face images (resized to 256x256), split into 70% training, 15% validation, and 15% testing.
  • Places2: Used to evaluate the model's generalizability across diverse scenes and environments.

Results and Discussion

The core advantage of partial convolutions lies in their ability to ignore masked regions, preserving the integrity of known data. Ablation studies revealed a synergy between the loss components: Perceptual loss is critical for sharpness and edge definition, while Style loss ensures the reconstructed regions match the surrounding color and texture, preventing a "pasted-on" appearance.

Qualitative results showing the inpainting process from corrupted image and mask to the final reconstructed output.

Quantitatively, the Partial Convolution (PConv) model significantly outperformed classical techniques like the Navier-Stokes algorithm. For a 5% mask ratio, the PConv model achieved a PSNR of ~55.5, compared to ~6.3 for the classical method. Qualitatively, the model enables "Automated Segmented Object Removal" when paired with a segmentation model (e.g., FCN-ResNet101), allowing for the realistic removal of people or objects from backgrounds.

Conclusion

This work demonstrates that partial convolutions provide a robust framework for semantic image inpainting. While training is computationally intensive—requiring approximately 20 hours for 34,500 iterations—the results mark a significant step forward. Future research will focus on extending this framework to video inpainting to ensure temporal consistency and exploring "image deocclusion" to reconstruct scenes behind foreground objects.

Summary updated

BibTeX
@misc{patel2021image,
  author = {Harsh Patel and Amey Kulkarni and Shivam Sahni and Udit Vyas},
  title = {{Image Inpainting using Partial Convolution}},
  year = {2021},
  eprint = {2108.08791},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2108.08791},
}
Figure