Posted by
Michael Schmid on
Apr 07, 2008; 10:15am
URL: http://imagej.273.s1.nabble.com/Visualize-orthogonal-views-3D-reconstruction-tp3696642p3696648.html
Hi Mathieu,
the following PlugIn gets the same result as the gui Process>Filters>
Gaussian Blur command with ImageJ 1.40c (also for sigma = 0; small
deviations may arise form different accurracy; I have set it rather
low here with 0.01):
import ij.plugin.filter.GaussianBlur;
import ij.plugin.PlugIn;
import ij.process.*;
import ij.gui.*;
import ij.*;
public class TestGaussian implements PlugIn {
double sigma = 1; //or 0 or whatever you like
public void run(String unusedArg) {
ImagePlus imp = IJ.getImage();
if (imp==null) return;
ImageProcessor ip = imp.getProcessor();
ip.setRoi((Roi)null); //otherwise, a snapshot would be needed
GaussianBlur gb = new GaussianBlur();
gb.blurGaussian(ip, sigma, sigma, 0.01);
imp.updateAndDraw();
}
}
----
Note that the inner workings of Gaussian Blur have changed in
versions 1.38r, 1.38s and 1.38u, so the current API will not
fit the pre-1.38u versions.
---
Using the built-in Gaussian Blur is *much* faster that using
convolution with a (m x m) Gaussian kernel and also faster than
successive convolution operations with (m x 1) and (1 x m)
Gaussian kernels (especially for large sigma).
Michael
________________________________________________________________
On 6 Apr 2008, at 17:22, Jan Stühmer wrote:
> Hi Mathieu,
>
> have you tried a bigger convolution kernel than 3x3 ?
> A higher sigma than half the size of the convolution kernel makes
> not much
> sense if you want to have a reasonable precision.
>
> To adjust the kernel size ( m x m ) to the sigma value you can
> compute the value
> of the normal distribution (normalized gaussian) for x = 0.5 * m
> This gives you a hint of the error you get if you discretize the
> normal distribution
> for that filter size.
>
> What is a normal distribution with sigma=0 ? It should be the Dirac
> measure
> which should result in a non-modified image, you are right. But
> this is a special
> case of the normal distribution.
> In the end it depends on how ImageJ computes it's filter kernel
> because you get
> a division by zero if sigma is zero.
>
> Cheers,
> Jan
>
> Mathieu Goeminne schrieb:
>> Hi all,
>>
>> I try to use ImageJ to blur an image using the API (not the GUI)
>> with a
>> 3x3 convolution matrix gaussian blur. So I use a GaussianBlur object,
>> and call the blur(ImagePlus, double) method. Comparing the result
>> with
>> that is obtained using the ImageJ GUI or the GIMP, it appears my call
>> make an "excessive" blur : for a given sigma (the standard
>> deviation),
>> "my" blurring is stronger that the Gimp or the ImageJ GUI blurring.
>>
>> An other problem seems to be an artificial minimum on the sigma : for
>> every sigma < 1, the result seems to be
>> Approximately the same as a sigma=1 blurring. For instance, a
>> sigma=0
>> blurring blurs really my image, but it should return a non-
>> modified image.
>>
>> The documentation (and the API) of ImageJ says :
>>
>>
>>> 'Radius' means the radius of decay to exp(-0.5) ~ 61%, i.e. the
>>>
>> standard deviation sigma of the Gaussian (this is the same as in
>> Photoshop, but different from the previous ImageJ function 'Gaussian
>> Blur', where a value 2.5 times as much has to be entered)
>>
>> I tried to divide my sigma by 2.5, but there is no visible
>> difference,
>> and the sigma=0 case is not resolved.
>>
>> I use ImageJ 1.38
>>
>> Any idea?
>>
>> Thanks.
>>
>>