skimage2.filters.threshold_li#

skimage2.filters.threshold_li(image, *, tolerance=None, initial_guess=None, iter_callback=None)[source]#

Compute threshold value by Li’s iterative Minimum Cross Entropy method.

Parameters:
image(M, N[, …]) ndarray

Grayscale input image.

tolerancefloat, optional

Finish the computation when the change in the threshold in an iteration is less than this value. By default, this is half the smallest difference between intensity values in image.

initial_guessfloat or Callable[[array[float]], float], optional

Li’s iterative method uses gradient descent to find the optimal threshold. If the image intensity histogram contains more than two modes (peaks), the gradient descent could get stuck in a local optimum. An initial guess for the iteration can help the algorithm find the globally-optimal threshold. A float value defines a specific start point, while a callable should take in an array of image intensities and return a float value. Example valid callables include numpy.mean (default), lambda arr: numpy.quantile(arr, 0.95), or even skimage.filters.threshold_otsu().

iter_callbackCallable[[float], Any], optional

A function that will be called on the threshold at every iteration of the algorithm.

Returns:
thresholdfloat

Upper threshold value. All pixels with an intensity higher than this value are assumed to be foreground.

References

[1]

Li C.H. and Lee C.K. (1993) “Minimum Cross Entropy Thresholding” Pattern Recognition, 26(4): 617-625 DOI:10.1016/0031-3203(93)90115-D

[2]

Li C.H. and Tam P.K.S. (1998) “An Iterative Algorithm for Minimum Cross Entropy Thresholding” Pattern Recognition Letters, 18(8): 771-776 DOI:10.1016/S0167-8655(98)00057-9

[3]

Sezgin M. and Sankur B. (2004) “Survey over Image Thresholding Techniques and Quantitative Performance Evaluation” Journal of Electronic Imaging, 13(1): 146-165 DOI:10.1117/1.1631315

[4]

ImageJ AutoThresholder code, http://fiji.sc/wiki/index.php/Auto_Threshold

Examples

>>> from _skimage2.data import camera
>>> image = camera()
>>> thresh = threshold_li(image)
>>> binary = image > thresh