Learn R Programming

EBImage (version 4.14.2)

otsu: Calculate Otsu's threshold

Description

Returns a threshold value based on Otsu's method, which can be then used to reduce the grayscale image to a binary image.

Usage

otsu(x, range = c(0, 1), levels = 256)

Arguments

x
A Grayscale Image object or an array.
range
Numeric vector of length 2 specifying the histogram range used for thresholding.
levels
Number of grayscale levels.

Value

A vector of length equal to the total number of frames in x. Each vector element contains the Otsu's threshold value calculated for the corresponding image frame.

Details

Otsu's thresholding method [1] is useful to automatically perform clustering-based image thresholding. The algorithm assumes that the distribution of image pixel intensities follows a bi-modal histogram, and separates those pixels into two classes (e.g. foreground and background). The optimal threshold value is determined by minimizing the combined intra-class variance.

The threshold value is calculated for each image frame separately resulting in a output vector of length equal to the total number of frames in the image.

The default number of levels corresponds to the number of gray levels of an 8bit image. It is recommended to adjust this value according to the bit depth of the processed data, i.e. set levels to 2^16 = 65536 when working with 16bit images.

References

[1] Nobuyuki Otsu, "A threshold selection method from gray-level histograms". IEEE Trans. Sys., Man., Cyber. 9 (1): 62-66. doi:10.1109/TSMC.1979.4310076 (1979)

See Also

thresh

Examples

Run this code
  x = readImage(system.file("images", "sample.png", package="EBImage"))
  display(x)
  
  ## threshold using Otsu's method
  y = x > otsu(x)
  display(y)

Run the code above in your browser using DataLab