gaussian

gaussian

skimage.filters.gaussian(image, sigma, output=None, mode='nearest', cval=0, multichannel=None) [source]

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.ndi.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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
>>> a = np.zeros((3, 3))
>>> a[1, 1] = 1
>>> a
array([[ 0.0.0.],
       [ 0.1.0.],
       [ 0.0.0.]])
>>> gaussian(a, sigma=0.4# mild smoothing
array([[ 0.001631160.037125020.00163116],
       [ 0.037125020.844961580.03712502],
       [ 0.001631160.037125020.00163116]])
>>> gaussian(a, sigma=1# more smooting
array([[ 0.058550180.096532930.05855018],
       [ 0.096532930.159155890.09653293],
       [ 0.058550180.096532930.05855018]])
>>> # Several modes are possible for handling boundaries
>>> gaussian(a, sigma=1, mode='reflect')
array([[ 0.087673080.120750240.08767308],
       [ 0.120750240.166306710.12075024],
       [ 0.087673080.120750240.08767308]])
>>> # For RGB images, each is filtered separately
>>> from skimage.data import astronaut
>>> image = astronaut()
>>> filtered_img = gaussian(image, sigma=1, multichannel=True)
doc_scikit_image
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.