code: def find_label_overlaps(parent_labels, child_labels, validate=True):
      """
      Find per pixel overlap of parent labels and child labels
  
      'parent_labels' - the parents which contain the children in 'labels' format
      'child_labels' - the children to be mapped to a parent in 'labels' format
  
      Returns a sparse 'coo_matrix' of overlap between each parent and child.
      Note that the first row and column are empty, as these
      correspond to parent and child labels of 0.
      """
      if validate:
          _validate_labels(parent_labels)
          _validate_labels(child_labels)
  
      parent_count = np.max(parent_labels)
      child_count = np.max(child_labels)
      #
      # If the labels are different shapes, crop to shared shape.
      #
      common_shape = np.minimum(parent_labels.shape, child_labels.shape)
  
      if parent_labels.ndim == 3:
          parent_labels = parent_labels[
              0 : common_shape[0],
              0 : common_shape[1],
              0 : common_shape[2],
          ]
          child_labels = child_labels[
              0 : common_shape[0],
              0 : common_shape[1],
              0 : common_shape[2],
          ]
      else:
          parent_labels = parent_labels[
              0 : common_shape[0], 0 : common_shape[1]
          ]
          child_labels = child_labels[
              0 : common_shape[0], 0 : common_shape[1]
          ]
  
      #
      # Only look at points that are labeled in parent and child
      #
      not_zero = (parent_labels > 0) & (child_labels > 0)
      not_zero_count = np.sum(not_zero)
  
      #
      # each row (axis = 0) is a parent
      # each column (axis = 1) is a child
      #
      return scipy.sparse.coo_matrix(
          (
              np.ones((not_zero_count,)),
              (parent_labels[not_zero], child_labels[not_zero]),
          ),
          shape=(parent_count + 1, child_count + 1),
      )
  
imports: from enum import Enum
  import numpy
  from numpy.random.mtrand import RandomState
  import scipy.sparse
  import centrosome.index
label_desc: Use image node_id 24 for calling a global function with example usage: find_label_overlaps(parent_labels, child_labels, validate) and returns: scipy