Skip to main content
. 2024 Apr 8;24(7):2371. doi: 10.3390/s24072371
Algorithm 2. Copy-Paste Objects from Multiple Images
Input:
   - ‘results’: Output of Algorithm 1
   - ‘fallen_person_imgs’: List of fallen person images
Output:
   - Augmented image
For eachbg_imginbg_imgsdo
   Initialize an ‘occlusion_mask’ to 0
   Iw, Ih = size of ‘bg_img’
   Open corresponding file in ‘bg_txts’, read lines into ‘bg_lines

   For eachbg_lineinbg_linesdo
      Update the corresponding ‘occlusion_mask’ to 255

   If the section changes, then
      Update ‘heightmax’, ‘widthmax’, ‘heightmin’, ‘widthmin’, ‘areamax
      Create a ‘bonnet’ mask with Grounded-SAM
   RoIratio=(Iwbboxmin_x) bboxmin_x(Iwbboxmax_x) bboxmax_x

   IfRoIratio’ > 0.5, then
      RoIratio=1RoIratio
      RoIthr=bonnetybboxmin_y * RoIratio+bboxmin_y

   For eachfallen_person_imginfallen_person_imgsdo
      Break if you encounter the maximum paste object value during the loop
      Create a ‘fallen person’ mask with the YOLOv8x-seg
      Adjust position and size for fallen person within RoI
      Randomly rotate ‘fallen person’ with a probability of 0.25
      Each ‘fallen person’ is flipped vertically and horizontally with a probability of 0.5
      ifocclusion_maskexists at the current position, then
         continue
      Paste a ‘fallen person’ into the background image
      Apply alpha blending

   Save the augmented image