Page 1 of 1
sigma and radius arguments for -blur and -gaussian-blur
Posted: 2010-07-01T07:30:23-07:00
by coulon
In the documentation of both options there is the equation of a 2-D Gaussian function. u and v are its variables. I understand how sigma changes the shape of the function. But the documentation says r^2=u^2+v^2. Then why is r an argument? Isn't there a misprint?
Re: sigma and radius arguments for -blur and -gaussian-blur
Posted: 2010-07-01T07:51:23-07:00
by snibgo
My maths isn't good enough to explain Gaussian functions. An internet search might help. I think (but could be wrong) that r defines the maximum values of u and v.
Re: sigma and radius arguments for -blur and -gaussian-blur
Posted: 2010-07-01T09:32:57-07:00
by fmw42
r defines the extent or size of the filter, sigma determines the roll-off of the gaussian shape. but after about 2-3 sigma, the gaussian has rolled down to near zero, thus it can be used to determine r. that is why you can use radiusxsigma = 0xsigma, nominally r is set to about 3 sigma. But if you specify radius, then you still need to specify sigma. note that if you use radiusx65000, you change the gaussian shape into a linear roll-off
Re: sigma and radius arguments for -blur and -gaussian-blur
Posted: 2010-07-01T12:35:07-07:00
by coulon
fmw42 wrote:r defines the extent or size of the filter, sigma determines the roll-off of the gaussian shape. but after about 2-3 sigma, the gaussian has rolled down to near zero, thus it can be used to determine r. that is why you can use radiusxsigma = 0xsigma, nominally r is set to about 3 sigma. But if you specify radius, then you still need to specify sigma. note that if you use radiusx65000, you change the gaussian shape into a linear roll-off
Then I think the documention should say - I hesitate to speak LaTeX - :
Convolve the image with a Gaussian or normal distribution. The formula is:
Let r be the distance from origin (r2 = u2 + v2) and σ be the standard deviation of the Gaussian distribution.
If r<radius then
G(u,v)=the regular Gaussian formula
else
G(u,v)=0
endif
As a guideline, set radius to approximately 3σ. Specify a radius of 0 and ImageMagick selects a suitable radius for you.
Re: sigma and radius arguments for -blur and -gaussian-blur
Posted: 2010-07-01T13:23:03-07:00
by fmw42
see
http://www.imagemagick.org/script/comma ... s.php#blur. seems to say pretty much that, though not quite in those words.
Re: sigma and radius arguments for -blur and -gaussian-blur
Posted: 2010-07-01T19:13:11-07:00
by anthony
fmw42 wrote:r defines the extent or size of the filter, sigma determines the roll-off of the gaussian shape. but after about 2-3 sigma, the gaussian has rolled down to near zero, thus it can be used to determine r. that is why you can use radiusxsigma = 0xsigma, nominally r is set to about 3 sigma. But if you specify radius, then you still need to specify sigma. note that if you use radiusx65000, you change the gaussian shape into a linear roll-off
Just as a FYI. if the radius argument is set to 0 it will be set to something about 3 times the sigma.
However the exact forumula used is very complex as what it really does is determine the radius at which the gaussian function does not produce enough 'weight' relative to the Integer Quality of the Imagemagick being used. That is to say the contribution is so small, that it becomes smaller than the 'quantum rounding' effects of using integers to hold the image. As such the actual R really depends not only on sigma, but also the Quality of your specific IM compilation.
NOTE this radius also is different for Blur (using 2 1-dimensional convolutions) than for Gaussian (using a larger, slower, single 2-dimensional convolution).
The result is that the largest possible radius, that will still produce meaningful results for the IM version being used will be calculated.
Re: sigma and radius arguments for -blur and -gaussian-blur
Posted: 2010-07-01T19:21:03-07:00
by anthony
coulon wrote:fmw42 wrote:The formula is:
Let r be the distance from origin (r2 = u2 + v2) and σ be the standard deviation of the Gaussian distribution.
If r<radius then
G(u,v)=the regular Gaussian formula
else
G(u,v)=0
endif
As a guideline, set radius to approximately 3σ. Specify a radius of 0 and ImageMagick selects a suitable radius for you.
Again it isn't really like that!
The 'radius' argument is ONLY used to determine the size of the convolution kernel.
That is a -gaussian 3x1 will calculate a 2-dimentional gaussian distribute of sigma=1, into a square array that is 2x{radius}+1 or a 7x7 array.
With a recent version of ImageMagick you can now even have it output this calculated array using the new -morphology operators.
For an example of this see....
http://www.imagemagick.org/Usage/convolve/#gaussian
where a sigma = 0.8 kernel was printed. You can see from that example that for my IM Q16
the array was calculated to be 7x7 thus it calculated a internel radius=3 for this kernel.
The 'blur' kernel (next section) also calculated a radius of 3 for 0.8 though typically it is slightly bigger for 1-dimensional blurring kernels.
Re: sigma and radius arguments for -blur and -gaussian-blur
Posted: 2010-07-01T19:40:54-07:00
by anthony
I have updated the documentation for both -blur and -gaussian-blur, to make it clearer, as the text was designed with a different 'formula image' than what is now provided.
It may take a bit of time to appear online.