## 3 Method  
The aim of our work is a simple yet efficient SAM-based Copy-Paste data augmentation pipeline (see Figure 1) for the generation of synthetic training data for colony detection. The first step of the proposed pipeline involves segmenting and cutting out microbial colonies from real images to inpaint them onto new, empty agar dish images. To isolate individual colonies, we use the Segment Anything Model (SAM) [15]. The SAM is provided with the bounding box coordinates from the dataset annotations and is prompted to segment the region of the image within each bounding box. To ensure accurate class assignments for the cutout colonies, the extracted colonies are automatically sorted based on background brightness, colony class, and the intensity and color of the cutout. Colonies with artifacts (as can be seen in Figure 2b), such as visible background textures or poor segmentations, are discarded to maintain the quality of samples used for inpainting. For microbial clusters containing more than one colony, an overlap analysis is performed. The bounding boxes are processed sequentially, with each one checked for overlap with subsequent boxes. If overlap is detected, the overlapping boxes are merged into a single, larger bounding box. These new coordinates are then used to prompt SAM to segment the entire microbial cluster. The segmented clusters are sorted using the same criteria as the individual colonies to ensure consistency in quality. Figure 1: Overview of the proposed pipeline. First, colonies are segmented using a pre-trained and frozen Segment Anything Model [15]. Next, poor segmentations are filtered out to avoid introducing artifacts into the synthetic images. The segmented colonies are then inserted onto new, empty agar plates. Finally, YOLOv8 [48] is pre-trained on the synthetic data and fine-tuned on real data to achieve optimal accuracy. To create a synthetic agar dish, several parameters are randomly selected to ensure variability. These include the type of the background \(B\), the color intensity \(I\), and the hue \(H\) of the dish. Based on this, pre-sorted cutouts \(c\) of the colonies are selected from all the cutouts \(C\) so that they perfectly match the selected background for a realistic appearance. Figure 3 (center) provides an example where the colony blends seamlessly with the background, in contrast to Figure 3 (right), where there is a clear mismatch. To highlight the importance of adjusting the colony from the agar dish, Figure 3 (left) displays a real image for comparison. For each synthetic image, a random empty agar dish \(e\) is selected from a collection of multiple dishes \(E\). In the real dataset [4], typically up to two microbial species are inoculated on a dish. Therefore, a microbial species class is chosen at random, with a 50% chance that a second random species will be added to each dish for generation. Next, the number of microbial colonies to be generated (\(N\)) is randomly selected from a range of 1 to 100. If more than 100 colonies are used for data generation, there is a risk that the agar dish will be overfilled and unrealistic results will be obtained because there is not enough space for larger colonies. Microbial colony samples for pasting are randomly selected based on the color and intensity of the agar dish. Both the pseudo-annotations (bounding boxes) and the corresponding cutouts are used for further processing, with the bounding box dimensions matching the size of the cutout. For each microbial colony cutout \(c_{n}\), random coordinates are generated within the boundaries of the agar dish. Only coordinates that ensure no  
Figure 3: Examples of generated data (f.l.t.r. ): real image from the AGAR dataset, generated image where the colonies match the background, and generated image where the colonies do not match the background. Figure 2: Examples of good and bad segmentations of colonies from the AGAR dataset [4] with SAM [15]. overlap with the bounding boxes of previously placed colonies are selected.