Login  Register

Re: Gaussian blur

Posted by cihat eldeniz on Jun 04, 2009; 5:12pm
URL: http://imagej.273.s1.nabble.com/Gaussian-blur-tp3692269p3692271.html

It definitely helps a lot. Thank you very much for the time and effort!

2009/6/4 Michael Schmid <[hidden email]>

> Hi Cihat,
>
> the Gaussian Blur of ImageJ is a bit complicated:
> - It does two successive filter operation, one in x, one in y. This is
> faster than a 2D kernel. (Gaussian Blur is a separable filter)
> - The kernel size reaches out as far as required to have the edge values at
> roughly 2*10^-3 (8-bit, RGB) or 2*10^-4 (16-bit, float) of the center value;
> you have read this correctly from the source code. The equation that you
> have read from the makeGaussianKernel method is for the radius; the side
> length is 2*radius-1.
> - At the edges, the kernel is smoothly tapered towards zero to avoid
> artifacts caused by the small step that one have would otherwise. This
> process will fail if you set an accuracy that is too low, thus the upper
> limit of 0.02 for the accuracy. So you can't have a 3x3 kernel with sigma=1.
> - For large values of sigma, the rows or columns are first downscaled, then
> the filter operation is performed with a smaller sigma (smaller kernel),
> afterwards they are upscaled to the original size. Otherwise, computing time
> would be prohibitive for large sigma.
>
> The whole algorithm is a compromise between speed and accuracy.
>
> If you only want a 3x3 kernel for sigma=1, you have to use the Convolver
> class.
>
> An alternative would be taking the GaussianBlur code as an external plugin
> and eliminating the 'edge correction code' of makeGaussianKernel. For a
> small kernel size it won't be worth the effort - there the Convolver will be
> fast enough.
>
> Hope this helps,
>
> Michael
> ________________________________________________________________
>
>
> On 4 Jun 2009, at 16:09, cihat eldeniz wrote:
>
>  Hello,
>>
>> In matlab, if we do h = fspecial('gauss',3,1), we get:
>>
>> h =
>>
>>    0.0751    0.1238    0.0751
>>    0.1238    0.2042    0.1238
>>    0.0751    0.1238    0.0751
>>
>> Then we use imfilter(ourImage,h) to get the blurred image.
>>
>> If I copy and paste this 2D kernel into the convolver [using
>> Process>Filters>Convolve...], I get nearly the same result as matlab.
>> However, I would also like to learn how to do it by using imagej commands
>> only within a plugin.
>>
>> If I use Gaussian Blur with sigma 1, then the image is convolved with a
>> 6x6
>> window right? [Since the assumed accuracy is 2e-4 for an image which is
>> not
>> Byte or Color, and the sidelength of the kernel is given by
>> ceil(sigma*sqrt(-2*log(accuracy)))+1]. To have a 3x3 window, I have to set
>> the accuracy to at least exp(-2) = 0.1353, which is well above the
>> recommended upper limit on the website [0.02].
>>
>> How could I have imagej perform the filtering operation in exactly the
>> same
>> way as matlab with the 3x3 h given above, or is it possible at all?
>>
>> Thanks.
>>
>