multithreshold
result = multithreshold(x, levels)
Input: x, levels · Output: result
What it is
x is an Image, Signal, Vec, or scalar; levels is a Vec/matrix or tuple List of cut-point numbers (sorted ascending regardless of input order). Quantizes into len(levels)+1 bands at the given cut points. Image → posterized image of the same dimensions with evenly-spaced gray levels per band; Signal/plain numeric → raw 0-based band index.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = multithreshold(x, levels) | x Image, Signal, Vec, or scalarx is an Image, Signal, Vec, or scalar.levels Vec, matrix, List, or numberlevels is a Vec/matrix or tuple List of cut-point numbers (sorted ascending regardless of input order). | result Image, Signal, Vec, or Num | Returns the same kind of value x was: an Image from an Image, a same-Fs Signal from a Signal, and otherwise a Vec/Num of 0-based band indices. |
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
multithreshold(x, levels) — quantizes into len(levels)+1 bands at the given cut points (levels a Vec/matrix literal or a List of numbers, sorted ascending regardless of input order); see apply_multithreshold's doc comment for the per-kind output convention (0-based band index for Vec/Signal, evenly-spaced posterized gray levels for Image).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.