Module: filter

LPIFilter2D

class skimage.filter.LPIFilter2D(impulse_response, **filter_params)

Bases: object

Linear Position-Invariant Filter (2-dimensional)

__init__(impulse_response, **filter_params)
Parameters:

impulse_response : callable f(r, c, **filter_params)

Function that yields the impulse response. r and c are 1-dimensional vectors that represent row and column positions, in other words coordinates are (r[0],c[0]),(r[0],c[1]) etc. **filter_params are passed through.

In other words, impulse_response would be called like this:

>>> def impulse_response(r, c, **filter_params):
...     pass
>>>
>>> r = [0,0,0,1,1,1,2,2,2]
>>> c = [0,1,2,0,1,2,0,1,2]
>>> filter_params = {'kw1': 1, 'kw2': 2, 'kw3': 3}
>>> impulse_response(r, c, **filter_params)

Examples

Gaussian filter: Use a 1-D gaussian in each direction without normalization coefficients. >>> def filt_func(r, c, sigma = 1): ... return np.exp(-np.hypot(r, c)/sigma) >>> filter = LPIFilter2D(filt_func)

deprecated

class skimage.filter.deprecated(alt_func=None, behavior='warn')

Bases: object

Decorator to mark deprecated functions with warning.

Adapted from <http://wiki.python.org/moin/PythonDecoratorLibrary>.

Parameters:

alt_func : str

If given, tell user what function to use instead.

behavior : {‘warn’, ‘raise’}

Behavior during call to deprecated function: ‘warn’ = warn user that function is deprecated; ‘raise’ = raise error.

__init__(alt_func=None, behavior='warn')
skimage.filter.canny(image[, sigma, ...]) Edge filter an image using the Canny algorithm.
skimage.filter.denoise_bilateral(*args, **kwargs) Deprecated function. Use skimage.restoration.denoise_bilateral instead.
skimage.filter.denoise_tv_bregman(*args, ...) Deprecated function. Use skimage.restoration.denoise_tv_bregman instead.
skimage.filter.denoise_tv_chambolle(*args, ...) Deprecated function. Use skimage.restoration.denoise_tv_chambolle instead.
skimage.filter.gabor_filter(image, frequency) Return real and imaginary responses to Gabor filter.
skimage.filter.gabor_kernel(frequency[, ...]) Return complex 2D Gabor filter kernel.
skimage.filter.gaussian_filter(image, sigma) Multi-dimensional Gaussian filter
skimage.filter.hprewitt(image[, mask]) Find the horizontal edges of an image using the Prewitt transform.
skimage.filter.hscharr(image[, mask]) Find the horizontal edges of an image using the Scharr transform.
skimage.filter.hsobel(image[, mask]) Find the horizontal edges of an image using the Sobel transform.
skimage.filter.inverse(data[, ...]) Apply the filter in reverse to the given data.
skimage.filter.prewitt(image[, mask]) Find the edge magnitude using the Prewitt transform.
skimage.filter.rank_order(image) Return an image of the same shape where each pixel is the index of the pixel value in the ascending order of the unique values of image, aka the rank-order value.
skimage.filter.roberts(image[, mask]) Find the edge magnitude using Roberts’ cross operator.
skimage.filter.roberts_negative_diagonal(image) Find the cross edges of an image using the Roberts’ Cross operator.
skimage.filter.roberts_positive_diagonal(image) Find the cross edges of an image using Roberts’ cross operator.
skimage.filter.scharr(image[, mask]) Find the edge magnitude using the Scharr transform.
skimage.filter.sobel(image[, mask]) Find the edge magnitude using the Sobel transform.
skimage.filter.threshold_adaptive(image, ...) Applies an adaptive threshold to an array.
skimage.filter.threshold_isodata(image[, nbins]) Return threshold value based on ISODATA method.
skimage.filter.threshold_otsu(image[, nbins]) Return threshold value based on Otsu’s method.
skimage.filter.threshold_yen(image[, nbins]) Return threshold value based on Yen’s method.
skimage.filter.vprewitt(image[, mask]) Find the vertical edges of an image using the Prewitt transform.
skimage.filter.vscharr(image[, mask]) Find the vertical edges of an image using the Scharr transform.
skimage.filter.vsobel(image[, mask]) Find the vertical edges of an image using the Sobel transform.
skimage.filter.wiener(data[, ...]) Minimum Mean Square Error (Wiener) inverse filter.

