code: def dc(result, reference):
      r"""
      Dice coefficient
  
      Computes the Dice coefficient (also known as Sorensen index) between the binary
      objects in two images.
  
      The metric is defined as
  
      .. math::
  
          DC=\frac{2|A\cap B|}{|A|+|B|}
  
      , where :math:`A` is the first and :math:`B` the second set of samples (here: binary objects).
  
      Parameters
      ----------
      result : array_like
          Input data containing objects. Can be any type but will be converted
          into binary: background where 0, object everywhere else.
      reference : array_like
          Input data containing objects. Can be any type but will be converted
          into binary: background where 0, object everywhere else.
  
      Returns
      -------
      dc : float
          The Dice coefficient between the object(s) in ```result``` and the
          object(s) in ```reference```. It ranges from 0 (no overlap) to 1 (perfect overlap).
  
      Notes
      -----
      This is a real metric. The binary images can therefore be supplied in any order.
      """
      result = numpy.atleast_1d(result.astype(numpy.bool_))
      reference = numpy.atleast_1d(reference.astype(numpy.bool_))
  
      intersection = numpy.count_nonzero(result & reference)
  
      size_i1 = numpy.count_nonzero(result)
      size_i2 = numpy.count_nonzero(reference)
  
      try:
          dc = 2.0 * intersection / float(size_i1 + size_i2)
      except ZeroDivisionError:
          dc = 1.0
  
      return dc
  
imports: import numpy
  from scipy.ndimage import _ni_support
  from scipy.ndimage import distance_transform_edt, binary_erosion, generate_binary_structure
  from scipy.ndimage import label, find_objects
  from scipy.stats import pearsonr
label_desc: Use image node_id 1 for calling a global function with example usage: dc(result, reference) and returns: dc