Calculate Otsu's threshold
Returns a threshold value based on Otsu's method, which can be then used to reduce the grayscale image to a binary image.
otsu(x, range = c(0, 1), levels = 256)
x |
A |
range |
Numeric vector of length 2 specifying the histogram range used for thresholding. |
levels |
Number of grayscale levels. |
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.
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.
Philip A. Marais philipmarais@gmail.com, Andrzej Oles andrzej.oles@embl.de, 2014
[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)
x = readImage(system.file("images", "sample.png", package="EBImage")) display(x) ## threshold using Otsu's method y = x > otsu(x) display(y)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.