code: def connected_components_reference_implementation(images):
      try:
          from scipy.ndimage import measurements
      except ImportError:
          logging.exception(
              "Skipping test method because scipy could not be loaded"
          )
          return
      image_or_images = np.asarray(images)
      if len(image_or_images.shape) == 2:
          images = image_or_images[None, :, :]
      elif len(image_or_images.shape) == 3:
          images = image_or_images
      components = np.asarray(
          [measurements.label(image)[0] for image in images]
      )
      # Get the count of nonzero ids for each image, and offset each image's nonzero
      # ids using the cumulative sum.
      num_ids_per_image = components.reshape(
          [-1, components.shape[1] * components.shape[2]]
      ).max(axis=-1)
      positive_id_start_per_image = np.cumsum(num_ids_per_image)
      for i in range(components.shape[0]):
          new_id_start = (
              positive_id_start_per_image[i - 1] if i > 0 else 0
          )
          components[i, components[i] > 0] += new_id_start
      if len(image_or_images.shape) == 2:
          return components[0, :, :]
      else:
          return components
  
file_path: addons/tensorflow_addons/image/tests/connected_components_test.py
imports: import pytest
  import logging
  import tensorflow
  import numpy
  from tensorflow_addons.image.connected_components import connected_components
label_desc: Use image node_id 10 for calling a global function with example usage: connected_components_reference_implementation(images) and returns: components, components