Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gaussian smoothing in MATLAB

For an m x n array of elements with some noisy images, I want to perform Gaussian smoothing. How do I do that in MATLAB?

I've read the math involves smoothing everything with a kernel at a certain scale, but I have no idea how to do this in MATLAB.

like image 407
qpr92 Avatar asked May 05 '10 06:05

qpr92


People also ask

How do you do Gaussian smoothing?

We do it by dividing the Gaussian kernel values by sum of all the Gaussian kernel values. Then, we do element-wise multiplication of new cases column with Gaussian kernel values column and sum them to get the smoothed number of cases. We get the smoothed number of cases: 2036.

What is Gaussian smoothing in image processing?

In image processing, a Gaussian blur (also known as Gaussian smoothing) is the result of blurring an image by a Gaussian function (named after mathematician and scientist Carl Friedrich Gauss).

What is smoothing in Matlab?

Smoothing is a method of reducing the noise within a data set. Curve Fitting Toolbox™ allows you to smooth data using methods such as moving average, Savitzky-Golay filter and Lowess models or by fitting a smoothing spline.


1 Answers

Hopefully, you have the Image Processing toolbox. If so, then you can create a Gaussian filter with the fspecial function like so:

myfilter = fspecial('gaussian',[3 3], 0.5);

I have used the default values for hsize ([3 3]) and sigma (0.5) here, but you might want to play around with them. hsize is just the size of the filter, in this case it is a 3 x 3 matrix. Sigma is the sigma of the gaussian function (see the bottom of the fspecial function page).

Now you can use imfilter to filter your image:

myfilteredimage = imfilter(unfilteredimage, myfilter, 'replicate');

here I have simply passed in the unfilteredimage, the filter, and a parameter that says how the filter should handle the boundaries. In this case, I've chosen replicate which sets input array values outside the bounds of the array to the nearest array border value, but you can try some other values (or leaving off that option sets all outside of image values to 0).

like image 137
Justin Peel Avatar answered Oct 16 '22 14:10

Justin Peel