{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / filters / thresholding / threshold_niblack

function

skimage.filters.thresholding:threshold_niblack

source: /dev/scikit-image/src/skimage/filters/thresholding.py :1060

Signature

def   threshold_niblack ( image window_size = 15 k = 0.2 )

Summary

Applies Niblack local threshold to an array.

Extended Summary

A threshold T is calculated for every pixel in the image using the following formula

T = m(x,y) - k * s(x,y)

where m(x,y) and s(x,y) are the mean and standard deviation of pixel (x,y) neighborhood defined by a rectangular window with size w times w centered around the pixel. k is a configurable parameter that weights the effect of standard deviation.

Parameters

image : (M, N[, ...]) ndarray

Grayscale input image.

window_size : int, or iterable of int, optional

Window size specified as a single odd integer (3, 5, 7, …), or an iterable of length image.ndim containing only odd integers (e.g. (1, 5, 5)).

k : float, optional

Value of parameter k in threshold formula.

Returns

threshold : (M, N[, ...]) ndarray

Threshold mask. All pixels with an intensity higher than this value are assumed to be foreground.

Notes

This algorithm is originally designed for text recognition.

The Bradley threshold is a particular case of the Niblack one, being equivalent to

>>> from skimage import data
>>> image = data.page()
>>> q = 1
>>> threshold_image = threshold_niblack(image, k=0) * q

for some value q. By default, Bradley and Roth use q=1.

Examples

from skimage import data
image = data.page()
threshold_image = threshold_niblack(image, window_size=7, k=0.1)

Aliases

  • skimage.filters.threshold_niblack