adaptive_threshold
result = adaptive_threshold(image, block_size=, [method="mean"], [offset=0])
Input: image, block_size, method, offset · Output: result
What it is
image is an Image; block_size is a required odd positive integer, the side length of the per-pixel neighborhood. Locally adaptive, unlike threshold/otsu above: each pixel's own threshold is mean(neighborhood) - offset, where the neighborhood mean is a uniform box average (method="mean") or a Gaussian-weighted one (method="gaussian"). Binarized with the same >= convention as threshold.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = adaptive_threshold(image, block_size=, [method="mean"], [offset=0]) | image Imageimage is an Image.block_size —block_size is a required odd positive integer, the side length of the per-pixel neighborhood.method optional (default "mean")Locally adaptive, unlike threshold/otsu above: each pixel's own threshold is mean(neighborhood) - offset, where the neighborhood mean is a uniform box average (method="mean") or a Gaussian-weighted one (method="gaussian").offset optional (default 0)Locally adaptive, unlike threshold/otsu above: each pixel's own threshold is mean(neighborhood) - offset, where the neighborhood mean is a uniform box average (method="mean") or a Gaussian-weighted one (method="gaussian"). | result Image | Returns a binary Image of the same dimensions. |
Examples
No documentation example calls this form yet. The Images chapter is where one belongs.
How it works
threshold pass, 2026-09-24). threshold/otsu/multi_otsu/ kapur_threshold above are all GLOBAL — one histogram, one scalar cut for the whole image, which can't binarize an image whose background brightness drifts across the frame. These three compute a per-pixel threshold (or, for clahe, a per-pixel remapping) from each pixel's own local neighborhood instead. See image::Image::adaptive_threshold/ for the algorithms; these arms are just the argument parsing. adaptive_threshold(image, block_size=, [method="mean"], [offset=0]) — OpenCV-style adaptive threshold: local mean(neighborhood) - offset per pixel (method="mean": uniform box mean; "gaussian": Gaussian-weighted mean). block_size is a required keyword (must be odd) — no positional form, since "the 2nd argument is a block size" is easy to confuse with otsu-family builtins whose 2nd argument is a threshold LEVEL, not a window size.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.