3
$\begingroup$

I am calling fspecial in matlab to create a Guassian blur of an image.

For example,

%Create Gaussian Filter
G = fspecial('gaussian', [5 5], 2);

% Blur Image
blurredImage = imfilter(nonBlurredImage,G,'same')

The parameter [5 5] is hsize which defines the extent to which the Gaussian filter is applied ... which according to user "Try Hard" ... "In the case of a gaussian filter, the intensity at each pixel around the central one is weighted according to a gaussian function prior to performing a box average over the region."

The parameter 2 is sigma ... with units of pixels.

Say the size of nonBlurredImage is 200x200. And that the side of each pixel represents a length of 0.25 mm. Then the image could resolve objects with a "resolution" of 1 line pair/mm without aliasing.

If I pass G = fspecial('gaussian', [5 5], 1) to the filter function, and then produce the blurred image. What would be the "resolution" of this image? How does it relate to hsize? If I instead used [10 10] or [1 1], how would that affect things?

Thanks!

$\endgroup$
  • $\begingroup$ This answer here may help you. $\endgroup$ – Tarin Ziyaee Jun 5 '14 at 22:04
1
$\begingroup$

The size of the filter, as you correctly point out, determines the area over which it has averages the pixels.

In theory a gaussian filter has non-zero weights for all distances from the centre. In practise however it is not feasible to do this as computation time would be large. Therefore the gaussian is cut-off outside the filter size and the weights outside are set to zero.

To ensure a good representation of a real gaussian the filter size should be large enough that the weights outside the filter would be small, if not your result is significantly distorted from a real gaussian.

The $\sigma$ of the filter is what determines the weights so this should be used to determine the filter size too. I then to use a filter of at least $6\sigma$ (make sure answer is odd), although Drazick has a different suggestion.

For resolution the answer somewhat depends on your definition of resolution. I would generally say the resolution after filtering is $2\sigma$, ignoring any other effects such as pixel size and optical resolution. If the filter size is too small this will change, although I'm not sure its always well defined as you'll get some ringing effects from the sharp cut-off.

$\endgroup$
1
$\begingroup$

When applying Gaussian Blur on an image you should care for the STD only.
The rest should be set as following:

STD_TO_RADIUS_FACTOR = 5;
kernelRadius = ceil(STD_TO_RADIUS_FACTOR * kernelStd);
kernelLength = (2 * kernelRadius ) + 1;
mGaussianKernel = fspecial('gaussian', [kernelLength, kernelLength], kernelRadius);

Now, regarding the resolution of the image, this is tricky since it has many parameters in it.
If you want to measure it in Cycles in Spatial (As DFT), you can see the spectrum properties (Cut Off Frequency) of a Gaussian Kernel.

Update

The STD_TO_RADIUS_FACTOR should be determined by the balance between accuracy and performance.
The above is basically a truncated version of the Gaussian Kernel (Which is infinite). The balance sets how good is the approximation vs. how long the Convolution Kernel is (The longer the higher computational resources it requires).

$\endgroup$
  • $\begingroup$ I agree with the principle of setting kernel size based on the std. Do you have any good explanation for the quantities you use though? $\endgroup$ – nivag Jun 6 '14 at 13:47
  • $\begingroup$ @nivag, At any size it would be a truncated approximation of the Gaussian Blur. Some use 3 times the STD, some use more. It is a balance between accuracy and performance. $\endgroup$ – Royi Jun 6 '14 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.