Natural Image Matting via Guided Contextual Attention

Yaoyi Li, Hongtao Lu

Abstract

Image matting is a fundamental computer vision task that involves estimating the foreground opacity for every pixel in an image. This paper introduces a novel end-to-end deep learning approach that utilizes a Guided Contextual Attention (GCA) module. The GCA module leverages low-level image appearance to guide the global propagation of high-level opacity information, effectively resolving local ambiguities in semi-transparent regions. Our method achieves state-of-the-art results on major benchmarks, including the Adobe Composition-1k dataset and the alphamatting.com benchmark.

Introduction

The process of image matting is defined by the composition equation $I = \alpha F + (1-\alpha)B$, where $I$ is the observed image, $F$ and $B$ are the foreground and background colors, and $\alpha$ is the opacity. This is an ill-posed problem with three unknowns for every known pixel value. Deep learning has significantly advanced matting, yet many models struggle with "local ambiguity"—where a semi-transparent foreground patch may be indistinguishable from a solid background patch without broader context.

To address this, the authors propose looking at the "far-surrounding" context by finding similar textures in known regions to inform the opacity of unknown pixels. While traditional affinity-based methods attempted this through hand-crafted similarities, they lacked the representational power of deep neural networks.

Proposed Architecture

The core of the approach is a customized U-Net architecture integrated with Guided Contextual Attention (GCA) blocks.

The proposed GCA matting architecture, featuring a U-Net backbone with integrated GCA blocks and a short cut block for detail preservation.

The network employs several key components to improve performance over standard baselines:

  1. Spectral Normalization: Used to stabilize the training process.
  2. Short Cut Block: Feeds the original image directly into the final layers to preserve fine-grained details and gradients.
  3. GCA Blocks: Placed symmetrically in the encoder and decoder at the $64 \times 64$ resolution stage to propagate opacity information multiple times.

Guided Contextual Attention (GCA)

The GCA module is inspired by contextual attention mechanisms used in image inpainting. It operates using two distinct feature flows:

  • Image Feature Flow (Guidance): Extracts low-level appearance features such as color and texture from the RGB image.
  • Alpha Feature Flow: Carries high-level opacity information through the encoder-decoder.

The module calculates a similarity matrix (attention map) based on the image features between unknown and known regions. This map then guides the propagation of alpha features from known areas to fill in unknown regions.

Visualization of the GCA module's attention maps. The model uses low-level RGB features to guide the propagation of opacity information across the image.

By implementing this as a convolution/deconvolution operation, the model can look at the entire image to resolve a single pixel's ambiguity, mimicking the strengths of traditional affinity-based methods within a modern deep-learning framework.

Experimental Results

The GCA Matting model was evaluated on the Adobe Composition-1k dataset and the alphamatting.com benchmark.

  • Adobe Composition-1k: The model achieved an MSE of 0.0091 and a SAD of 35.28, outperforming previous state-of-the-art methods like SampleNet (0.0099 MSE / 40.35 SAD).
  • alphamatting.com: At the time of submission, the model ranked 1st in the Gradient Error metric, highlighting its ability to capture fine structures like hair and mesh.

Qualitative results demonstrate that the model is significantly better at "seeing through" complex objects, such as sieves or fine mesh, where previous models often produced blurry artifacts.

Conclusion and Limitations

While the GCA module provides a powerful mechanism for resolving ambiguity, it introduces quadratic computational complexity $O((hw)^2)$ relative to the feature map dimensions. Consequently, GCA blocks are currently restricted to lower-resolution feature maps. Future work will focus on more efficient attention mechanisms and extending this approach to video matting.

Summary updated

BibTeX
@inproceedings{li2020natural,
  author = {Yaoyi Li and Hongtao Lu},
  title = {{Natural Image Matting via Guided Contextual Attention}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2020},
  doi = {10.1609/aaai.v34i07.6809},
}
Figure