code: def crop_labels_and_image(labels, image):
      """Crop a labels matrix and an image to the lowest common size
  
      labels - a n x m labels matrix
      image - a 2-d or 3-d image
  
      Assumes that points outside of the common boundary should be masked.
      """
      min_dim1 = min(labels.shape[0], image.shape[0])
      min_dim2 = min(labels.shape[1], image.shape[1])
  
      if labels.ndim == 3:  # volume
          min_dim3 = min(labels.shape[2], image.shape[2])
  
          if image.ndim == 4:  # multichannel volume
              return (
                  labels[:min_dim1, :min_dim2, :min_dim3],
                  image[:min_dim1, :min_dim2, :min_dim3, :],
              )
  
          return (
              labels[:min_dim1, :min_dim2, :min_dim3],
              image[:min_dim1, :min_dim2, :min_dim3],
          )
  
      if image.ndim == 3:  # multichannel image
          return (
              labels[:min_dim1, :min_dim2],
              image[:min_dim1, :min_dim2, :],
          )
  
      return labels[:min_dim1, :min_dim2], image[:min_dim1, :min_dim2]
  
imports: import matplotlib.cm
  import numpy
  import skimage.color
  from ...preferences import get_default_colormap
label_desc: Use image node_id 1 for calling a global function with example usage: crop_labels_and_image(labels, image) and returns: labels,  image, labels,  image, labels,  image, labels,  image