Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

imgaussfilt

2-D Gaussian filtering of images

Syntax

B = imgaussfilt(A)
B = imgaussfilt(A,sigma)
B = imgaussfilt(___,Name,Value,...)
gpuarrayB = imgaussfilt(gpuarrayA,___)

Description

B = imgaussfilt(A) filters image A with a 2-D Gaussian smoothing kernel with standard deviation of 0.5. Returns B, the filtered image.

B = imgaussfilt(A,sigma) filters image A with a 2-D Gaussian smoothing kernel with standard deviation specified by sigma.

B = imgaussfilt(___,Name,Value,...) filters image A with Name-Value pairs used to control aspects of the filtering.

example

gpuarrayB = imgaussfilt(gpuarrayA,___) performs the filtering operation on a GPU. The input image must be a gpuArray. The function returns a gpuArray. This syntax requires the Parallel Computing Toolbox™.

Examples

collapse all

Read image to be filtered.

I = imread('cameraman.tif');

Filter the image with a Gaussian filter with standard deviation of 2.

Iblur = imgaussfilt(I, 2);

Display all results for comparison.

subplot(1,2,1)
imshow(I)
title('Original Image');
subplot(1,2,2)
imshow(Iblur)
title('Gaussian filtered image, \sigma = 2')

This example shows how to perform a Gaussian smoothing operation on a GPU.

Read image to be filtered into a gpuArray.

I = gpuArray(imread('cameraman.tif'));

Perform Gaussian smoothing.

Iblur = imgaussfilt(I, 2);

Display all the results for comparison.

subplot(1,2,1), imshow(I), title('Original Image');

subplot(1,2,2), imshow(Iblur)
title('Gaussian filtered image, \sigma = 2')

Input Arguments

collapse all

Image to be filtered, specified as a real, nonsparse matrix of any dimension.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Standard deviation of the Gaussian distribution, specified as a scalar or 2-element vector of positive values. If you specify a scalar, the Gaussian kernel is square.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Input image for GPU, specified as a gpuArray.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: B = imgaussfilt(A,'FilterSize',3);

collapse all

Size of the Gaussian filter, specified as a scalar or 2-element vector of positive, odd integers. If you specify a scalar, the filter is a square.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Padding to be used on image before filtering, specified as a one of the following values, or a numeric scalar. If you specify a scalar (X), input image values outside the bounds of the image are implicitly assumed to have the value X.

ValueDescription
'circular'

Pad with circular repetition of elements within the dimension.

'replicate'

Pad by repeating border elements of array.

'symmetric'

Pad image with mirror reflections of itself.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char

Domain in which to perform filtering, specified as one of the following values:

ValueDescription
'auto'Perform convolution in the spatial or frequency domain, based on internal heuristics.
'frequency'Perform convolution in the frequency domain.
'spatial'Perform convolution in the spatial domain.

Data Types: char

Output Arguments

collapse all

Filtered image, returned as a real, nonsparse matrix, the same size and class as the input image.

Filtered image, returned as a gpuArray.

Tips

  • If image A contains Infs or NaNs, the behavior of imgaussfilt for frequency domain filtering is undefined. This can happen if you set the 'FilterDomain' parameter to 'frequency' or if you set it to 'auto' and imgaussfilt uses frequency domain filtering. To restrict the propagation of Infs and NaNs in the output in a manner similar to imfilter, consider setting the 'FilterDomain' parameter to 'spatial'.

  • When you set the 'FilterDomain' parameter to 'auto', imgaussfilt uses an internal heuristic to determine whether spatial or frequency domain filtering is faster. This heuristic is machine dependent and may vary for different configurations. For optimal performance, try both options, 'spatial' and 'frequency', to determine the best filtering domain for your image and kernel size.

  • If you do not specify the 'Padding' parameter, imgaussfilt uses 'replicate' padding by default, which is different from the default used by imfilter.

Extended Capabilities

Introduced in R2015a

Was this topic helpful?