Bases: object
Linear Position-Invariant Filter (2-dimensional)
Parameters: | impulse_response : callable f(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)
Bases: object
Decorator to mark deprecated functions with warning.
Adapted from <http://wiki.python.org/moin/PythonDecoratorLibrary>.
Parameters: | alt_func : str
behavior : {‘warn’, ‘raise’}
|
---|
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. |
Edge filter an image using the Canny algorithm.
Parameters: | image : 2D array
sigma : float
low_threshold : float
high_threshold : float
mask : array, dtype=bool, optional
|
---|---|
Returns: | output : 2D 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’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)
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
win_size : int
sigma_range : float
sigma_spatial : float
bins : int
mode : string
cval : string
|
---|---|
Returns: | denoised : ndarray
|
References
[R172] | http://users.soe.ucsc.edu/~manduchi/Papers/ICCV98.pdf |
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
weight : float, optional
eps : float, optional
max_iter : int, optional
isotropic : boolean, optional
|
---|---|
Returns: | u : ndarray
|
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 |
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
weight : float, optional
eps : float, optional
n_iter_max : int, optional
multichannel : bool, optional
|
---|---|
Returns: | out : ndarray
|
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)
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
frequency : float
theta : float
bandwidth : float
sigma_x, sigma_y : float
offset : float, optional
|
---|---|
Returns: | real, imag : arrays
|
References
[R178] | http://en.wikipedia.org/wiki/Gabor_filter |
[R179] | http://mplab.ucsd.edu/tutorials/gabor.pdf |
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
theta : float
bandwidth : float
sigma_x, sigma_y : float
offset : float, optional
|
---|---|
Returns: | g : complex array
|
References
[R180] | http://en.wikipedia.org/wiki/Gabor_filter |
[R181] | http://mplab.ucsd.edu/tutorials/gabor.pdf |
Multi-dimensional Gaussian filter
Parameters: | image : array-like
sigma : scalar or sequence of scalars
output : array, optional
mode : {‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, optional
cval : scalar, optional
multichannel : bool, optional (default: None)
|
---|---|
Returns: | filtered_image : ndarray
|
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)
Find the horizontal edges of an image using the Prewitt transform.
Parameters: | image : 2-D array
mask : 2-D array, optional
|
---|---|
Returns: | output : 2-D array
|
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 Scharr transform.
Parameters: | image : 2-D array
mask : 2-D array, optional
|
---|---|
Returns: | output : 2-D array
|
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. |
Find the horizontal edges of an image using the Sobel transform.
Parameters: | image : 2-D array
mask : 2-D array, optional
|
---|---|
Returns: | output : 2-D array
|
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
|
---|---|
Other Parameters: | |
predefined_filter : LPIFilter2D
|
Find the edge magnitude using the Prewitt transform.
Parameters: | image : 2-D array
mask : 2-D array, optional
|
---|---|
Returns: | output : 2-D array
|
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]))
Find the edge magnitude using Roberts’ cross operator.
Parameters: | image : 2-D array
mask : 2-D array, optional
|
---|---|
Returns: | output : 2-D array
|
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
mask : 2-D array, optional
|
---|---|
Returns: | output : 2-D array
|
Notes
We use the following kernel and return the absolute value of the result at each point:
0 1
-1 0
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
mask : 2-D array, optional
|
---|---|
Returns: | output : 2-D array
|
Notes
We use the following kernel and return the absolute value of the result at each point:
1 0
0 -1
Find the edge magnitude using the Scharr transform.
Parameters: | image : 2-D array
mask : 2-D array, optional
|
---|---|
Returns: | output : 2-D array
|
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. |
Find the edge magnitude using the Sobel transform.
Parameters: | image : 2-D array
mask : 2-D array, optional
|
---|---|
Returns: | output : 2-D array
|
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
[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)
Return threshold value based on ISODATA method.
Histogram-based threshold, known as Ridler-Calvard method or intermeans.
Parameters: | image : array
nbins : int, optional
|
---|---|
Returns: | threshold : float or int, corresponding input array dtype.
|
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
Return threshold value based on Otsu’s method.
Parameters: | image : array
nbins : int, optional
|
---|---|
Returns: | threshold : float
|
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
Return threshold value based on Yen’s method.
Parameters: | image : array
nbins : int, optional
|
---|---|
Returns: | threshold : float
|
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
Find the vertical edges of an image using the Prewitt transform.
Parameters: | image : 2-D array
mask : 2-D array, optional
|
---|---|
Returns: | output : 2-D array
|
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 Scharr transform.
Parameters: | image : 2-D array
mask : 2-D array, optional
|
---|---|
Returns: | output : 2-D array
|
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. |
Find the vertical edges of an image using the Sobel transform.
Parameters: | image : 2-D array
mask : 2-D array, optional
|
---|---|
Returns: | output : 2-D array
|
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
|
---|---|
Other Parameters: | |
predefined_filter : LPIFilter2D
|