code: def clip_big_image(image_path, clip_save_dir, args, to_label=False):
      image = cv2.imread(image_path)
  
      h, w, c = image.shape
      clip_size = args.clip_size
      stride_size = args.stride_size
  
      num_rows = (
          math.ceil((h - clip_size) / stride_size)
          if math.ceil((h - clip_size) / stride_size) * stride_size
          + clip_size
          >= h
          else math.ceil((h - clip_size) / stride_size) + 1
      )
      num_cols = (
          math.ceil((w - clip_size) / stride_size)
          if math.ceil((w - clip_size) / stride_size) * stride_size
          + clip_size
          >= w
          else math.ceil((w - clip_size) / stride_size) + 1
      )
  
      x, y = np.meshgrid(
          np.arange(num_cols + 1), np.arange(num_rows + 1)
      )
      xmin = x * clip_size
      ymin = y * clip_size
  
      xmin = xmin.ravel()
      ymin = ymin.ravel()
      xmin_offset = np.where(
          xmin + clip_size > w,
          w - xmin - clip_size,
          np.zeros_like(xmin),
      )
      ymin_offset = np.where(
          ymin + clip_size > h,
          h - ymin - clip_size,
          np.zeros_like(ymin),
      )
      boxes = np.stack(
          [
              xmin + xmin_offset,
              ymin + ymin_offset,
              np.minimum(xmin + clip_size, w),
              np.minimum(ymin + clip_size, h),
          ],
          axis=1,
      )
  
      if to_label:
          color_map = np.array(
              [
                  [255, 255, 255],
                  [255, 0, 0],
                  [255, 255, 0],
                  [0, 255, 0],
                  [0, 255, 255],
                  [0, 0, 255],
                  [0, 0, 0],
              ]
          )
          flatten_v = np.matmul(
              image.reshape(-1, c), np.array([2, 3, 4]).reshape(3, 1)
          )
          out = np.zeros_like(flatten_v)
          for idx, class_color in enumerate(color_map):
              value_idx = np.matmul(
                  class_color, np.array([2, 3, 4]).reshape(3, 1)
              )
              if idx == 6:
                  out[flatten_v == value_idx] = 255
              else:
                  out[flatten_v == value_idx] = idx
          image = out.reshape(h, w)
  
      for box in boxes:
          start_x, start_y, end_x, end_y = box
          clipped_image = (
              image[start_y:end_y, start_x:end_x]
              if to_label
              else image[start_y:end_y, start_x:end_x, :]
          )
          idx_i, idx_j = osp.basename(image_path).split("_")[2:4]
          cv2.imwrite(
              osp.join(
                  clip_save_dir,
                  f"{idx_i}_{idx_j}_{start_x}_{start_y}_{end_x}_{end_y}.png",
              ),
              clipped_image.astype(np.uint8),
          )
  
file_path: PaddleSeg/contrib/RSSegBenchmark/data/prepare_potsdam.py
imports: import argparse
  import glob
  import math
  import os
  import os.path
  import tempfile
  import zipfile
  import cv2
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: clip_big_image(image_path, clip_save_dir, args, to_label) without return types