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.
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.
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).
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With