code: def thin(image, max_num_iter=None):
      """
      Perform morphological thinning of a binary image.
  
      Parameters
      ----------
      image : binary (M, N) ndarray
          The image to thin. If this input isn't already a binary image,
          it gets converted into one: In this case, zero values are considered
          background (False), nonzero values are considered foreground (True).
      max_num_iter : int, number of iterations, optional
          Regardless of the value of this parameter, the thinned image
          is returned immediately if an iteration produces no change.
          If this parameter is specified it thus sets an upper bound on
          the number of iterations performed.
  
      Returns
      -------
      out : ndarray of bool
          Thinned image.
  
      See Also
      --------
      skeletonize, medial_axis
  
      Notes
      -----
      This algorithm [1]_ works by making multiple passes over the image,
      removing pixels matching a set of criteria designed to thin
      connected regions while preserving eight-connected components and
      2 x 2 squares [2]_. In each of the two sub-iterations the algorithm
      correlates the intermediate skeleton image with a neighborhood mask,
      then looks up each neighborhood in a lookup table indicating whether
      the central pixel should be deleted in that sub-iteration.
  
      References
      ----------
      .. [1] Z. Guo and R. W. Hall, "Parallel thinning with
             two-subiteration algorithms," Comm. ACM, vol. 32, no. 3,
             pp. 359-373, 1989. :DOI:`10.1145/62065.62074`
      .. [2] Lam, L., Seong-Whan Lee, and Ching Y. Suen, "Thinning
             Methodologies-A Comprehensive Survey," IEEE Transactions on
             Pattern Analysis and Machine Intelligence, Vol 14, No. 9,
             p. 879, 1992. :DOI:`10.1109/34.161346`
  
      Examples
      --------
      >>> square = np.zeros((7, 7), dtype=bool)
      >>> square[1:-1, 2:-2] = 1
      >>> square[0, 1] =  1
      >>> square.view(np.uint8)
      array([[0, 1, 0, 0, 0, 0, 0],
             [0, 0, 1, 1, 1, 0, 0],
             [0, 0, 1, 1, 1, 0, 0],
             [0, 0, 1, 1, 1, 0, 0],
             [0, 0, 1, 1, 1, 0, 0],
             [0, 0, 1, 1, 1, 0, 0],
             [0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
      >>> skel = thin(square)
      >>> skel.view(np.uint8)
      array([[0, 1, 0, 0, 0, 0, 0],
             [0, 0, 1, 0, 0, 0, 0],
             [0, 0, 0, 1, 0, 0, 0],
             [0, 0, 0, 1, 0, 0, 0],
             [0, 0, 0, 1, 0, 0, 0],
             [0, 0, 0, 0, 0, 0, 0],
             [0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
      """
      # check that image is 2d
      check_nD(image, 2)
  
      # convert image to uint8 with values in {0, 1}
      skel = np.asanyarray(image, dtype=bool).view(np.uint8)
  
      # neighborhood mask
      mask = np.array(
          [[8, 4, 2], [16, 0, 1], [32, 64, 128]], dtype=np.uint8
      )
  
      # iterate until convergence, up to the iteration limit
      max_num_iter = max_num_iter or np.inf
      num_iter = 0
      n_pts_old, n_pts_new = np.inf, np.sum(skel)
      while n_pts_old != n_pts_new and num_iter < max_num_iter:
          n_pts_old = n_pts_new
  
          # perform the two "subiterations" described in the paper
          for lut in [G123_LUT, G123P_LUT]:
              # correlate image with neighborhood mask
              N = ndi.correlate(skel, mask, mode="constant")
              # take deletion decision from this subiteration's LUT
              D = np.take(lut, N)
              # perform deletion
              skel[D] = 0
  
          n_pts_new = np.sum(skel)  # count points after thinning
          num_iter += 1
  
      return skel.astype(bool)
  
file_path: scikit-image/skimage/morphology/_skeletonize.py
imports: import numpy
  from scipy import ndimage
  from .._shared.utils import check_nD
  from ..util import crop
  from ._skeletonize_3d_cy import _compute_thin_image
  from ._skeletonize_cy import _fast_skeletonize, _skeletonize_loop, _table_lookup_index
label_desc: Use image node_id 4 for calling a global function with example usage: thin(image, max_num_iter) and returns: skel