Qu

kapur_threshold

Builtin index · Images

result = kapur_threshold(x)

Input: x · Output: result

What it is

x is an Image, Vec, or Signal. Same "compute, don't apply" shape as otsu_threshold, but using Kapur's entropy-maximizing criterion instead of Otsu's between-class variance — tends to handle unequal class sizes better.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = kapur_threshold(x)
x Image, Vec, or Signalnot documented yet
result number
Returns a single threshold number.

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)
output
[30.625, 135.46875] 130.3125 4 4 4
a synthetic field with one bright patch

from images

How it works

kapur_threshold(x) — same shape as otsu_threshold but using Kapur's entropy-maximizing criterion instead of Otsu's between-class variance (see qu_core::threshold:: kapur_threshold's doc comment for why this is a genuinely different, information-theoretic alternative rather than a second name for the same computation — it tends to handle unequal class sizes better than Otsu's variance criterion).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.