code: def gbernsen(f, se, contrast_threshold, gthresh):
      """
      thresholded = gbernsen(f, se, contrast_threshold, gthresh)
  
      Generalised Bernsen local thresholding
  
      Parameters
      ----------
      f : ndarray
          input image
      se : boolean ndarray
          structuring element to use for "locality"
      contrast_threshold : integer
          contrast threshold
      gthresh : numeric, optional
          global threshold to fall back in low contrast regions
  
      Returns
      -------
      thresholded : binary ndarray
  
      See Also
      --------
      bernsen : function
          Bernsen thresholding with a circular region
      """
      from mahotas.convolve import rank_filter
  
      fmax = rank_filter(f, se, se.sum() - 1)
      fmin = rank_filter(f, se, 0)
      fptp = fmax - fmin
      fmean = (
          fmax / 2.0 + fmin / 2.0
      )  # Do not use (fmax + fmin) as that may overflow
      return np.choose(
          fptp < contrast_threshold, (fmean < gthresh, fmean > f)
      )
  
file_path: mahotas/mahotas/thresholding.py
imports: from __future__ import division
  import numpy
  from .histogram import fullhistogram
  from .None import _histogram
  from .internal import _verify_is_integer_type
label_desc: Use image node_id 5 for calling a global function with example usage: gbernsen(f, se, contrast_threshold, gthresh) and returns: np