Image.otsu#

Image.otsu(nbins: int = 256) Any[source]#

Otsu threshold selection

Parameters:

nbins (int, optional) – number of bins for histogram computation, defaults to 256

Returns:

Otsu’s threshold

Return type:

scalar

Compute the optimal threshold for binarizing an image with a bimodal intensity histogram. t is a scalar threshold that maximizes the variance between the classes of pixels below and above the threshold t.

Example:

>>> from machinevisiontoolbox import Image
>>> img = Image.Read('street.png')
>>> img.otsu()
np.float64(116.044921875)

Note

  • Converts a color image to greyscale.

  • Implementation gives slightly different result to MATLAB Machine Vision Toolbox.

  • Works for greyscale integer and floating-point images.

References:
  • A Threshold Selection Method from Gray-Level Histograms, N. Otsu. IEEE Trans. Systems, Man and Cybernetics Vol SMC-9(1), Jan 1979, pp 62-66.

  • An improved method for image thresholding on the valley-emphasis method. H-F Ng, D. Jargalsaikhan etal. Signal and Info Proc. Assocn. Annual Summit and Conf (APSIPA). 2013. pp1-4

  • P. Corke, Robotics, Vision & Control for Python, Springer, 2023, Section 12.1.1.

Seealso:

triangle threshold threshold_interactive threshold_adaptive