canny

skimage.filter.canny(image, sigma=1.0, low_threshold=None, high_threshold=None, mask=None)

Edge filter an image using the Canny algorithm.

Parameters:

image : 2D array

Greyscale input image to detect edges on; can be of any dtype.

sigma : float

Standard deviation of the Gaussian filter.

low_threshold : float

Lower bound for hysteresis thresholding (linking edges). If None, low_threshold is set to 10% of dtype’s max.

high_threshold : float

Upper bound for hysteresis thresholding (linking edges). If None, high_threshold is set to 20% of dtype’s max.

mask : array, dtype=bool, optional

Mask to limit the application of Canny to a certain area.

Returns:

output : 2D array (image)

The binary edge map.

See also

skimage.sobel

Notes

The steps of the algorithm are as follows:

  • Smooth the image using a Gaussian with sigma width.
  • Apply the horizontal and vertical Sobel operators to get the gradients within the image. The edge strength is the norm of the gradient.
  • Thin potential edges to 1-pixel wide curves. First, find the normal to the edge at each point. This is done by looking at the signs and the relative magnitude of the X-Sobel and Y-Sobel to sort the points into 4 categories: horizontal, vertical, diagonal and antidiagonal. Then look in the normal and reverse directions to see if the values in either of those directions are greater than the point in question. Use interpolation to get a mix of points instead of picking the one that’s the closest to the normal.
  • Perform a hysteresis thresholding: first label all points above the high threshold as edges. Then recursively label any point above the low threshold that is 8-connected to a labeled point as an edge.

References

Canny, J., A Computational Approach To Edge Detection, IEEE Trans. Pattern Analysis and Machine Intelligence, 8:679-714, 1986

William Green’s Canny tutorial http://dasl.mem.drexel.edu/alumni/bGreen/www.pages.drexel.edu/_weg22/can_tut.html

Examples

>>> from skimage import filter
>>> # Generate noisy image of a square
>>> im = np.zeros((256, 256))
>>> im[64:-64, 64:-64] = 1
>>> im += 0.2 * np.random.random(im.shape)
>>> # First trial with the Canny filter, with the default smoothing
>>> edges1 = filter.canny(im)
>>> # Increase the smoothing for better results
>>> edges2 = filter.canny(im, sigma=3)

denoise_bilateral

skimage.filter.denoise_bilateral(*args, **kwargs)

Deprecated function. Use skimage.restoration.denoise_bilateral instead.

Denoise image using bilateral filter.

This is an edge-preserving and noise reducing denoising filter. It averages pixels based on their spatial closeness and radiometric similarity.

Spatial closeness is measured by the gaussian function of the euclidian distance between two pixels and a certain standard deviation (sigma_spatial).

Radiometric similarity is measured by the gaussian function of the euclidian distance between two color values and a certain standard deviation (sigma_range).

Parameters:

image : ndarray

Input image.

win_size : int

Window size for filtering.

sigma_range : float

Standard deviation for grayvalue/color distance (radiometric similarity). A larger value results in averaging of pixels with larger radiometric differences. Note, that the image will be converted using the img_as_float function and thus the standard deviation is in respect to the range [0, 1].

sigma_spatial : float

Standard deviation for range distance. A larger value results in averaging of pixels with larger spatial differences.

bins : int

Number of discrete values for gaussian weights of color filtering. A larger value results in improved accuracy.

mode : string

How to handle values outside the image borders. See scipy.ndimage.map_coordinates for detail.

cval : string

Used in conjunction with mode ‘constant’, the value outside the image boundaries.

Returns:

