threshold_adaptive
-
skimage.filters.threshold_adaptive(image, block_size, method='gaussian', offset=0, mode='reflect', param=None)
[source] -
Applies an adaptive threshold to an array.
Also known as local or dynamic thresholding where 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 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.
Returns: threshold : (N, M) ndarray
Thresholded binary image
References
[R197] http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html?highlight=threshold#adaptivethreshold Examples
>>> from skimage.data import camera >>> image = camera()[:50, :50] >>> binary_image1 = threshold_adaptive(image, 15, 'mean') >>> func = lambda arr: arr.mean() >>> binary_image2 = threshold_adaptive(image, 15, 'generic', param=func)
- ‘generic’: use custom function (see
Please login to continue.