3D Gaussian Filter in MATLAB

15,277

Solution 1

There are two ways to solve this in order to do the filtering in an efficient manner:

(1) Use CONVN three times to filter your data with three 1D Gaussians, one x-by-1-by-1, one 1-by-y-by-1, and one 1-by-1-by-z.

(2) If you have the signal processing toolbox, use FFTFILT to perform filtering in inverse space (or use any one of the fft-convolution algorithms on the file exchange).

[(3) Send me an email and I'll send you my fftFilterImage, which does 3D Gauss filtering.]

Solution 2

imfilter can already do 3D filtering, as long as the data matrix and the filter you give it are 3D. See the imfilter page.

Solution 3

This task can be handled with the new (as of R2015a) imgaussfilt3 function.

The basic syntax is as follows:

B = imgaussfilt3(A,sigma)

There are also a number of name-value pair arguments:

  • 'FilterSize': Size of the Gaussian filter, defaulting to a cube of size 2*ceil(2*sigma)+1.
  • 'Padding': Type of padding ('replicate' (default) | 'circular' | 'symmetric').
  • 'FilterDomain': Perform convolution in domain: 'frequency' or 'spatial' (default auto).
Share:
15,277
Bill Cheatham
Author by

Bill Cheatham

Computer vision, graphics and machine learning.

Updated on June 14, 2022

Comments

  • Bill Cheatham
    Bill Cheatham almost 2 years

    Is there a 3D eqivalent of imfilter available for MATLAB? I wish to apply Gaussian filtering to a 3D histogram. I was going to implement it myself, by creating a (3D) Gaussian filter, then looping over each element in my histogram, and summing up the corresponding data entries.

    However, I didn't want to implement it myself in a slow and inefficient way if there's something already out there, or a cleverer way of doing it.