code: def perimeter(bwimage, n=4, mode="constant"):
      """
      p = perimeter(bwimage, n=4, mode="constant")
  
      Calculate total perimeter of all objects in binary image.
  
      Parameters
      ----------
      bwimage : array
          binary image
      n : int, optional
          passed to ``bwperim`` as is
      mode : str, optional
          passed to ``bwperim`` as is
  
      Returns
      -------
      p : float
          total perimeter of all objects in binary image
  
      See Also
      --------
      bwperim : function
          Finds the perimeter region
  
      References
      ----------
      .. [1] K. Benkrid, D. Crookes. Design and FPGA Implementation of
             a Perimeter Estimator. The Queen's University of Belfast.
             https://www.cs.qub.ac.uk/~d.crookes/webpubs/papers/perimeter.doc
      """
      global _perimeter_values
      perim = bwperim(bwimage, n, mode)
      perim = perim.astype(np.uint8, copy=False)
  
      histogram = mh.fullhistogram(mh.convolve(perim, _perimeter_magic))
  
      if _perimeter_values is None:
          _perimeter_values = np.zeros(34, float)
          _perimeter_values[[5, 7, 15, 17, 25, 27]] = 1
          _perimeter_values[[21, 33]] = np.sqrt(2)
          _perimeter_values[[13, 23]] = (1 + np.sqrt(2)) / 2
  
      size = min(34, len(histogram))
      return np.dot(histogram[:size], _perimeter_values[:size])
  
imports: from __future__ import division
  import numpy
  from .morph import get_structuring_elem
  from .None import _labeled
  from .internal import _get_output
  from ._filters import _checked_mode2int
  import mahotas
label_desc: Use image node_id 16 for calling a global function with example usage: perimeter(bwimage, n, mode) and returns: np