Bases: object
Linear Position-Invariant Filter (2-dimensional)
Parameters : | impulse_response : callable f(r, c, **filter_params)
|
---|
Examples
Gaussian filter:
>>> def filt_func(r, c):
... return np.exp(-np.hypot(r, c)/1)
>>> filter = LPIFilter2D(filt_func)
skimage.filter.canny(image[, sigma, ...]) | Edge filter an image using the Canny algorithm. |
skimage.filter.hprewitt(image[, mask]) | Find the horizontal edges of an image using the Prewitt 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.median_filter(image[, ...]) | Masked median filter with octagon shape. |
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.sobel(image[, mask]) | Calculate the absolute magnitude Sobel to find edges. |
skimage.filter.threshold_adaptive(image, ...) | Applies an adaptive threshold to an array. |
skimage.filter.threshold_otsu(image[, nbins]) | Return threshold value based on Otsu’s method. |
skimage.filter.tv_denoise(im[, weight, eps, ...]) | Perform total-variation denoising on 2-d and 3-d images |
skimage.filter.vprewitt(image[, mask]) | Find the vertical edges of an image using the Prewitt 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. |
Edge filter an image using the Canny algorithm.
Parameters : | image : array_like, dtype=float
sigma : float
low_threshold : float
high_threshold : float
mask : array, dtype=bool, optional
|
---|---|
Returns : | output : array (image)
|
See also
skimage.sobel
Notes
The steps of the algorithm are as follows:
References
Canny, J., A Computational Approach To Edge Detection, IEEE Trans. Pattern Analysis and Machine Intelligence, 8:679-714, 1986
William Green’ 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)
Find the horizontal edges of an image using the Prewitt transform.
Parameters : | image : array_like, dtype=float
mask : array_like, dtype=bool, optional
|
---|---|
Returns : | output : ndarray
|
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
Find the horizontal edges of an image using the Sobel transform.
Parameters : | image : array_like, dtype=float
mask : array_like, dtype=bool, optional
|
---|---|
Returns : | output : ndarray
|
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
Apply the filter in reverse to the given data.
Parameters : | data : (M,N) ndarray
impulse_response : callable f(r, c, **filter_params)
filter_params : dict
max_gain : float
|
---|
Masked median filter with octagon shape.
Parameters : | image : (M,N) ndarray, dtype uint8
radius : {int, 2}, optional
mask : (M,N) ndarray, dtype uint8, optional
percent : {int, 50}, optional
|
---|---|
Returns : | out : (M,N) ndarray, dtype uint8
|
Find the edge magnitude using the Prewitt transform.
Parameters : | image : array_like, dtype=float
mask : array_like, dtype=bool, optional
|
---|---|
Returns : | output : ndarray
|
Notes
Return the square root of the sum of squares of the horizontal and vertical Prewitt transforms.
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 :
original_values: 1-d ndarray :
|
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]))
Calculate the absolute magnitude Sobel to find edges.
Parameters : | image : array_like, dtype=float
mask : array_like, dtype=bool, optional
|
---|---|
Returns : | output : ndarray
|
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.
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
block_size : int
method : {‘generic’, ‘gaussian’, ‘mean’, ‘median’}, optional
offset : float, optional
mode : {‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, optional
param : {int, function}, optional
|
---|---|
Returns : | threshold : (N, M) ndarray
|
References
Examples
>>> from skimage.data import camera
>>> image = camera()
>>> binary_image1 = threshold_adaptive(image, 15, 'mean')
>>> func = lambda arr: arr.mean()
>>> binary_image2 = threshold_adaptive(image, 15, 'generic', param=func)
Return threshold value based on Otsu’s method.
Parameters : | image : array
nbins : int
|
---|---|
Returns : | threshold : float
|
References
[R45] | Wikipedia, http://en.wikipedia.org/wiki/Otsu’s_Method |
Examples
>>> from skimage.data import camera
>>> image = camera()
>>> thresh = threshold_otsu(image)
>>> binary = image > thresh
Perform total-variation denoising on 2-d and 3-d images
Parameters : | im: ndarray (2d or 3d) of ints, uints or floats :
weight: float, optional :
eps: float, optional :
n_iter_max: int, optional :
|
---|---|
Returns : | out: ndarray :
|
Notes
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 [R46].
References
[R46] | (1, 2) A. Chambolle, An algorithm for total variation minimization and applications, Journal of Mathematical Imaging and Vision, Springer, 2004, 20, 89-97. |
Examples
>>> import scipy
>>> # 2D example using lena
>>> lena = scipy.lena()
>>> import scipy
>>> lena = scipy.lena().astype(np.float)
>>> lena += 0.5 * lena.std()*np.random.randn(*lena.shape)
>>> denoised_lena = tv_denoise(lena, weight=60)
>>> # 3D example on synthetic data
>>> x, y, z = np.ogrid[0:40, 0:40, 0:40]
>>> 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 = tv_denoise_3d(mask, weight=100)
Find the vertical edges of an image using the Prewitt transform.
Parameters : | image : array_like, dtype=float
mask : array_like, dtype=bool, optional
|
---|---|
Returns : | output : ndarray
|
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
Find the vertical edges of an image using the Sobel transform.
Parameters : | image : array_like, dtype=float
mask : array_like, dtype=bool, optional
|
---|---|
Returns : | output : ndarray
|
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
Minimum Mean Square Error (Wiener) inverse filter.
Parameters : | data : (M,N) ndarray
K : float or (M,N) ndarray
impulse_response : callable f(r, c, **filter_params)
filter_params : dict
|
---|