code: def get_global_threshold(
      image,
      mask=None,
      threshold_method="otsu",
      threshold_min=0,
      threshold_max=1,
      threshold_correction_factor=1,
      assign_middle_to_foreground="foreground",
      log_transform=False,
      **kwargs,
  ):
      if log_transform:
          image, conversion_dict = centrosome.threshold.log_transform(
              image
          )
  
      if mask is not None:
          # Apply mask and discard masked pixels
          image = image[mask]
  
      # Shortcuts - Check if image array is empty or all pixels are the same value.
      if len(image) == 0:
          threshold = 0.0
      elif numpy.all(image == image.ravel()[0]):
          # All pixels are the same value
          threshold = image.ravel()[0]
  
      elif threshold_method.casefold() in (
          "minimum_cross_entropy",
          "sauvola",
      ):
          tol = max(
              numpy.min(numpy.diff(numpy.unique(image))) / 2,
              0.5 / 65536,
          )
          threshold = skimage.filters.threshold_li(image, tolerance=tol)
      elif threshold_method.casefold() == "robust_background":
          threshold = get_threshold_robust_background(image, **kwargs)
      elif threshold_method.casefold() == "otsu":
          threshold = skimage.filters.threshold_otsu(image)
      elif threshold_method.casefold() == "multiotsu":
          bin_wanted = (
              0
              if assign_middle_to_foreground.casefold() == "foreground"
              else 1
          )
          kwargs["nbins"] = (
              kwargs["nbins"] if "nbins" in kwargs else 128
          )
          threshold = skimage.filters.threshold_multiotsu(
              image, **kwargs
          )
          threshold = threshold[bin_wanted]
      else:
          raise NotImplementedError(
              f"Threshold method {threshold_method} not supported."
          )
  
      if log_transform:
          threshold = centrosome.threshold.inverse_log_transform(
              threshold, conversion_dict
          )
  
      threshold *= threshold_correction_factor
      threshold = min(max(threshold, threshold_min), threshold_max)
      return threshold
  
imports: import numpy
  import skimage.color
  import skimage.morphology
  import centrosome
  import centrosome.threshold
  import scipy
  import matplotlib
label_desc: Use image node_id 15 for calling a global function with example usage: get_global_threshold(image, mask, threshold_method, threshold_min, threshold_max, threshold_correction_factor, assign_middle_to_foreground, log_transform) and returns: threshold