multi_otsu
result = multi_otsu(x, n_classes)
Input: x, n_classes · Output: result
What it is
x is an Image, Vec, or Signal; n_classes is a positive integer, the desired number of intensity classes. The n_classes - 1-threshold generalization of otsu_threshold.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = multi_otsu(x, n_classes) | x Image, Vec, or Signalx is an Image, Vec, or Signal.n_classes numbern_classes is a positive integer, the desired number of intensity classes. | result Vec | Returns a Vec of n_classes - 1 cut points in ascending order. Compose with multithreshold(x, multi_otsu(x, n)) to segment into n classes. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
m = [10, 20, 30, 220; 15, 25, 200, 230; 120, 130, 210, 225; 125, 135, 205, 215]
img = image_from_matrix(m)
seg = otsu(img) # compute Otsu's level and apply it
imshow(seg)
cuts = multi_otsu(img, 3) # two cut points -> three bands
banded = multithreshold(img, cuts)
imshow(banded)
k = kapur_threshold(img) # entropy-based single threshold
fg = foreground_mask(img, k, radius=1) # threshold + speck cleanup
print(cuts, k, seg.width, banded.width, fg.width)
[30.625, 135.46875] 130.3125 4 4 4
from images
How it works
multi_otsu(x, n_classes) — the n_classes-1-threshold generalization of otsu_threshold, returned as a Vec in ascending order (mirrors otsu_threshold's "compute, don't apply" contract; compose with multithreshold(x, multi_otsu(x, n)) to actually segment).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.