Lightweight Portrait Matting via Regional Attention and Refinement

Yatao Zhong, Ilya Zharkov · DOI

Abstract

Portrait matting is a critical task in computer vision, traditionally requiring auxiliary inputs such as trimaps or background images. This paper introduces a lightweight, two-stage framework that achieves high-resolution matting without these requirements. By combining a Vision Transformer (ViT) backbone for coarse estimation with a novel Cross Region Attention (CRA) module for local refinement, the proposed model reduces computational costs to 1/20th of previous leading models while maintaining state-of-the-art quality. The system achieves real-time performance for HD (54.9 FPS) and near real-time for 4K video (19.5 FPS) on standard consumer GPUs.

Introduction

Image matting involves the precise separation of a foreground object from its background, defined by the equation $I = \alpha F + (1-\alpha)B$. This problem is inherently ill-posed as multiple combinations of foreground ($F$), background ($B$), and alpha matte ($\alpha$) can produce the same pixel color ($I$). While traditional methods rely on hand-drawn trimaps, modern "trimap-free" models face a significant trade-off between computational efficiency and the preservation of fine details. Processing high-resolution (HD or 4K) images at full scale is computationally prohibitive, yet downsampling often results in the loss of crucial hair-thin details.

Methodology

The proposed architecture follows a "coarse-to-fine" strategy divided into two primary stages:

1. Low-Resolution Stage

The model utilizes a Swin Transformer (ViT) backbone to generate a coarse alpha matte and a predicted trimap. To preserve information during downsampling, the authors employ pixel-unshuffle (tokenization). Unlike standard pooling or strided convolutions, tokenization reshapes the image into patches, moving spatial information into the channel dimension. This allows the ViT to process high-channel, low-spatial-resolution data while retaining the original pixel information necessary for later refinement.

2. Refinement Stage and Cross Region Attention (CRA)

The second stage focuses on "uncertain" regions identified by the coarse stage. These regions are cropped into $8 \times 8$ patches for high-resolution processing. To overcome the loss of global context inherent in local cropping, the authors introduced the Cross Region Attention (CRA) module.

The two-stage architecture overview, showing the transition from coarse estimation to regional refinement.

The CRA module uses a K-Nearest Neighbors (KNN) approach, allowing local patches to communicate with their neighbors. By incorporating a learnable lookup table for relative positional bias, the model maintains an understanding of spatial relationships, propagating contextual information across the image without the need for a heavy global network at high resolution.

Experimental Results

The model was evaluated on the P3M-10k and PPM-100 datasets, which are standard benchmarks for human portrait matting.

Efficiency and Speed

The framework demonstrates remarkable efficiency, requiring only 19 GFLOPs—a nearly 20x reduction compared to P3M-Net's 364.9 GFLOPs. On an Nvidia RTX 6000, the model achieves 54.9 FPS for HD and 19.5 FPS for 4K video, making it suitable for real-time applications.

Qualitative and Quantitative Performance

Despite its lightweight nature, the model matches or exceeds the accuracy of much heavier counterparts like MODNet and BGMv2. It particularly excels in metrics like "Connectivity" and "Gradient" errors, which correlate strongly with human perception of matte quality, especially around complex hair boundaries.

Qualitative comparison of the proposed model against Ground Truth (GT) and other leading matting frameworks.

Conclusion

This research provides a viable path for high-quality, real-time portrait matting on consumer hardware. By inverting the typical context-gathering order and focusing computation on uncertain boundary regions via the CRA module, the model bridges the gap between efficiency and detail. Future work will focus on improving robustness against high-contrast background textures and reducing error propagation between the coarse and refinement stages.

Summary updated

BibTeX
@inproceedings{zhong2024lightweight,
  author = {Yatao Zhong and Ilya Zharkov},
  title = {{Lightweight Portrait Matting via Regional Attention and Refinement}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2024},
  doi = {10.1109/wacv57701.2024.00411},
}
Figure