Manuscript Offprint
arXiv:2611.03455Bg-Mix: On Using Image Backgrounds for Data Augmentation in Electron Microscopy Images
ABSTRACT
Electron microscopy (EM) serves as a cornerstone in virology enabling the visualization of viral particles and is widely used in research, diagnostics and morphological characterization of pathogens. Computer-assisted image analysis can help facilitate and speed up this labor-intensive method, however, typical EM virus datasets are small and sparsely labeled, resulting in a lack of readily available deep learning models due to training limitations. To overcome data shortages and leverage content-rich, diverse sample backgrounds, we employed background-based data augmentation. To this end, we propose Bg-Mix, a form of data augmentation method, which decomposes training images into foreground objects and backgrounds and subsequently rearranges both into novel augmented images. This not only enhances the performance of object detection models but also increases the diversity of the training data. Using Bg-Mix provides an increase between +0.8 and +3.3 box mean average precision (mAP) points over the baseline when tested across two datasets using two architectures, thereby demonstrating its effectiveness.
Keywords Data Augmentation · Object Detection · Electron Microscopy
1 Introduction
Negative-staining Scanning-Transmission/Transmission Electron Microscopy (STEM/TEM) of clinical samples can help diagnose unknown and emerging infections [1]. Recognizing virus particles in those images, however, requires expert knowledge: viruses must be differentiated from debris and cell material, and morphologically similar viruses must be distinguished from one another. Automated virus detection can reduce the workload of experts by alleviating the need for labor-intensive manual analysis, while potentially enabling faster and more accurate diagnoses.
In light of the rise of deep learning methods in imaging and microscopy data availability, a myriad of models for object detection/instance segmentation [2, 3] and classification [4, 5] have been developed over the past decade. Still, biomedical imaging datasets remain costly to acquire and particularly time-consuming to annotate, often resulting in limited dataset availability and size. Several strategies have been proposed to address these limitations, including transfer learning [6], synthetic image generation [7], and data augmentation [8]. In this work, we focus on the latter strategy, which is particularly well suited to negative-staining STEM/TEM images because of their content-rich backgrounds.
In recent years, several methods have been proposed for data augmentation: In the Copy-Paste method [9], objects are cut from a random training image and pasted at random on another training image. The model in [10] learns the kind of background each class appears on and pastes objects only where the background fits. In [11] the labeled objects are kept intact and only the background is synthetically generated by using diffusion models [12].
All of the above works use large numbers of natural training images, for example from the COCO dataset [13]. However, STEM/TEM datasets are often limited in size, typically comprising only a few hundred annotations, making data augmentation particularly valuable for supervised learning approaches.
*Corresponding authors: {srivastavaa, koerbern}@rki.de

