sigma and radius arguments for -blur and -gaussian-blur
sigma and radius arguments for -blur and -gaussian-blur
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?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: sigma and radius arguments for -blur and -gaussian-blur
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.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: sigma and radius arguments for -blur and -gaussian-blur
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
Then I think the documention should say - I hesitate to speak LaTeX - :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
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: sigma and radius arguments for -blur and -gaussian-blur
see http://www.imagemagick.org/script/comma ... s.php#blur. seems to say pretty much that, though not quite in those words.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: sigma and radius arguments for -blur and -gaussian-blur
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: sigma and radius arguments for -blur and -gaussian-blur
Again it isn't really like that!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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: sigma and radius arguments for -blur and -gaussian-blur
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.
It may take a bit of time to appear online.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/