TopNet: Transformer-Based Object Placement Network for Image Compositing

Sijie Zhu, Zhe Lin, Scott Cohen, Jason Kuen, Zhifei Zhang, Chen Chen

Abstract

Image compositing requires determining the optimal location and scale for an object within a background image to ensure visual realism. Traditional methods often struggle with the trade-off between computational efficiency and the ability to capture local scene context. This paper presents TopNet, a Transformer-based architecture that treats object placement as a dense prediction task. By correlating global object features with local background patches, TopNet generates a 3D heatmap of plausible placements in a single forward pass. Experimental results demonstrate that TopNet achieves a significant performance leap, improving Mean IoU from 0.448 to 0.620 while operating over 10 times faster than previous state-of-the-art dense methods.

1. Introduction

Image compositing—the process of inserting an object from one image into another—is a fundamental task in photo editing and creative design. The primary challenge lies in determining the "where" and "how big": placing an object in a way that respects the scene's geometry, perspective, and semantic logic. An incorrectly placed object, such as a car floating in the sky or a dog larger than a house, immediately breaks the illusion of reality.

Existing approaches to this problem generally fall into two categories. Sparse prediction models attempt to regress a few candidate bounding boxes. While fast, these models often rely on global image features and overlook critical local cues, such as the presence of a flat surface. Conversely, sliding-window evaluation models treat placement as a classification task, exhaustively checking every possible location and scale. While more thorough, this approach is computationally prohibitive for real-time applications. TopNet bridges this gap by providing a dense, multi-modal prediction framework that is both context-aware and highly efficient.

2. Methodology

2.1 Architecture Overview

TopNet introduces a dense prediction formulation for object placement. The architecture is built upon three core components:

  • Dual Encoders: The model utilizes two separate encoders (either CNN or Vision Transformer based). One encoder extracts global features from the object to be inserted, while the other extracts local patch tokens from the background image.
  • Transformer Module: At the heart of TopNet is a multi-layer Transformer that performs cross-attention between the global object feature and every local background patch. This allows the model to correlate the object's identity with specific scene details—for instance, recognizing that a "boat" object should be associated with "water" patches.
  • Upsampling Decoder: The correlated features are processed by a decoder to produce a 3D heatmap. The dimensions of this heatmap ($H \times W \times S$) represent the horizontal position, vertical position, and scale of the object, respectively.

2.2 Sparse Contrastive Loss

A significant challenge in training placement models is the sparsity of ground-truth data; most training images provide only one "correct" placement. Standard regression losses would penalize other equally valid locations. To address this, the authors proposed a Sparse Contrastive Loss. This loss function encourages high scores at the ground-truth location and low scores at known "bad" locations (identified through sampling), while remaining agnostic toward other potentially valid peaks in the heatmap. This allows the model to learn multiple plausible placement regions.

3. Datasets and Evaluation

The model was evaluated using two primary benchmarks:

  1. Pixabay Dataset: A large-scale self-supervised dataset comprising approximately 928,000 images. The authors used the LaMa inpainting model to remove existing objects, using the original locations as ground truth for training.
  2. Object Placement Assessment (OPA): A benchmark of 62,000 images with human-annotated labels, used to evaluate how well the model's predictions align with human perceptions of realism.

4. Key Results and Insights

4.1 Performance and Efficiency

TopNet demonstrates a substantial improvement over existing methods. On the Pixabay dataset, it achieved a Mean IoU of 0.620, compared to the previous state-of-the-art (GALA) at 0.448. Furthermore, TopNet is over 10 times faster than previous dense methods, enabling its use in interactive creative tools where users require near-instant feedback.

4.2 The Importance of Local Cues

The success of TopNet underscores the necessity of local context. By using a Transformer to cross-reference object features with local background patches, the model can identify subtle cues like floor textures or perspective lines that are essential for realistic placement.

4.3 Multi-modal Suggestions

Unlike regression-based models that output a single coordinate, TopNet’s heatmap approach acknowledges that there is rarely only one "right" answer. The model can suggest multiple candidate regions, and because it generates a dense map, it can instantly update recommendations if a user manually adjusts the scale or moves the object to a specific area.

5. Limitations and Future Work

While TopNet represents a significant advancement, it currently focuses on 2D constraints (x, y, and scale). It does not explicitly account for 3D rotation, perspective warping, or complex occlusions (e.g., placing an object behind a foreground element). Additionally, the model does not yet model environmental consistency factors such as lighting, shadows, or reflections. Future research may integrate 3D scene understanding and lighting estimation to further enhance the seamlessness of AI-assisted compositions.

6. Conclusion

TopNet provides a robust and efficient solution for the object placement problem in image compositing. By leveraging a Transformer-based dense prediction strategy, it achieves superior accuracy and speed, offering a practical path forward for intelligent, interactive photo editing tools.

Summary updated

BibTeX
@inproceedings{zhu2023topnet,
  author = {Sijie Zhu and Zhe Lin and Scott Cohen and Jason Kuen and Zhifei Zhang and Chen Chen},
  title = {{TopNet: Transformer-Based Object Placement Network for Image Compositing}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2023},
}
Figure