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.

imgaussfilt3

3-D Gaussian filtering of 3-D images

Syntax

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

Description

example

B = imgaussfilt3(A) filters 3-D image A with a 3-D Gaussian smoothing kernel with standard deviation of 0.5.

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

B = imgaussfilt3(___,Name,Value,...) filters 3-D image A with a 3-D Gaussian smoothing kernel with Name-Value pairs used to control aspects of the filtering.

example

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

Examples

collapse all

Load MRI data and display it.

vol = load('mri');
figure
montage(vol.D)
title('Original image volume')

Smooth the image with a 3-D Gaussian filter.

siz = vol.siz;
vol = squeeze(vol.D);   
sigma = 2;
 
volSmooth = imgaussfilt3(vol, sigma);
  
figure
montage(reshape(volSmooth,siz(1),siz(2),1,siz(3)))
title('Gaussian filtered image volume')

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

Load MRI data to be filtered.

vol = load('mri');
figure, montage(vol.D), title('Original image volume')

Create a gpuArray containing the volume data and perform Gaussian smoothing.

siz = vol.siz;
vol = gpuArray(squeeze(vol.D));   
sigma = 2; 

volSmooth = imgaussfilt3(vol, sigma);

Collect the smoothed data from the GPU (using the gather function) and display all the results for comparison.

figure, montage(reshape(gather(volSmooth),siz(1),siz(2),1,siz(3)))
title('Gaussian filtered image volume')

Input Arguments

collapse all

Image to be filtered, specified as a 3-D, real, nonsparse array.

Example: volSmooth = imgaussfilt3(vol,2);

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

Standard deviation of the Gaussian distribution, specified as a numeric, real, positive scalar or a 3-element vector. If sigma is a scalar, imgaussfilt3 uses a cubic Gaussian kernel.

Example: volSmooth = imgaussfilt3(vol, 2);

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

Input image for GPU, specified as a gpuArray.

Example: gpuarrayA = gpuArray(imread('cameraman.tif')); gpuarrayB = imgaussfilt3(gpuarrayA);

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: Smooth = imgaussfilt3(vol,sigma,'padding','circular');

collapse all

Size of the Gaussian filter, specified as a scalar or 3-element vector of real, positive, odd, integers. If you specify a scalar Q, imgaussfilt3 uses a cubic Gaussian filter of size [Q Q Q].

Example: volSmooth = imgaussfilt3(vol,sigma,'FilterSize',5);

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

Type of padding to be used on image before filtering, specified as one of the following values, or a numeric scalar. If you specify a scalar, imgaussfilt3 uses that value for input image pixels that fall outside the bounds of the image.

Padding TypeDescription
'circular'

Pad with circular repetition of elements within the dimension.

'replicate'

Pad by repeating border elements of array.

'symmetric'

Pad array with mirror reflections of itself.

Example: volSmooth = imgaussfilt3(vol,sigma,'padding','circular');

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.

Filter Domain Description
'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.

Example: Smooth = imgaussfilt3(vol,sigma,'FilterDomain','frequency');

Data Types: char

Output Arguments

collapse all

Filtered image, returned as a numeric array, the same class and size as input image.

Filtered image, returned as a gpuArray.

Tips

  • If image A contains Infs or NaNs, the behavior of imgaussfilt3 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 imgaussfilt3 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', imgaussfilt3 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, imgaussfilt3 uses 'replicate' padding by default, which is different from the default used by imfilter.

Introduced in R2015a

Was this topic helpful?