3
votes

I would like to perform an asymmetrical gaussian filtering on a 3D data matrix in MATLAB. With imgaussfilt3, I am able to do it symmetrically (same blurring in all three dimensions). However, I can only give one value for sigma, hence the filtering is the same in all dimensions.

In another thread, I found the possibility to seperate the filtering and apply it horizontally and vertically (in that case it was only 2D), using the fspecial function. Sadly, I'm not able to make it work (I keep getting different results than when using imgaussfilt in a small example matrix), and the documentation for fspecial says that the gaussian mode is no longer recommended and to use imgaussfilt instead.

To provide an example:

matrix = rand(30,30,30);
sigma = 2;
matrix_symblur = imgaussfilt3(matrix,sigma);

Which I now want to change in the way that sigma is 1, 2 and 3 for the three dimensions, respectively, so that the blurring effect is differently strong for the three dimensions.

I am using MATLAB R2017a. Can anyone help?

1
Sounds like you need to define your own filtering kernel, then use a more general function like imfilter. Good luck!Dev-iL

1 Answers

1
votes

The imgaussfilt3 function can already do this out of the box. According to the documentation, sigma can be (emphasis mine)

sigma — Standard deviation of the Gaussian distribution
0.5 (default) | numeric, real, positive scalar or a 3-element vector

So, to have a sigma of 1 in the first dimension, 2 in the second dimension, and 3 in the third dimension, you can call imgaussfilt3 as follows:

matrix = rand(30,30,30);
sigma = [1, 2, 3];
matrix_symblur = imgaussfilt3(matrix, sigma);