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 “imgaussfilt” function 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
pixelSize = realWorldSize / objectSizePixels;
- Desired standard deviation in meters
sigmaPixels = sigmaMeters / pixelSize;
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 refer “imgaussfilt” 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!