code: def filter_labeled(
      labeled, remove_bordering=False, min_size=None, max_size=None
  ):
      """Filter labeled regions based on a series of conditions
  
      .. versionadded :: 1.4.1
  
      Parameters
      ----------
      labeled : labeled array
      remove_bordering : bool, optional
          whether to remove regions that touch the border
      min_size : int, optional
          Minimum size (in pixels) of objects to keep (default is no minimum)
      max_size : int, optional
          Maximum size (in pixels) of objects to keep (default is no maximum)
  
      Returns
      -------
      filtered : labeled array
      nr : int
          number of new labels
      """
      from mahotas.labeled import remove_regions, labeled_size
  
      labeled = _as_labeled(labeled, labeled, "filter_labeled")
      if remove_bordering:
          labeled = mh.labeled.remove_bordering(labeled)
          labeled, nr = mh.labeled.relabel(labeled)
      else:
          nr = labeled.max()
  
      to_keep = np.ones(nr + 1, bool)
  
      if min_size is not None or max_size is not None:
          sizes = labeled_size(labeled)
          if min_size:
              to_keep &= sizes >= min_size
          if max_size:
              to_keep &= sizes <= max_size
      to_keep[0] = True
      to_remove = np.where(~to_keep)
      labeled = remove_regions(labeled, to_remove)
      labeled, nr = mh.labeled.relabel(labeled, inplace=True)
      return labeled, nr
  
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 18 for calling a global function with example usage: filter_labeled(labeled, remove_bordering, min_size, max_size) and returns: labeled,  nr