skimage2.filters.butterworth#
- skimage2.filters.butterworth(image, cutoff_frequency_ratio=0.005, high_pass=True, order=2.0, channel_axis=None, *, squared_butterworth=True, npad=0)[source]#
Apply a Butterworth filter to enhance high or low frequency features.
This filter is defined in the Fourier domain.
- Parameters:
- image(M[, N[, …, P]][, C]) ndarray
Input image.
- cutoff_frequency_ratiofloat, optional
Determines the position of the cut-off relative to the shape of the FFT. Receives a value between [0, 0.5].
- high_passbool, optional
Whether to perform a high pass filter. If False, a low pass filter is performed.
- orderfloat, optional
Order of the filter which affects the slope near the cut-off. Higher order means steeper slope in frequency space.
- channel_axisint, optional
If there is a channel dimension, provide the index here. If None (default) then all axes are assumed to be spatial dimensions.
- squared_butterworthbool, optional
When True, the square of a Butterworth filter is used. See notes below for more details.
- npadint, optional
Pad each edge of the image by
npadpixels usingnumpy.pad’smode='edge'extension.
- Returns:
- resultndarray
The Butterworth-filtered image.
Notes
A band-pass filter can be achieved by combining a high-pass and low-pass filter. The user can increase
npadif boundary artifacts are apparent.The “Butterworth filter” used in image processing textbooks (e.g. [1], [2]) is often the square of the traditional Butterworth filters as described by [3], [4]. The squared version will be used here if
squared_butterworthis set toTrue. The lowpass, squared Butterworth filter is given by the following expression for the lowpass case:\[H_{low}(f) = \frac{1}{1 + \left(\frac{f}{c f_s}\right)^{2n}}\]with the highpass case given by
\[H_{hi}(f) = 1 - H_{low}(f)\]where \(f=\sqrt{\sum_{d=0}^{\mathrm{ndim}} f_{d}^{2}}\) is the absolute value of the spatial frequency, \(f_s\) is the sampling frequency, \(c\) the
cutoff_frequency_ratio, and \(n\) is the filterorder[1]. Whensquared_butterworth=False, the square root of the above expressions are used instead.Note that
cutoff_frequency_ratiois defined in terms of the sampling frequency, \(f_s\). The FFT spectrum covers the Nyquist range (\([-f_s/2, f_s/2]\)) socutoff_frequency_ratioshould have a value between 0 and 0.5. The frequency response (gain) at the cutoff is 0.5 whensquared_butterworthis true and \(1/\sqrt{2}\) when it is false.References
[2]Birchfield, Stan. Image Processing and Analysis. 2018. Cengage Learning.
[3]Butterworth, Stephen. “On the theory of filter amplifiers.” Wireless Engineer 7.6 (1930): 536-541.
Examples
Apply a high-pass and low-pass Butterworth filter to a grayscale and color image respectively:
>>> from _skimage2.data import camera, astronaut >>> from _skimage2.filters import butterworth >>> high_pass = butterworth(camera(), 0.07, True, 8) >>> low_pass = butterworth(astronaut(), 0.01, False, 4, channel_axis=-1)