code: def get_patch_crop_coords(img, patch_size, min_overlap=30):
      """
  
      _:param img (y, x, (z))
      _:param patch_size: list of len 2 (2D) or 3 (3D).
      _:param min_overlap: minimum required overlap of patches.
      If too small, some areas are poorly represented only at edges of single patches.
      _:return ndarray: shape (n_patches, 2*dim). crop coordinates for each patch.
      """
      crop_coords = []
      for dim in range(len(img.shape)):
          n_patches = int(np.ceil(img.shape[dim] / patch_size[dim]))
  
          # no crops required in this dimension, add image shape as coordinates.
          if n_patches == 1:
              crop_coords.append([(0, img.shape[dim])])
              continue
  
          # fix the two outside patches to coords patchsize/2 and interpolate.
          center_dists = (img.shape[dim] - patch_size[dim]) / (
              n_patches - 1
          )
  
          if (patch_size[dim] - center_dists) < min_overlap:
              n_patches += 1
              center_dists = (img.shape[dim] - patch_size[dim]) / (
                  n_patches - 1
              )
  
          patch_centers = np.round(
              [
                  (patch_size[dim] / 2 + (center_dists * ii))
                  for ii in range(n_patches)
              ]
          )
          dim_crop_coords = [
              (
                  center - patch_size[dim] / 2,
                  center + patch_size[dim] / 2,
              )
              for center in patch_centers
          ]
          crop_coords.append(dim_crop_coords)
  
      coords_mesh_grid = []
      for ymin, ymax in crop_coords[0]:
          for xmin, xmax in crop_coords[1]:
              if len(crop_coords) == 3 and patch_size[2] > 1:
                  for zmin, zmax in crop_coords[2]:
                      coords_mesh_grid.append(
                          [ymin, ymax, xmin, xmax, zmin, zmax]
                      )
              elif len(crop_coords) == 3 and patch_size[2] == 1:
                  for zmin in range(img.shape[2]):
                      coords_mesh_grid.append(
                          [ymin, ymax, xmin, xmax, zmin, zmin + 1]
                      )
              else:
                  coords_mesh_grid.append([ymin, ymax, xmin, xmax])
      return np.array(coords_mesh_grid).astype(int)
  
file_path: medicaldetectiontoolkit/utils/dataloader_utils.py
imports: import numpy
  import os
  from multiprocessing import Pool
label_desc: Use image node_id 2 for calling a global function with example usage: get_patch_crop_coords(img, patch_size, min_overlap) and returns: np