skimage2.filters.threshold_otsu#

skimage2.filters.threshold_otsu(image=None, nbins=256, *, hist=None)[source]#

Return threshold value based on Otsu’s method.

Either image or hist must be provided. If hist is provided, the actual histogram of the image is ignored.

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

Grayscale input image.

nbinsint, optional

Number of bins used to calculate histogram. This value is ignored for integer arrays.

histarray, or 2-tuple of arrays, optional

Histogram from which to determine the threshold, and optionally a corresponding array of bin center intensities. If no hist provided, this function will compute it from the image.

Returns:
thresholdfloat

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

Notes

The input image must be grayscale.

References

Examples

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