Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do 3D Gaussian filtering in OpenCV? [duplicate]

I have a multidimension matrix and I want to do Gaussian smoothing not only in 2D along x and y, but I also want to do smoothing across the channels in 3D. How can I do that in OpenCV?

I know there is a function called GaussianBlur which can apply a Gaussian filter in 2D, but how about 3D? The way you can call this looks something like below:

GaussianBlur(frame, frame2, Size(sigma, sigma), 0, 0);
like image 982
user2970089 Avatar asked Aug 15 '14 21:08

user2970089


People also ask

Why Gaussian filter is better than mean filter?

Gaussian filter has better performance in frequency domain. Mean filter is the least effective among low-pass filters. Ideally it should stop high frequencies and pass only low frequencies. In reality it passes many high frequencies and stops some of the low frequencies (slow roll-off and poor stopband attenuation).

Does Gaussian filter preserve edges?

Because of this, a Gaussian provides gentler smoothing and preserves edges better than a similarly sized mean filter.


1 Answers

This isn't supported off of OpenCV natively. However, because Gaussian filtering is separable, you can filter each dimension separately.

Use a combination of BaseRowFilter: http://docs.opencv.org/modules/imgproc/doc/filtering.html#BaseRowFilter and BaseColumnFilter: http://docs.opencv.org/modules/imgproc/doc/filtering.html#BaseColumnFilter and specify the Gaussian kernels as 1D.

Use getGaussianKernel: http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=gauss#getgaussiankernel to help you compute a 1D Gaussian kernel without having to do this yourself.

Now, for the third dimension, this is going to be tricky. You'll have to apply individual row / column filters to each 3D slice at a particular spatial location. For example, if you had a volume of 5 slices, and the size of one image was 10 x 10, the final filtered result in 3D is you having to extract 100 1D signals of size 5, then apply the kernel on each of these 1D signals separately.

Take a look at this post for more insight: How to do a Gaussian filtering in 3D . Someone else has tried to do this in the past.

Good luck!

like image 146
rayryeng Avatar answered Oct 17 '22 04:10

rayryeng