CANet: A Context-Aware Network for Shadow Removal

Zipei Chen, Chengjiang Long, Ling Zhang, Chunxia Xiao

TL;DR

CANet is a novel two-stage, context-aware deep network designed to remove shadows from images by intelligently transferring texture and illumination information from non-shadow regions to shadow regions. By matching patches globally and processing color channels separately before a final deep refinement stage, it achieves state-of-the-art performance with highly realistic, artifact-free results.

What Problem Does This Paper Address?

Shadows are a ubiquitous natural phenomenon, but in computer vision, they are a major nuisance. They degrade the performance of essential tasks like object tracking, visual recognition, and image captioning because they alter the apparent color and geometry of a scene.

Traditional physical-based methods try to calculate illumination models but frequently leave behind harsh, unnatural shadow boundaries. Modern learning-based methods use deep networks to understand the scene but typically focus on expanding the network's receptive field. This approach often misses the fine-grained, global contextual relationships hidden within the image—specifically, the fact that a shadowed region often shares identical texture and material properties with a well-lit region elsewhere in the same image. CANet addresses this gap by explicitly finding and leveraging these non-shadowed "twin" regions to guide the reconstruction.

Methods

CANet breaks the shadow removal task into a two-stage pipeline:

Figure 1. The overview of our proposed CANet, which takes two stages for shadow removal. At Stage-I, the contextual feature is firstly extracted via a pretrained DenseNet [18]; meanwhile, the designed contextual patch matching module (CPM) (see Figure 2) is used to acquire a set of contextual matching pairs; then, applying a contextual feature transfer mechanism (see Figure 3) to transfer contextual information from non-shadow patches to shadow patches to recover the L and A/B channels of the shadow-removal image. At Stage-II, we integrate the recovered L and A/B channel information with the input shadow image and feed them into a DenseUNet to generate the final shadow-removal result.

Stage-I: Contextual Matching and Feature Transfer

  1. Contextual Patch Matching (CPM): To find matching regions without being blinded by the shadow itself, the authors first create a "shadow-unaware" image by applying a mean-filter to the lightness channel. They then extract $32 \times 32$ patches from both the original and shadow-unaware images. A dual-head network evaluates patch pairs to predict both a correlation score (0 to 1) and a pair type classification (identifying which patch is shadowed vs. unshadowed).
Figure 2. The architecture of our dual-head contextual patch matching module. We first calculate the shadow-unaware image by lightness average with a mean-filter operation. Then, we extract 32 × 32 patches from the shadow image and the shadow-unaware image, and feed them into the shared patch descriptor to extract deep learning features. Finally, the extracted features are fed into the two heads to predict the type (denoted as -1, 0, or 1) of the in- put patch pair and the corresponding degree as a continuous value in the range of 0 to 1 to measure their correlation.
  1. Contextual Feature Transfer (CFT): Directly copying features from a bright region to a dark region creates harsh discontinuities. Instead, the CFT mechanism uses Gaussian sampling to adaptively blend features from the top-$k$ matched non-shadow patches across multiple scales.
Figure 3. The illustration of how we use our contextual feature transfer mechanism to transfer the contextual information according to captured contextual matching pairs. Note that we use the Gaussian sampling to sample contextual information from non-shadow patches and integrate them to the query shadow patches adaptively.
  1. Channel Separation: Shadows affect lightness far more than color. CANet processes the $L$ (lightness) and $A/B$ (chrominance) channels separately in the LAB color space using upsampling and residual blocks. This prevents over-processing the color channels while ensuring the lightness is fully recovered.

Stage-II: Refinement

The separated, recovered channels from Stage-I are concatenated with the original shadow image and fed into an encoder-decoder network called DenseUNet. This stage cleans up any residual artifacts or mismatch errors from Stage-I, outputting a smooth, final shadow-free image.

Datasets

The network was trained and evaluated on two prominent shadow removal benchmarks:

  • ISTD: Contains 1,330 training triplets (shadow image, shadow mask, and shadow-free ground truth) and 540 testing triplets.
  • SRD: Contains 2,680 training pairs and 408 testing pairs. Notably, SRD lacks ground-truth shadow masks, so the authors utilized a state-of-the-art shadow detection method (DSD) combined with manual cleanup to generate approximate masks for training the CPM module.

Key Insights and Ideas

  • The "Shadow-Unaware" Image: One of the cleverest tricks in the paper is mean-filtering the lightness channel to create a shadow-unaware representation. This effectively normalizes the illumination across the image, allowing the patch matcher to focus strictly on underlying texture similarity rather than being distracted by the shadow.
  • The Asymmetry of LAB Channels: Statistical analysis by the authors revealed that the $L$ channel is dramatically more sensitive to shadows than the $A$ and $B$ channels.
Figure 4. The difference between the input shadow image and the ground truth shadow-free image in shadow areas of each channel in LAB color space on the ISTD dataset [35](first row) and the SRD dataset [31](second row).

Treating them as separate sub-problems prevents the color bleeding and distortion common in networks that treat RGB channels uniformly.

  • Soft vs. Hard Transfer: Instead of a hard replacement of features, the integration of Gaussian sampling within the feature transfer mechanism provides a larger receptive field and smooths out spatial transitions, preventing patch-like artifacts.

Key Results

CANet was compared against eight state-of-the-art traditional and learning-based methods (including RIS-GAN, DSC, and ARGAN).

Quantitative Performance: Evaluated using Root Mean Square Error (RMSE) in the LAB color space (where lower is better), CANet outperformed all competitors across the board:

  • ISTD Dataset: Achieved an RMSE of 8.86 in shadow areas and 6.15 overall (compared to the next best, RIS-GAN, at 9.15 and 6.62).
  • SRD Dataset: Achieved an RMSE of 7.82 in shadow areas and 5.98 overall (compared to RIS-GAN at 8.09 and 6.17).

Qualitative Performance: Visually, CANet successfully eliminates the "ghosting" artifacts and boundary color distortions that plague other networks. It maintains excellent color consistency with the surrounding environment, even in complex real-world scenes outside the benchmark datasets.

Limitations and Future Work

Despite its strong performance, CANet has a few notable limitations:

  1. Context Dependency: If a shadowed object has a completely unique texture with no unshadowed equivalent anywhere else in the image, the CPM module cannot find a valid match, causing the illumination recovery to degrade.
  2. Environmental Luminosity Variations: If the training data contains pairs with highly inconsistent camera exposures, the model can occasionally output results with minor color inconsistencies.
  3. Video Temporal Consistency: While CANet can process video frames individually, it does not inherently account for temporal continuity between frames. The authors plan to address video-level shadow removal and expand the framework to handle highlight removal in future work.

Summary updated

BibTeX
@misc{chen2021canet,
  author = {Zipei Chen and Chengjiang Long and Ling Zhang and Chunxia Xiao},
  title = {{CANet: A Context-Aware Network for Shadow Removal}},
  year = {2021},
  eprint = {2108.09894},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2108.09894},
}
Figure