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.
Input image.
Odd size of pixel neighborhood which is used to calculate the threshold value (e.g. 3, 5, 7, ..., 21, ...).
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.
Constant subtracted from weighted mean of neighborhood to calculate the local threshold value. Default offset is 0.
The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'. Default is 'reflect'.
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.
Value to fill past edges of input if mode is 'constant'.
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.
>>> from skimage.data import cameraSee :
... 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)
The following pages refer to to this document either explicitly or contain code examples using this.
skimage.filters.thresholding.threshold_local
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