code: def dense_patch_slices(image_size, patch_size, scan_interval):
      """
      Enumerate all slices defining 2D/3D patches of size `patch_size` from an `image_size` input image.
      Args:
          image_size (tuple of int): dimensions of image to iterate over
          patch_size (tuple of int): size of patches to generate slices
          scan_interval (tuple of int): dense patch sampling interval
      Returns:
          a list of slice objects defining each patch
      """
      num_spatial_dims = len(image_size)
      if num_spatial_dims not in (2, 3):
          raise ValueError("image_size should has 2 or 3 elements")
  
      scan_num = [
          int(math.ceil(float(image_size[i]) / scan_interval[i]))
          if scan_interval[i] != 0
          else 1
          for i in range(num_spatial_dims)
      ]
      slices = []
      if num_spatial_dims == 3:
          for i in range(scan_num[0]):
              start_i = i * scan_interval[0]
              start_i -= max(start_i + patch_size[0] - image_size[0], 0)
              slice_i = slice(start_i, start_i + patch_size[0])
  
              for j in range(scan_num[1]):
                  start_j = j * scan_interval[1]
                  start_j -= max(
                      start_j + patch_size[1] - image_size[1], 0
                  )
                  slice_j = slice(start_j, start_j + patch_size[1])
  
                  for k in range(0, scan_num[2]):
                      start_k = k * scan_interval[2]
                      start_k -= max(
                          start_k + patch_size[2] - image_size[2], 0
                      )
                      slice_k = slice(start_k, start_k + patch_size[2])
                      slices.append((slice_i, slice_j, slice_k))
      else:
          for i in range(scan_num[0]):
              start_i = i * scan_interval[0]
              start_i -= max(start_i + patch_size[0] - image_size[0], 0)
              slice_i = slice(start_i, start_i + patch_size[0])
  
              for j in range(scan_num[1]):
                  start_j = j * scan_interval[1]
                  start_j -= max(
                      start_j + patch_size[1] - image_size[1], 0
                  )
                  slice_j = slice(start_j, start_j + patch_size[1])
                  slices.append((slice_i, slice_j))
      return slices
  
file_path: PaddleSeg/contrib/MedicalSeg/medicalseg/core/infer.py
imports: import collections.abc
  import paddle
  import paddle
  import paddle.nn.functional
  import math
label_desc: Use image node_id 4 for calling a global function with example usage: dense_patch_slices(image_size, patch_size, scan_interval) and returns: slices