Foreground-aware Semantic Representations for Image Harmonization

Konstantin Sofiiuk, Polina Popenova, Anton Konushin

Abstract

Image harmonization is the process of adjusting the appearance of a foreground object to ensure it blends naturally with a new background. Traditional methods often struggle with high-level semantic consistency, leading to unrealistic results. We introduce iDIH (improved Deep Image Harmonization), a framework that leverages pre-trained semantic segmentation backbones to provide high-level context. By making these backbones "foreground-aware" and employing a novel Foreground-Normalized MSE (FN-MSE) loss, our model achieves state-of-the-art performance on the iHarmony4 benchmark, significantly improving visual fidelity and training efficiency.

Introduction

Image compositing—the act of cutting an object from one image and pasting it into another—is a cornerstone of digital photo editing. However, the resulting composite often appears "fake" or "uncanny" because the foreground object’s lighting, contrast, and color temperature do not match the environmental conditions of the new background.

The proposed image harmonization pipeline, transforming a raw composite into a visually consistent result.

The task of image harmonization aims to resolve these discrepancies automatically, creating a seamless and visually plausible final image.

What Problem Does This Paper Address?

Current deep learning approaches for image harmonization typically train encoder-decoder networks from scratch. This approach is often inefficient because, without prior knowledge, a neural network must learn both low-level pixel statistics and high-level object semantics simultaneously from relatively small datasets.

A composite image showing a clear visual mismatch between the foreground boy and the background scene.

If a model lacks semantic understanding—for example, not recognizing that it is processing a "person" or a "car"—it may apply incorrect adjustments. A model might mistakenly turn a giraffe bright red to "match" a sunset, rather than subtly adjusting its shading based on the light source. The authors argue that integrating high-level semantic features is the key to moving beyond simple pixel matching.

Methods

The proposed iDIH architecture integrates pre-trained semantic backbones through three primary innovations:

1. Foreground-Aware Pre-trained Backbones

Instead of training from zero, the model utilizes state-of-the-art semantic segmentation networks (e.g., HRNet+OCR or DeepLabV3+) pre-trained on ImageNet. To make these networks "foreground-aware," an additional convolutional layer is added at the input stage to process the object mask. This mask is fused with the standard RGB input, allowing the model to extract distinct features for the foreground object versus the background.

2. The iDIH Architecture

The researchers modified the standard Deep Image Harmonization (DIH) structure to be fully convolutional and introduced a blending layer. Rather than reconstructing the entire image, the network predicts the harmonized foreground and an attention mask ($M_A$), which is then used to seamlessly blend the adjusted foreground back onto the original, high-quality background.

3. Foreground-Normalized MSE (FN-MSE)

Standard Mean Squared Error (MSE) loss is often biased toward the background. In cases where the foreground object is small, the model can achieve a low loss by simply doing nothing, as the already-correct background pixels dominate the calculation. FN-MSE addresses this by normalizing the error based on the area of the foreground object, forcing the model to prioritize the harmonization of small objects.

Datasets and Evaluation

The model was evaluated using the iHarmony4 dataset, the current gold standard for harmonization tasks. It includes four diverse sub-datasets:

  • HCOCO: Synthesized from COCO with category-specific color transfers.
  • HFlickr: Real-world images with manually segmented objects.
  • HAdobe5k: Professionally edited photos from the MIT-Adobe FiveK dataset.
  • Hday2night: Objects harmonized across different times of day.

Key Results

The iDIH-HRNet-W18 model established a new state-of-the-art across all primary metrics:

  • MSE Reduction: The model achieved an MSE of 22.15 on the combined iHarmony4 test set, a significant improvement over the previous DIH baseline (76.77) and DoveNet (52.36).
  • Visual Fidelity: Peak Signal-to-Noise Ratio (PSNR) reached 38.24 dB, indicating superior image quality.
  • Small Object Performance: The FN-MSE loss led to marked improvements in harmonizing objects that occupy less than 5% of the total image area.
  • Efficiency: By leveraging pre-trained weights, the model required only 13 hours of training on a single GPU, compared to over 100 hours for some competing architectures.

Conclusion

By incorporating semantic awareness into the harmonization process, the iDIH framework demonstrates that high-level object understanding is crucial for realistic image compositing. While the method currently depends on provided foreground masks and synthetic training data, it represents a major step forward in both performance and training efficiency for the field of computer vision.

Summary updated

BibTeX
@inproceedings{sofiiuk2021foreground,
  author = {Konstantin Sofiiuk and Polina Popenova and Anton Konushin},
  title = {{Foreground-aware Semantic Representations for Image Harmonization}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2021},
  doi = {10.1109/wacv48630.2021.00166},
}
Figure