skimage2.filters.threshold_multiotsu#
- skimage2.filters.threshold_multiotsu(image=None, classes=3, nbins=256, *, hist=None)[source]#
Generate
classes-1 threshold values to divide gray levels inimage, following Otsu’s method for multiple classes.The threshold values are chosen to maximize the total sum of pairwise variances between the thresholded graylevel classes. See Notes and [1] for more details.
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.
- classesint, optional
Number of classes to be thresholded, i.e. the number of resulting regions.
- nbinsint, optional
Number of bins used to calculate the 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 (see notes).
- Returns:
- thresharray
Array containing the threshold values for the desired classes.
- Raises:
- ValueError
If
imagecontains less grayscale value then the desired number of classes.
Notes
This implementation relies on a Cython function whose complexity is \(O\left(\frac{Ch^{C-1}}{(C-1)!}\right)\), where \(h\) is the number of histogram bins and \(C\) is the number of classes desired.
If no hist is given, this function will make use of
skimage.exposure.histogram, which behaves differently thannp.histogram. While both allowed, use the former for consistent behaviour.The input image must be grayscale.
References
[1]Liao, P-S., Chen, T-S. and Chung, P-C., “A fast algorithm for multilevel thresholding”, Journal of Information Science and Engineering 17 (5): 713-727, 2001. Available at: <https://ftp.iis.sinica.edu.tw/JISE/2001/200109_01.pdf> DOI:10.6688/JISE.2001.17.5.1
[2]Tosa, Y., “Multi-Otsu Threshold”, a java plugin for ImageJ. Available at: <http://imagej.net/plugins/download/Multi_OtsuThreshold.java>
Examples
>>> from _skimage2.color import label2rgb >>> from _skimage2 import data >>> image = data.camera() >>> thresholds = threshold_multiotsu(image) >>> regions = np.digitize(image, bins=thresholds) >>> regions_colorized = label2rgb(regions)