Figure 1: Bg-Mix. The background of a random training image (a) and the foreground objects of another random training image (b) are extracted and blended to form the background-augmented image (c).
Here, we propose Bg-Mix, a data augmentation method where segmented objects are extracted from one training image, an object-free background is extracted from another one and both are subsequently rearranged into a new augmented training image. We thus make use of the rich and diverse negative-stained STEM/TEM backgrounds without the need to either learn them or generate them artificially. We tested three ways to obtain object-free backgrounds, two ways to blend the object's edges and six ways to place the foreground objects. We evaluate on two public negative-stained STEM/TEM virus datasets with two model architectures including an ablation study on different Bg-Mix modes and compare with the previously described Copy-Paste method.
2.1 Overview
Bg-Mix randomly extracts foreground objects and object-free backgrounds from training images in a given dataset and subsequently mixes them back together to form new training samples (cf. Fig. 1).
2.2 Background Extraction
From a randomly drawn training image, the background is extracted in one of the following three ways:
A. Selecting the largest object-free square in the image and resizing it back to the image size,
B. Removing its objects using segmentation masks and setting the pixels of the mask to zero,
C. Removing its objects using segmentation masks and applying biharmonic inpainting [14], which fills the mask by smooth interpolation based on the surrounding pixel values.
2.3 Object Blending
Bg-Mix incorporates two modes to blend extracted foreground objects and backgrounds:
D. Hard edges: The foreground objects are pasted onto the background as they are,
E. Blurred edges: The pasted foreground objects' boundaries are blurred using a Gaussian kernel of size with standard deviation .
2.4 Object Placement
We consider six object placement methods depending on the foreground, background and the placement order:
F. Foreground objects from one image, hence one class, are pasted onto a background from any class at their original positions,
G. Foreground objects from one image, hence one class, are pasted onto a background from the same class at their original positions,
H. Foreground objects from multiple images of a single class are pasted onto a background from any class at random non-overlapping positions,
I. Foreground objects from multiple images of a single class are pasted onto a background from the same class at random non-overlapping positions,
J. Foreground objects from multiple images of any class are pasted onto a background from any class at random non-overlapping positions,
K. At least one foreground object from each class is pasted onto a background from any class at random non-overlapping positions.
3 Experiments
3.1 Datasets
For virus segmentation, we utilized two publicly available datasets in this study. In both datasets, each image contains objects of only one class, which enabled us to use class-matched backgrounds for experiments.
The EMViR dataset [15] contains 1084 negative-staining STEM images with segmentation masks of four classes of respiratory viruses (Adeno, Corona, Orthomyxo and Paramyxo), split into 762 training, 157 validation and 165 test images.
The virus dataset of [16], abbreviated VISN in the following, contains 622 negative-staining TEM images with segmentation masks of six virus classes (SARS-CoV-2, H1N1, Respiratory syncytial, Herpes simplex, Adeno and Vaccinia), divided into 499 training and 123 test images.
As pre-processing steps, (1) the EMViR object masks were converted to COCO json annotations to match the VISN format, (2) a VISN validation set was created from a stratified 15% of the original training set, and (3) all images across both datasets were resized to pixels and their annotations were rescaled proportionally.
3.2 Training
We evaluated Bg-Mix on both datasets with two object detection/instance segmentation architectures: Mask R-CNN [2] with a ResNet-50-FPN backbone and RTMDet-Ins-L [3]. Both models were initialized with weights pretrained on COCO [13], implemented using the MMDetection toolbox [17] and fine-tuned on each dataset. We kept each architecture's published optimizer and learning rate schedule and extended it to 500 epochs: SGD with momentum 0.9
Table 1: Mask R-CNN and RTMDet-Ins models with Copy-Paste and Bg-Mix on EMViR and VISN datasets. The brackets show the change from the first row of the same block. is the probability with which Copy-Paste or Bg-Mix was applied to a training image ( for EMViR; for VISN). Best results are shown in bold.
| Model | EMViRbox mAP | VISNbox mAP |
|---|---|---|
| Mask R-CNN | 55.7 | 77.7 |
| + Copy-Paste () | 55.5 (-0.2) | 75.9 (-1.8) |
| + Bg-Mix () | 58.3 (+2.6) | 78.5 (+0.8) |
| RTMDet-Ins | 54.5 | 57.9 |
| + Copy-Paste () | 56.7 (+2.2) | 60.5 (+2.6) |
| + Bg-Mix () | 57.8 (+3.3) | 58.7 (+0.8) |
Table 2: Ablation study of Bg-Mix on the EMViR dataset with Mask R-CNN: all combinations of background extraction, blending and object placement methods. All runs except baseline use . Best setup is shown in bold.
| Run | Extraction | Blending | Placement | box mAP | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| A | B | C | D | E | F | G | H | I | J | K | |||
| Baseline | - | - | - | 55.7 | |||||||||
| 1 | ✓ | ✓ | ✓ | 57.7 (+2.0) | |||||||||
| 2 | ✓ | ✓ | ✓ | 57.0 (+1.3) | |||||||||
| 3 | ✓ | ✓ | ✓ | 57.9 (+2.2) | |||||||||
| 4 | ✓ | ✓ | ✓ | 57.5 (+1.8) | |||||||||
| 5 | ✓ | ✓ | ✓ | 58.3 (+2.6) | |||||||||
| 6 | ✓ | ✓ | ✓ | 57.6 (+1.9) | |||||||||
| 7 | ✓ | ✓ | ✓ | 56.1 (+0.4) | |||||||||
| 8 | ✓ | ✓ | ✓ | 56.7 (+1.0) | |||||||||
| 9 | ✓ | ✓ | ✓ | 56.7 (+1.0) | |||||||||
| 10 | ✓ | ✓ | ✓ | 57.1 (+1.4) | |||||||||
| 11 | ✓ | ✓ | ✓ | 56.7 (+1.0) | |||||||||
| 12 | ✓ | ✓ | ✓ | 58.1 (+2.4) | |||||||||
| 13 | ✓ | ✓ | ✓ | 55.9 (+0.2) | |||||||||
| 14 | ✓ | ✓ | ✓ | 53.8 (-1.9) | |||||||||
| 15 | ✓ | ✓ | ✓ | 58.0 (+2.3) | |||||||||
| 16 | ✓ | ✓ | ✓ | 55.7 (±0.0) | |||||||||
| 17 | ✓ | ✓ | ✓ | 56.5 (+0.8) | |||||||||
| 18 | ✓ | ✓ | ✓ | 56.4 (+0.7) | |||||||||
| 19 | ✓ | ✓ | ✓ | 55.7 (±0.0) | |||||||||
| 20 | ✓ | ✓ | ✓ | 55.7 (±0.0) | |||||||||
| 21 | ✓ | ✓ | ✓ | 57.0 (+1.3) | |||||||||
| 22 | ✓ | ✓ | ✓ | 56.6 (+0.9) | |||||||||
| 23 | ✓ | ✓ | ✓ | 55.7 (±0.0) | |||||||||
| 24 | ✓ | ✓ | ✓ | 57.2 (+1.5) | |||||||||
| 25 | ✓ | ✓ | ✓ | 56.6 (+0.9) | |||||||||
| 26 | ✓ | ✓ | ✓ | 56.0 (+0.3) | |||||||||
| 27 | ✓ | ✓ | ✓ | 54.3 (-1.4) | |||||||||
| 28 | ✓ | ✓ | ✓ | 56.0 (+0.3) | |||||||||
| 29 | ✓ | ✓ | ✓ | 58.1 (+2.4) | |||||||||
| 30 | ✓ | ✓ | ✓ | 55.4 (-0.3) | |||||||||
| 31 | ✓ | ✓ | ✓ | 57.8 (+2.1) | |||||||||
| 32 | ✓ | ✓ | ✓ | 55.9 (+0.2) | |||||||||
| 33 | ✓ | ✓ | ✓ | 57.8 (+2.1) | |||||||||
| 34 | ✓ | ✓ | ✓ | 57.5 (+1.8) | |||||||||
| 35 | ✓ | ✓ | ✓ | 56.3 (+0.6) | |||||||||
| 36 | ✓ | ✓ | ✓ | 56.9 (+1.2) | |||||||||
and weight decay , with the learning rate divided by 10 at epochs 333 and 458, for Mask R-CNN, and AdamW with weight decay 0.05 and cosine decay from epoch 250 for RTMDet-Ins. With a uniform batch size of 8, we scaled the published learning rates linearly: from 0.02 (batch size 16) to 0.01 for Mask R-CNN, and from 0.004 (batch size 256) to for RTMDet-Ins.
Bg-Mix was applied independently to each training image with probability , so the number of training images per epoch stayed fixed. To observe the effect of Bg-Mix alone, no other augmentation was used. We compared Bg-Mix using the same architectures without augmentation (baseline) and with Copy-Paste [9], the latter applied with the same probability as Bg-Mix: on EMViR and on VISN. This choice was made based on our observation that for the EMViR dataset, increased performance, but for the VISN dataset, decreased the performance. We evaluated on the validation set every 10 epochs and kept the checkpoint with the best validation box mAP for testing. All runs were averaged over three random seeds.
3.3 Results
Bg-Mix obtained the largest gain on the EMViR dataset for both architectures (+2.6 and +3.3 box mAP) (cf. Table 1). For the VISN dataset, Bg-Mix had a small increase (+0.8 and +0.8 box mAP) for both models. The small increase for Bg-Mix (and the corresponding decrease for Copy-Paste) for the Mask R-CNN architecture and the VISN dataset can be attributed to the already saturated baseline (77.7 box mAP).
From the ablation study involving the Mask R-CNN architecture and the EMViR dataset (cf. Table 2), we observe the following, reporting gains of box mAP in points averaged over all runs using the corresponding option: (1) Background Extraction: inpainting (+1.2) and zeroing the object pixels (+1.1) perform best, (2) Blending: hard edges are slightly better than blurred edges (+1.1 vs. +0.8), and (3) Object Placement: original objects at their original positions work best (+2.0). The best run combines inpainting, hard edges and original placement (run 5, 58.3 box mAP); the same setting is used for Bg-Mix in cf. Table 1.
4 Conclusion
This study describes Bg-Mix, a novel background augmentation method for virus detection in negative-staining STEM/TEM images: it extracts the objects from one training image, the object-free background from another and pastes the extracted objects onto this extracted background.
Compared to the baseline, the performance of models improved significantly by incorporating the Bg-Mix method. Our study is limited to object detection of viruses in EM images, however, we believe our findings can be transferred to other modalities with target objects on content-rich backgrounds.
5 Compliance with ethical standards
This study uses publicly available electron microscopy datasets of virus particles produced in vitro (EMViR [15], VISN [16]). No ethical approval was required.
6 Acknowledgments
Conflicts of Interest: This work was supported by institutional funding from Robert Koch Institute. The authors received no specific third-party grants or external financial support for this research.
References
[1] Cynthia S Goldsmith and Sara E Miller, “Modern uses of electron microscopy for detection of viruses,” Clinical microbiology reviews, vol. 22, no. 4, pp. 552–563, 2009.
[2] Kaiming He, Georgia Gkioxari, Piotr Dollár, and Ross Girshick, “Mask r-cnn,” in Proceedings of the IEEE international conference on computer vision, 2017, pp. 2961–2969.
[3] Chengqi Lyu, Wenwei Zhang, Haian Huang, Yue Zhou, Yudong Wang, Yanyi Liu, Shilong Zhang, and Kai Chen, “Rtmdet: An empirical study of designing real-time object detectors,” arXiv preprint arXiv:2212.07784, 2022.
[4] Fei Wang, Mengqing Jiang, Chen Qian, Shuo Yang, Cheng Li, Honggang Zhang, Xiaogang Wang, and Xiaou Tang, “Residual attention network for image classification,” in 2017 IEEE conference on computer vision and pattern recognition (CVPR). IEEE, 2017, pp. 6450–6458.
[5] Sanghyun Woo, Shoubhik Debnath, Ronghang Hu, Xinlei Chen, Zhuang Liu, In So Kweon, and Saining Xie, “Convnext v2: Co-designing and scaling convnets with masked autoencoders,” in 2023 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR). Ieee, 2023, pp. 16133–16142.
[6] Padmavathi Kora, Chui Ping Ooi, Oliver Faust, U Raghavendra, Anjan Gudigar, Wai Yee Chan, K Meenakshi, K Swaraja, Pawel Plawiak, and U Rajendra Acharya, “Transfer learning techniques for medical image analysis: A review,” Biocybernetics and biomedical engineering, vol. 42, no. 1, pp. 79–107, 2022.
[7] Lennart R Koetzier, Jie Wu, Domenico Mastrodicasa, Aline Lutz, Matthew Chung, W Adam Koszek, Jayanth Pratap, Akshay S Chaudhari, Pranav Rajpurkar, Matthew P Lungren, et al., “Generating synthetic data for medical imaging,” Radiology, vol. 312, no. 3, pp. e232471, 2024.
[8] Evgin Goceri, “Medical image data augmentation: techniques, comparisons and interpretations: E. goceri,” Artificial intelligence review, vol. 56, no. 11, pp. 12561–12605, 2023.
[9] Golnaz Ghiasi, Yin Cui, Aravind Srinivas, Rui Qian, Tsung-Yi Lin, Ekin D Cubuk, Quoc V Le, and Barret Zoph, "Simple copy-paste is a strong data augmentation method for instance segmentation," in 2021 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR). IEEE, 2021, pp. 2917–2927.
[10] Liuying Zhang, Zhiqiang Xing, and Xikun Wang, "Background instance-based copy-paste data augmentation for object detection," Electronics, vol. 12, no. 18, pp. 3781, 2023.
[11] Yuhang Li, Xin Dong, Chen Chen, Weiming Zhuang, and Lingjuan Lyu, "A simple background augmentation method for object detection with diffusion model," in European Conference on Computer Vision. Springer, 2024, pp. 462–479.
[12] Cheng Lu, Yuhao Zhou, Fan Bao, Jianfei Chen, Chongxuan Li, and Jun Zhu, "Dpm-solver++: Fast solver for guided sampling of diffusion probabilistic models," Machine Intelligence Research, vol. 22, no. 4, pp. 730–751, 2025.
[13] Tsung-Yi Lin, Michael Maire, Serge Belongie, James Hays, Pietro Perona, Deva Ramanan, Piotr Dollár, and C Lawrence Zitnick, "Microsoft coco: Common objects in context," in European conference on computer vision. Springer, 2014, pp. 740–755.
[14] Steven B Damelin and Nguyen S Hoang, "On surface completion and image inpainting by biharmonic functions: Numerical aspects," International Journal of Mathematics and Mathematical Sciences, vol. 2018, no. 1, pp. 3950312, 2018.
[15] Paula Klimczok, Abdul Omar, Michael Laue, and Nils Körber, "Emvir-electron microscopy image dataset of labelled respiratory viruses for deep learning model development," in 2025 IEEE 22nd International Symposium on Biomedical Imaging (ISBI). IEEE, 2025, pp. 1–5.
[16] Chi Xiao, Jun Wang, Shenrong Yang, Minxin Heng, Junyi Su, Hao Xiao, Jingdong Song, and Weifu Li, "Visn: virus instance segmentation network for tem images using deep attention transformer," Briefings in Bioinformatics, vol. 24, no. 6, pp. bbad373, 2023.
[17] Kai Chen, Jiaqi Wang, Jiangmiao Pang, Yuhang Cao, Yu Xiong, Xiaoxiao Li, Shuyang Sun, Wansen Feng, Ziwei Liu, Jiarui Xu, et al., "Mmdetection: Open mmlab detection toolbox and benchmark," arXiv preprint arXiv:1906.07155, 2019.