code: def superpixels(
      image: np.ndarray,
      n_segments: int,
      replace_samples: Sequence[bool],
      max_size: Optional[int],
      interpolation: int,
  ) -> np.ndarray:
      if not np.any(replace_samples):
          return image
  
      orig_shape = image.shape
      if max_size is not None:
          size = max(image.shape[:2])
          if size > max_size:
              scale = max_size / size
              height, width = image.shape[:2]
              new_height, new_width = int(height * scale), int(
                  width * scale
              )
              resize_fn = _maybe_process_in_chunks(
                  cv2.resize,
                  dsize=(new_width, new_height),
                  interpolation=interpolation,
              )
              image = resize_fn(image)
  
      segments = skimage.segmentation.slic(
          image,
          n_segments=n_segments,
          compactness=10,
          channel_axis=-1 if image.ndim > 2 else None,
      )
  
      min_value = 0
      max_value = MAX_VALUES_BY_DTYPE[image.dtype]
      image = np.copy(image)
      if image.ndim == 2:
          image = image.reshape(*image.shape, 1)
      nb_channels = image.shape[2]
      for c in range(nb_channels):
          # segments+1 here because otherwise regionprops always misses the last label
          regions = skimage.measure.regionprops(
              segments + 1, intensity_image=image[..., c]
          )
          for ridx, region in enumerate(regions):
              # with mod here, because slic can sometimes create more superpixel than requested.
              # replace_samples then does not have enough values, so we just start over with the first one again.
              if replace_samples[ridx % len(replace_samples)]:
                  mean_intensity = region.mean_intensity
                  image_sp_c = image[..., c]
  
                  if image_sp_c.dtype.kind in ["i", "u", "b"]:
                      # After rounding the value can end up slightly outside of the value_range. Hence, we need to clip.
                      # We do clip via min(max(...)) instead of np.clip because
                      # the latter one does not seem to keep dtypes for dtypes with large itemsizes (e.g. uint64).
                      value: Union[int, float]
                      value = int(np.round(mean_intensity))
                      value = min(max(value, min_value), max_value)
                  else:
                      value = mean_intensity
  
                  image_sp_c[segments == ridx] = value
  
      if orig_shape != image.shape:
          resize_fn = _maybe_process_in_chunks(
              cv2.resize,
              dsize=(orig_shape[1], orig_shape[0]),
              interpolation=interpolation,
          )
          image = resize_fn(image)
  
      return image
  
imports: from __future__ import division
  from typing import Optional, Sequence, Union
  from warnings import warn
  import cv2
  import numpy
  import skimage
  from albumentations import random_utils
  from albumentations.augmentations.utils import MAX_VALUES_BY_DTYPE, _maybe_process_in_chunks, clip, clipped, ensure_contiguous, is_grayscale_image, is_rgb_image, non_rgb_warning, preserve_channel_dim, preserve_shape
label_desc: Use image node_id 56 for calling a global function with example usage: superpixels(image, n_segments, replace_samples, max_size, interpolation) and returns: image, image