code: def test_rand_index():
      numpy.random.seed(310)
      i, j = numpy.mgrid[0:10, 0:20]
      #
      # Create a labeling with two objects 0:10, 0:5 and 0:10, 15:20.
      # The background class is 0:10, 5:15
      #
      ground_truth = (j < 5) | (j >= 15)
      #
      # Add a 3x4 square in the middle
      #
      test = ground_truth.copy()
      test[4:7, 8:12] = True
      #
      # I used R to generate the rand index and adjusted rand index
      # of the two segmentations: a 10 x 5 rectangle, a 10x10 background
      # and a 10x5 rectangle with 12 pixels that disagree in the middle
      #
      # The rand index is from rand.index in the fossil package and
      # the adjusted rand index is from cluster.stats in the fpc package.
      # There's an adjusted rand index in the fossil package but it gives
      # the wrong numbers (!!!!)
      #
      expected_rand_index = 0.9469347
      expected_adj_rand_index = 0.8830027
      workspace, module = make_workspace(
          dict(image=ground_truth), dict(image=test)
      )
      module.run(workspace)
      measurements = workspace.measurements
      mname = "_".join(
          (
              cellprofiler.modules.measureimageoverlap.C_IMAGE_OVERLAP,
              cellprofiler.modules.measureimageoverlap.FTR_RAND_INDEX,
              TEST_IMAGE_NAME,
          )
      )
      assert (
          round(
              abs(
                  measurements.get_current_image_measurement(mname)
                  - expected_rand_index
              ),
              6,
          )
          == 0
      )
      mname = "_".join(
          (
              cellprofiler.modules.measureimageoverlap.C_IMAGE_OVERLAP,
              cellprofiler.modules.measureimageoverlap.FTR_ADJUSTED_RAND_INDEX,
              TEST_IMAGE_NAME,
          )
      )
      assert (
          round(
              abs(
                  measurements.get_current_image_measurement(mname)
                  - expected_adj_rand_index
              ),
              6,
          )
          == 0
      )
  
imports: import io
  import numpy
  import numpy.random
  import numpy.testing
  import scipy.ndimage
  import cellprofiler_library.opts.measureimageoverlap
  import cellprofiler_core.image
  import cellprofiler_core.measurement
  import cellprofiler_core.module
  import cellprofiler_core.object
  import cellprofiler_core.pipeline
  import cellprofiler_core.preferences
  import cellprofiler_core.workspace
  from cellprofiler_core.constants.measurement import COLTYPE_FLOAT
  import cellprofiler.modules.measureimageoverlap
  import tests.frontend.modules
label_desc: Use image node_id 15 for calling a global function with example usage: test_rand_index() without return types