code: def load_mosaic(self, index):
      """
      将四张图片拼接在一张马赛克图像中
      :param self:
      :param index: 需要获取的图像索引
      :return:
      """
      # loads images in a mosaic
  
      labels4 = []  # 拼接图像的label信息
      s = self.img_size
      # 随机初始化拼接图像的中心点坐标
      xc, yc = [
          int(random.uniform(s * 0.5, s * 1.5)) for _ in range(2)
      ]  # mosaic center x, y
      # 从dataset中随机寻找三张图像进行拼接
      indices = [index] + [
          random.randint(0, len(self.labels) - 1) for _ in range(3)
      ]  # 3 additional image indices
      # 遍历四张图像进行拼接
      for i, index in enumerate(indices):
          # load image
          img, _, (h, w) = load_image(self, index)
  
          # place img in img4
          if i == 0:  # top left
              # 创建马赛克图像
              img4 = np.full(
                  (s * 2, s * 2, img.shape[2]), 114, dtype=np.uint8
              )  # base image with 4 tiles
              # 计算马赛克图像中的坐标信息(将图像填充到马赛克图像中)
              x1a, y1a, x2a, y2a = (
                  max(xc - w, 0),
                  max(yc - h, 0),
                  xc,
                  yc,
              )  # xmin, ymin, xmax, ymax (large image)
              # 计算截取的图像区域信息(以xc,yc为第一张图像的右下角坐标填充到马赛克图像中，丢弃越界的区域)
              x1b, y1b, x2b, y2b = (
                  w - (x2a - x1a),
                  h - (y2a - y1a),
                  w,
                  h,
              )  # xmin, ymin, xmax, ymax (small image)
          elif i == 1:  # top right
              # 计算马赛克图像中的坐标信息(将图像填充到马赛克图像中)
              x1a, y1a, x2a, y2a = (
                  xc,
                  max(yc - h, 0),
                  min(xc + w, s * 2),
                  yc,
              )
              # 计算截取的图像区域信息(以xc,yc为第二张图像的左下角坐标填充到马赛克图像中，丢弃越界的区域)
              x1b, y1b, x2b, y2b = (
                  0,
                  h - (y2a - y1a),
                  min(w, x2a - x1a),
                  h,
              )
          elif i == 2:  # bottom left
              # 计算马赛克图像中的坐标信息(将图像填充到马赛克图像中)
              x1a, y1a, x2a, y2a = (
                  max(xc - w, 0),
                  yc,
                  xc,
                  min(s * 2, yc + h),
              )
              # 计算截取的图像区域信息(以xc,yc为第三张图像的右上角坐标填充到马赛克图像中，丢弃越界的区域)
              x1b, y1b, x2b, y2b = (
                  w - (x2a - x1a),
                  0,
                  max(xc, w),
                  min(y2a - y1a, h),
              )
          elif i == 3:  # bottom right
              # 计算马赛克图像中的坐标信息(将图像填充到马赛克图像中)
              x1a, y1a, x2a, y2a = (
                  xc,
                  yc,
                  min(xc + w, s * 2),
                  min(s * 2, yc + h),
              )
              # 计算截取的图像区域信息(以xc,yc为第四张图像的左上角坐标填充到马赛克图像中，丢弃越界的区域)
              x1b, y1b, x2b, y2b = (
                  0,
                  0,
                  min(w, x2a - x1a),
                  min(y2a - y1a, h),
              )
  
          # 将截取的图像区域填充到马赛克图像的相应位置
          img4[y1a:y2a, x1a:x2a] = img[
              y1b:y2b, x1b:x2b
          ]  # img4[ymin:ymax, xmin:xmax]
          # 计算pad(图像边界与马赛克边界的距离，越界的情况为负值)
          padw = x1a - x1b
          padh = y1a - y1b
  
          # Labels 获取对应拼接图像的labels信息
          # [class_index, x_center, y_center, w, h]
          x = self.labels[index]
          labels = x.copy()  # 深拷贝，防止修改原数据
          if x.size > 0:  # Normalized xywh to pixel xyxy format
              # 计算标注数据在马赛克图像中的坐标(绝对坐标)
              labels[:, 1] = w * (x[:, 1] - x[:, 3] / 2) + padw  # xmin
              labels[:, 2] = h * (x[:, 2] - x[:, 4] / 2) + padh  # ymin
              labels[:, 3] = w * (x[:, 1] + x[:, 3] / 2) + padw  # xmax
              labels[:, 4] = h * (x[:, 2] + x[:, 4] / 2) + padh  # ymax
          labels4.append(labels)
  
      # Concat/clip labels
      if len(labels4):
          labels4 = np.concatenate(labels4, 0)
          # 设置上下限防止越界
          np.clip(
              labels4[:, 1:], 0, 2 * s, out=labels4[:, 1:]
          )  # use with random_affine
  
      # Augment
      # 随机旋转，缩放，平移以及错切
      img4, labels4 = random_affine(
          img4,
          labels4,
          degrees=self.hyp["degrees"],
          translate=self.hyp["translate"],
          scale=self.hyp["scale"],
          shear=self.hyp["shear"],
          border=-s // 2,
      )  # border to remove
  
      return img4, labels4
  
imports: import math
  import os
  import random
  import shutil
  from pathlib import Path
  import cv2
  import numpy
  import torch
  from PIL import Image, ExifTags
  from torch.utils.data import Dataset
  from tqdm import tqdm
  from build_utils.utils import xyxy2xywh, xywh2xyxy
label_desc: Use image node_id 3 for calling a global function with example usage: load_mosaic(index) and returns: img4,  labels4