code: def get_per_object_threshold(method, image, threshold, mask=None, labels=None,
                               threshold_range_min = None,
                               threshold_range_max = None,
                               **kwargs):
      
      if labels is None:
          labels = np.ones(image.shape,int)
          if not mask is None:
              labels[np.logical_not(mask)] = 0 
      label_extents = scipy.ndimage.find_objects(labels,np.max(labels))
      local_threshold = np.ones(image.shape,image.dtype)
      for i, extent in enumerate(label_extents, start=1):
          label_mask = labels[extent]==i
          if not mask is None:
              label_mask = np.logical_and(mask[extent], label_mask)
          values = image[extent]
          per_object_threshold = get_global_threshold(
              method, values, mask = label_mask, **kwargs)
          local_threshold[extent][label_mask] = per_object_threshold
      return local_threshold
docs: Return a matrix giving threshold per pixel calculated per-object
      
      image - image to be thresholded
      mask  - mask out "don't care" pixels
      labels - a label mask indicating object boundaries
      threshold - the global threshold