SCS-Co: Self-Consistent Style Contrastive Learning for Image Harmonization

Yucheng Hang, Bin Xia, Wenming Yang, Qingmin Liao

Abstract

Image harmonization is a critical task in image composition, aimed at adjusting the appearance of a foreground object to match the lighting and style of a new background. Existing deep learning approaches often struggle with a lack of explicit boundaries for visual distortion and rely on global background statistics that ignore local stylistic variations. We introduce SCS-Co, the first contrastive learning framework specifically designed for image harmonization. By dynamically generating multiple negative samples, SCS-Co provides the model with a robust understanding of visual disharmony. Furthermore, we propose Background-Attentional Adaptive Instance Normalization (BAIN) to align foreground styles with visually relevant background regions. Our method achieves state-of-the-art results on the iHarmony4 benchmark and demonstrates a unique "plug-and-play" capability that improves existing harmonization architectures.

Introduction

When an object is cropped from one image and pasted into another, the resulting composite often appears unnatural due to discrepancies in color temperature, illumination, and weather conditions. Image harmonization seeks to resolve these inconsistencies. However, current research faces two primary challenges. First, most models learn exclusively from positive examples (ground truth images), leaving the "solution space" for what constitutes a distorted image poorly defined. Second, many methods utilize global background statistics to normalize the foreground, which fails when the background contains diverse lighting conditions, such as a scene with both deep shadows and bright sunlight.

Methodology

Self-Consistent Style Contrastive Learning (SCS-Co)

The core of our approach is a contrastive learning scheme that regularizes the training process by defining what a "bad" result looks like. In this framework:

  • The Anchor: The harmonized image generated by the network.
  • The Positive Sample: The ground truth real image.
  • The Negative Samples: The original composite image and several dynamically generated "distorted" versions created via random color transfers from the training batch.

By pulling the anchor toward the positive sample and pushing it away from the negative samples in a style representation space, the model learns a precise definition of harmony. This is enforced through two constraints: Foreground Self-Style (SS-CR) and Foreground-Background Consistency (CS-CR). To focus on texture and lighting rather than object geometry, we utilize a pre-trained VGG-16 network as a style representation extractor.

Background-Attentional Adaptive Instance Normalization (BAIN)

To address the limitations of global statistics, we propose BAIN. Unlike previous methods like RAIN that use global averages, BAIN employs an attention mechanism to calculate the similarity between the foreground and specific background regions. The foreground is then normalized based on a weighted average of these features, ensuring it "listens" to the most visually relevant parts of the background.

Experimental Results

Quantitative and Qualitative Performance

We evaluated SCS-Co on the iHarmony4 benchmark (HCOCO, HAdobe5k, HFlickr, and Hday2night) and the DIH Real Composite Dataset. Our method achieved an average PSNR of 38.75 dB, significantly outperforming the previous state-of-the-art (38.19 dB). The Mean Squared Error (MSE) was also reduced from 24.44 to 21.33. Qualitatively, SCS-Co produces results with fewer ghosting artifacts and more natural color blending than earlier models like DoveNet or RainNet.

Human Preference

A user study involving 60 volunteers and approximately 30,000 pairwise comparisons confirmed these findings. SCS-Co achieved the highest Bradley-Terry (B-T) score of 1.841, indicating a clear human preference for its output over existing techniques.

Universal Applicability

A significant advantage of the SCS-Co training scheme is its versatility. When integrated into other architectures—such as RainNet, DIH, and iS2AM—it consistently improved performance without adding any additional parameters during the inference phase.

Conclusion and Limitations

SCS-Co advances image harmonization by introducing a contrastive learning framework that effectively utilizes negative samples to refine style boundaries. While the method is highly effective, it does involve a computational trade-off; increasing the number of negative samples improves performance but extends training time. Additionally, the reliance on a fixed VGG-16 style extractor suggests that future work could explore more sophisticated or learnable style representations and more diverse methods for generating negative samples to further enhance the model's understanding of visual harmony.

Summary updated

BibTeX
@inproceedings{hang2022scs,
  author = {Yucheng Hang and Bin Xia and Wenming Yang and Qingmin Liao},
  title = {{SCS-Co: Self-Consistent Style Contrastive Learning for Image Harmonization}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2022},
}
Figure