skimage 0.17.2

ParametersReturnsBackRef
threshold_local(image, block_size, method='gaussian', offset=0, mode='reflect', param=None, cval=0)

Also known as adaptive or dynamic thresholding. The threshold value is the weighted mean for the local neighborhood of a pixel subtracted by a constant. Alternatively the threshold can be determined dynamically by a given function, using the 'generic' method.

Parameters

image : (N, M) ndarray

Input image.

block_size : int

Odd size of pixel neighborhood which is used to calculate the threshold value (e.g. 3, 5, 7, ..., 21, ...).

method : {'generic', 'gaussian', 'mean', 'median'}, optional

Method used to determine adaptive threshold for local neighbourhood in weighted mean image.

  • 'generic': use custom function (see param parameter)

  • 'gaussian': apply gaussian filter (see param parameter for custom sigma value)

  • 'mean': apply arithmetic mean filter

  • 'median': apply median rank filter

By default the 'gaussian' method is used.

offset : float, optional

Constant subtracted from weighted mean of neighborhood to calculate the local threshold value. Default offset is 0.

mode : {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional

The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'. Default is 'reflect'.

param : {int, function}, optional

Either specify sigma for 'gaussian' method or function object for 'generic' method. This functions takes the flat array of local neighbourhood as a single argument and returns the calculated threshold for the centre pixel.

cval : float, optional

Value to fill past edges of input if mode is 'constant'.

Returns

threshold : (N, M) ndarray

Threshold image. All pixels in the input image higher than the corresponding pixel in the threshold image are considered foreground.

Compute a threshold mask image based on local pixel neighborhood.

Examples

This example is valid syntax, but we were not able to check execution
>>> from skimage.data import camera
... image = camera()[:50, :50]
... binary_image1 = image > threshold_local(image, 15, 'mean')
... func = lambda arr: arr.mean()
... binary_image2 = image > threshold_local(image, 15, 'generic',
...  param=func)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

skimage.filters.thresholding.threshold_local

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /skimage/filters/thresholding.py#143
type: <class 'function'>
Commit: