2-D Gaussian filtering of image

8 views (last 30 days)
Valerio Di Sano
Valerio Di Sano on 7 Jan 2018
Answered: Purvaja on 3 Feb 2025
I'm trying to smooth an image through imgaussfilt but I need to express the standard deviation in meters or pixels, not accross an adimensional number. Do you know how to have a correspondence?

Answers (1)

Purvaja
Purvaja on 3 Feb 2025
I understand that you wish to smooth an image with standard deviation in meters or pixels, relating to real-world dimensions. I have approached this using the “imgaussfiltfunction in two ways in MATLAB R2024b.
A. Converting meter to pixel values :
If we want to give sigma in the dimension of meters, we can get it by calculating the ratio between meters and pixels. For that, we should provide an estimated size of object in meters given in the image. And give the corresponding pixels that define the object in the image. The ratio of “meters/pixel” enables us to connect any sigma (in meters) to sigma (in pixels). Hence, we can use the resultant sigma in imgaussfilt” function. Follow the steps:
  • Read the Image
  • Give sizes in real world and pixels of the object
realWorldSize = 0.1; % meters
objectSizePixels = 20; % pixels
  • Calculate pixel size
pixelSize = realWorldSize / objectSizePixels; % meters/pixel
  • Desired standard deviation in meters
sigmaMeters = 0.01; % meters
  • Convert to pixels
sigmaPixels = sigmaMeters / pixelSize;
  • Apply Gaussian filter
meterImg = imgaussfilt(img, sigmaPixels);
  • Display the original and smoothed images
B. Using window sizes in pixels :
After going through MATLAB R2024b documentation for the “imgaussfilt” function, I came across a particular argument called “FilterSize” that enables us to define the window size (in pixels) for the Gaussian kernel. We can give a scalar odd positive integer, that will assume a square filter or else a vector of 2 odd positive integers for a rectangular filter.
  • Read the Image
  • Apply Gaussian filter with different sigma values
pixelImg = imgaussfilt(img, "FilterSize", [3 5]);
  • Display the original and smoothed images
For more clarification on the functions used, you can refer to the following resources:
For Gaussian Filtering referimgaussfilt” function:
Or you can access release specific documentation using this command in your MATLAB command window:
web(fullfile(docroot, 'images/ref/imgaussfilt.html'))
Hope this helps you!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!