denoised : ndarray

Denoised image.

References

[R172]http://users.soe.ucsc.edu/~manduchi/Papers/ICCV98.pdf

denoise_tv_bregman

skimage.filter.denoise_tv_bregman(*args, **kwargs)

Deprecated function. Use skimage.restoration.denoise_tv_bregman instead.

Perform total-variation denoising using split-Bregman optimization.

Total-variation denoising (also know as total-variation regularization) tries to find an image with less total-variation under the constraint of being similar to the input image, which is controlled by the regularization parameter.

Parameters:

image : ndarray

Input data to be denoised (converted using img_as_float`).

weight : float, optional

Denoising weight. The smaller the weight, the more denoising (at the expense of less similarity to the input). The regularization parameter lambda is chosen as 2 * weight.

eps : float, optional

Relative difference of the value of the cost function that determines the stop criterion. The algorithm stops when:

SUM((u(n) - u(n-1))**2) < eps

max_iter : int, optional

Maximal number of iterations used for the optimization.

isotropic : boolean, optional

Switch between isotropic and anisotropic TV denoising.

Returns:

u : ndarray

Denoised image.

References

[R173]http://en.wikipedia.org/wiki/Total_variation_denoising
[R174]Tom Goldstein and Stanley Osher, “The Split Bregman Method For L1 Regularized Problems”, ftp://ftp.math.ucla.edu/pub/camreport/cam08-29.pdf
[R175]Pascal Getreuer, “Rudin–Osher–Fatemi Total Variation Denoising using Split Bregman” in Image Processing On Line on 2012–05–19, http://www.ipol.im/pub/art/2012/g-tvd/article_lr.pdf
[R176]http://www.math.ucsb.edu/~cgarcia/UGProjects/BregmanAlgorithms_JacquelineBush.pdf

denoise_tv_chambolle

skimage.filter.denoise_tv_chambolle(*args, **kwargs)

Deprecated function. Use skimage.restoration.denoise_tv_chambolle instead.

Perform total-variation denoising on 2D and 3D images.

Parameters:

im : ndarray (2d or 3d) of ints, uints or floats

Input data to be denoised. im can be of any numeric type, but it is cast into an ndarray of floats for the computation of the denoised image.

weight : float, optional

Denoising weight. The greater weight, the more denoising (at the expense of fidelity to input).

eps : float, optional

Relative difference of the value of the cost function that determines the stop criterion. The algorithm stops when:

(E_(n-1) - E_n) < eps * E_0

n_iter_max : int, optional

Maximal number of iterations used for the optimization.

multichannel : bool, optional

Apply total-variation denoising separately for each channel. This option should be true for color images, otherwise the denoising is also applied in the 3rd dimension.

Returns:

out : ndarray

Denoised image.

Notes

Make sure to set the multichannel parameter appropriately for color images.

The principle of total variation denoising is explained in http://en.wikipedia.org/wiki/Total_variation_denoising

The principle of total variation denoising is to minimize the total variation of the image, which can be roughly described as the integral of the norm of the image gradient. Total variation denoising tends to produce “cartoon-like” images, that is, piecewise-constant images.

This code is an implementation of the algorithm of Rudin, Fatemi and Osher that was proposed by Chambolle in [R177].

References

[R177](1, 2) A. Chambolle, An algorithm for total variation minimization and applications, Journal of Mathematical Imaging and Vision, Springer, 2004, 20, 89-97.

Examples

2D example on Lena image:

>>> from skimage import color, data
>>> lena = color.rgb2gray(data.lena())[:50, :50]
>>> lena += 0.5 * lena.std() * np.random.randn(*lena.shape)
>>> denoised_lena = denoise_tv_chambolle(lena, weight=60)

3D example on synthetic data:

>>> x, y, z = np.ogrid[0:20, 0:20, 0:20]
>>> mask = (x - 22)**2 + (y - 20)**2 + (z - 17)**2 < 8**2
>>> mask = mask.astype(np.float)
>>> mask += 0.2*np.random.randn(*mask.shape)
>>> res = denoise_tv_chambolle(mask, weight=100)

gabor_filter

skimage.filter.gabor_filter(image, frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None, offset=0, mode='reflect', cval=0)

Return real and imaginary responses to Gabor filter.

The real and imaginary parts of the Gabor filter kernel are applied to the image and the response is returned as a pair of arrays.

Frequency and orientation representations of the Gabor filter are similar to those of the human visual system. It is especially suitable for texture classification using Gabor filter banks.

Parameters:

image : array

Input image.

frequency : float

Frequency of the harmonic function.

theta : float

Orientation in radians. If 0, the harmonic is in the x-direction.

bandwidth : float

The bandwidth captured by the filter. For fixed bandwidth, sigma_x and sigma_y will decrease with increasing frequency. This value is ignored if sigma_x and sigma_y are set by the user.

sigma_x, sigma_y : float

Standard deviation in x- and y-directions. These directions apply to the kernel before rotation. If theta = pi/2, then the kernel is rotated 90 degrees so that sigma_x controls the vertical direction.

offset : float, optional

Phase offset of harmonic function in radians.

Returns:

real, imag : arrays

Filtered images using the real and imaginary parts of the Gabor filter kernel.

References

[R178]http://en.wikipedia.org/wiki/Gabor_filter
[R179]http://mplab.ucsd.edu/tutorials/gabor.pdf

gabor_kernel

skimage.filter.gabor_kernel(frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None, offset=0)

Return complex 2D Gabor filter kernel.

Frequency and orientation representations of the Gabor filter are similar to those of the human visual system. It is especially suitable for texture classification using Gabor filter banks.

Parameters:

frequency : float

Frequency of the harmonic function.

theta : float

Orientation in radians. If 0, the harmonic is in the x-direction.

bandwidth : float

The bandwidth captured by the filter. For fixed bandwidth, sigma_x and sigma_y will decrease with increasing frequency. This value is ignored if sigma_x and sigma_y are set by the user.

sigma_x, sigma_y : float

Standard deviation in x- and y-directions. These directions apply to the kernel before rotation. If theta = pi/2, then the kernel is rotated 90 degrees so that sigma_x controls the vertical direction.

offset : float, optional

Phase offset of harmonic function in radians.

Returns:

g : complex array

Complex filter kernel.

References

[R180]http://en.wikipedia.org/wiki/Gabor_filter
[R181]http://mplab.ucsd.edu/tutorials/gabor.pdf

gaussian_filter

skimage.filter.gaussian_filter(image, sigma, output=None, mode='nearest', cval=0, multichannel=None)

Multi-dimensional Gaussian filter

Parameters:

image : array-like

input image (grayscale or color) to filter.

sigma : scalar or sequence of scalars

standard deviation for Gaussian kernel. The standard deviations of the Gaussian filter are given for each axis as a sequence, or as a single number, in which case it is equal for all axes.

output : array, optional

The output parameter passes an array in which to store the filter output.

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 ‘nearest’.

cval : scalar, optional

Value to fill past edges of input if mode is ‘constant’. Default is 0.0

multichannel : bool, optional (default: None)

Whether the last axis of the image is to be interpreted as multiple channels. If True, each channel is filtered separately (channels are not mixed together). Only 3 channels are supported. If None, the function will attempt to guess this, and raise a warning if ambiguous, when the array has shape (M, N, 3).

Returns:

filtered_image : ndarray

the filtered array

Notes

This function is a wrapper around scipy.ndimage.gaussian_filter().

Integer arrays are converted to float.

The multi-dimensional filter is implemented as a sequence of one-dimensional convolution filters. The intermediate arrays are stored in the same data type as the output. Therefore, for output types with a limited precision, the results may be imprecise because intermediate results may be stored with insufficient precision.

Examples

>>> a = np.zeros((3, 3))
>>> a[1, 1] = 1
>>> a
array([[ 0.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  0.]])
>>> gaussian_filter(a, sigma=0.4)  # mild smoothing
array([[ 0.00163116,  0.03712502,  0.00163116],
       [ 0.03712502,  0.84496158,  0.03712502],
       [ 0.00163116,  0.03712502,  0.00163116]])
>>> gaussian_filter(a, sigma=1)  # more smooting
array([[ 0.05855018,  0.09653293,  0.05855018],
       [ 0.09653293,  0.15915589,  0.09653293],
       [ 0.05855018,  0.09653293,  0.05855018]])
>>> # Several modes are possible for handling boundaries
>>> gaussian_filter(a, sigma=1, mode='reflect')
array([[ 0.08767308,  0.12075024,  0.08767308],
       [ 0.12075024,  0.16630671,  0.12075024],
       [ 0.08767308,  0.12075024,  0.08767308]])
>>> # For RGB images, each is filtered separately
>>> from skimage.data import lena
>>> image = lena()
>>> filtered_lena = gaussian_filter(image, sigma=1, multichannel=True)

hprewitt

skimage.filter.hprewitt(image, mask=None)

Find the horizontal edges of an image using the Prewitt transform.

Parameters:

image : 2-D array

Image to process.

mask : 2-D array, optional

An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.

Returns:

output : 2-D array

The Prewitt edge map.

Notes

We use the following kernel and return the absolute value of the result at each point:

 1   1   1
 0   0   0
-1  -1  -1

hscharr

skimage.filter.hscharr(image, mask=None)

Find the horizontal edges of an image using the Scharr transform.

Parameters:

image : 2-D array

Image to process.

mask : 2-D array, optional

An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.

Returns:

output : 2-D array

The Scharr edge map.

Notes

We use the following kernel and return the absolute value of the result at each point:

 3   10   3
 0    0   0
-3  -10  -3

References

[R182]D. Kroon, 2009, Short Paper University Twente, Numerical Optimization of Kernel Based Image Derivatives.

hsobel

skimage.filter.hsobel(image, mask=None)

Find the horizontal edges of an image using the Sobel transform.

Parameters:

image : 2-D array

Image to process.

mask : 2-D array, optional

An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.

Returns:

output : 2-D array

The Sobel edge map.

Notes

We use the following kernel and return the absolute value of the result at each point:

 1   2   1
 0   0   0
-1  -2  -1

inverse

skimage.filter.inverse(data, impulse_response=None, filter_params={}, max_gain=2, predefined_filter=None)

Apply the filter in reverse to the given data.

Parameters:

data : (M,N) ndarray

Input data.

impulse_response : callable f(r, c, **filter_params)

Impulse response of the filter. See LPIFilter2D.__init__.

filter_params : dict

Additional keyword parameters to the impulse_response function.

max_gain : float

Limit the filter gain. Often, the filter contains zeros, which would cause the inverse filter to have infinite gain. High gain causes amplification of artefacts, so a conservative limit is recommended.

Other Parameters:
 

predefined_filter : LPIFilter2D

If you need to apply the same filter multiple times over different images, construct the LPIFilter2D and specify it here.

prewitt

skimage.filter.prewitt(image, mask=None)

Find the edge magnitude using the Prewitt transform.

Parameters:

image : 2-D array

Image to process.

mask : 2-D array, optional

An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.

Returns:

output : 2-D array

The Prewitt edge map.

Notes

Return the square root of the sum of squares of the horizontal and vertical Prewitt transforms.

rank_order

skimage.filter.rank_order(image)

Return an image of the same shape where each pixel is the index of the pixel value in the ascending order of the unique values of image, aka the rank-order value.

Parameters:

image: ndarray :

Returns:

labels: ndarray of type np.uint32, of shape image.shape :

New array where each pixel has the rank-order value of the corresponding pixel in image. Pixel values are between 0 and n - 1, where n is the number of distinct unique values in image.

original_values: 1-d ndarray :

Unique original values of image

Examples

>>> a = np.array([[1, 4, 5], [4, 4, 1], [5, 1, 1]])
>>> a
array([[1, 4, 5],
       [4, 4, 1],
       [5, 1, 1]])
>>> rank_order(a)
(array([[0, 1, 2],
       [1, 1, 0],
       [2, 0, 0]], dtype=uint32), array([1, 4, 5]))
>>> b = np.array([-1., 2.5, 3.1, 2.5])
>>> rank_order(b)
(array([0, 1, 2, 1], dtype=uint32), array([-1. ,  2.5,  3.1]))

roberts

skimage.filter.roberts(image, mask=None)

Find the edge magnitude using Roberts’ cross operator.

Parameters:

image : 2-D array

Image to process.

mask : 2-D array, optional

An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.

Returns:

output : 2-D array

The Roberts’ Cross edge map.

roberts_negative_diagonal

skimage.filter.roberts_negative_diagonal(image, mask=None)

Find the cross edges of an image using the Roberts’ Cross operator.

The kernel is applied to the input image to produce separate measurements of the gradient component one orientation.

Parameters:

image : 2-D array

Image to process.

mask : 2-D array, optional

An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.

Returns:

output : 2-D array

The Robert’s edge map.

Notes

We use the following kernel and return the absolute value of the result at each point:

 0   1
-1   0

roberts_positive_diagonal

skimage.filter.roberts_positive_diagonal(image, mask=None)

Find the cross edges of an image using Roberts’ cross operator.

The kernel is applied to the input image to produce separate measurements of the gradient component one orientation.

Parameters:

image : 2-D array

Image to process.

mask : 2-D array, optional

An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.

Returns:

output : 2-D array

The Robert’s edge map.

Notes

We use the following kernel and return the absolute value of the result at each point:

1   0
0  -1

scharr

skimage.filter.scharr(image, mask=None)

Find the edge magnitude using the Scharr transform.

Parameters:

image : 2-D array

Image to process.

mask : 2-D array, optional

An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.

Returns:

output : 2-D array

The Scharr edge map.

Notes

Take the square root of the sum of the squares of the horizontal and vertical Scharrs to get a magnitude that’s somewhat insensitive to direction.

References

[R183]D. Kroon, 2009, Short Paper University Twente, Numerical Optimization of Kernel Based Image Derivatives.

sobel

skimage.filter.sobel(image, mask=None)

Find the edge magnitude using the Sobel transform.

Parameters:

image : 2-D array

Image to process.

mask : 2-D array, optional

An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.

Returns:

output : 2-D array

The Sobel edge map.

Notes

Take the square root of the sum of the squares of the horizontal and vertical Sobels to get a magnitude that’s somewhat insensitive to direction.

Note that scipy.ndimage.sobel returns a directional Sobel which has to be further processed to perform edge detection.

threshold_adaptive

skimage.filter.threshold_adaptive(image, block_size, method='gaussian', offset=0, mode='reflect', param=None)

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

Uneven 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

[R184]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)

threshold_isodata

skimage.filter.threshold_isodata(image, nbins=256)

Return threshold value based on ISODATA method.

Histogram-based threshold, known as Ridler-Calvard method or intermeans.

Parameters:

image : array

Input image.

nbins : int, optional

Number of bins used to calculate histogram. This value is ignored for integer arrays.

Returns:

threshold : float or int, corresponding input array dtype.

Upper threshold value. All pixels intensities that less or equal of this value assumed as background.

References

[R185]Ridler, TW & Calvard, S (1978), “Picture thresholding using an iterative selection method”
[R186]IEEE Transactions on Systems, Man and Cybernetics 8: 630-632, http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=4310039
[R187]Sezgin M. and Sankur B. (2004) “Survey over Image Thresholding Techniques and Quantitative Performance Evaluation” Journal of Electronic Imaging, 13(1): 146-165, http://www.busim.ee.boun.edu.tr/~sankur/SankurFolder/Threshold_survey.pdf
[R188]ImageJ AutoThresholder code, http://fiji.sc/wiki/index.php/Auto_Threshold

Examples

>>> from skimage.data import coins
>>> image = coins()
>>> thresh = threshold_isodata(image)
>>> binary = image > thresh

threshold_otsu

skimage.filter.threshold_otsu(image, nbins=256)

Return threshold value based on Otsu’s method.

Parameters:

image : array

Input image.

nbins : int, optional

Number of bins used to calculate histogram. This value is ignored for integer arrays.

Returns:

threshold : float

Upper threshold value. All pixels intensities that less or equal of this value assumed as foreground.

References

[R189]Wikipedia, http://en.wikipedia.org/wiki/Otsu’s_Method

Examples

>>> from skimage.data import camera
>>> image = camera()
>>> thresh = threshold_otsu(image)
>>> binary = image <= thresh

threshold_yen

skimage.filter.threshold_yen(image, nbins=256)

Return threshold value based on Yen’s method.

Parameters:

image : array

Input image.

nbins : int, optional

Number of bins used to calculate histogram. This value is ignored for integer arrays.

Returns:

threshold : float

Upper threshold value. All pixels intensities that less or equal of this value assumed as foreground.

References

[R190]Yen J.C., Chang F.J., and Chang S. (1995) “A New Criterion for Automatic Multilevel Thresholding” IEEE Trans. on Image Processing, 4(3): 370-378
[R191]Sezgin M. and Sankur B. (2004) “Survey over Image Thresholding Techniques and Quantitative Performance Evaluation” Journal of Electronic Imaging, 13(1): 146-165, http://www.busim.ee.boun.edu.tr/~sankur/SankurFolder/Threshold_survey.pdf
[R192]ImageJ AutoThresholder code, http://fiji.sc/wiki/index.php/Auto_Threshold

Examples

>>> from skimage.data import camera
>>> image = camera()
>>> thresh = threshold_yen(image)
>>> binary = image <= thresh

vprewitt

skimage.filter.vprewitt(image, mask=None)

Find the vertical edges of an image using the Prewitt transform.

Parameters:

image : 2-D array

Image to process.

mask : 2-D array, optional

An optional mask to limit the application to a certain area. Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.

Returns:

output : 2-D array

The Prewitt edge map.

Notes

We use the following kernel and return the absolute value of the result at each point:

1   0  -1
1   0  -1
1   0  -1

vscharr

skimage.filter.vscharr(image, mask=None)

Find the vertical edges of an image using the Scharr transform.

Parameters:

image : 2-D array

Image to process

mask : 2-D array, optional

An optional mask to limit the application to a certain area Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.

Returns:

output : 2-D array

The Scharr edge map.

Notes

We use the following kernel and return the absolute value of the result at each point:

 3   0   -3
10   0  -10
 3   0   -3

References

[R193]D. Kroon, 2009, Short Paper University Twente, Numerical Optimization of Kernel Based Image Derivatives.

vsobel

skimage.filter.vsobel(image, mask=None)

Find the vertical edges of an image using the Sobel transform.

Parameters:

image : 2-D array

Image to process

mask : 2-D array, optional

An optional mask to limit the application to a certain area Note that pixels surrounding masked regions are also masked to prevent masked regions from affecting the result.

Returns:

output : 2-D array

The Sobel edge map.

Notes

We use the following kernel and return the absolute value of the result at each point:

1   0  -1
2   0  -2
1   0  -1

wiener

skimage.filter.wiener(data, impulse_response=None, filter_params={}, K=0.25, predefined_filter=None)

Minimum Mean Square Error (Wiener) inverse filter.

Parameters:

data : (M,N) ndarray

Input data.

K : float or (M,N) ndarray

Ratio between power spectrum of noise and undegraded image.

impulse_response : callable f(r, c, **filter_params)

Impulse response of the filter. See LPIFilter2D.__init__.

filter_params : dict

Additional keyword parameters to the impulse_response function.

Other Parameters:
 

predefined_filter : LPIFilter2D

If you need to apply the same filter multiple times over different images, construct the LPIFilter2D and specify it here.