Evaluate Gaussian Noise

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Evaluate Gaussian Noise

Post by anthony »

I am having trouble with Evaluate Gaussian Noise.

Creating a 100x100 50% gray image and adding noise to it should get a pretty uniform histogram of the noise that was added.

For example...

Code: Select all

   convert -size 100x100 xc:gray50 -evaluate gaussian-noise 0.1 histogram:guassian_noise_0.1.gif
Image
shows a rather nice histogram of the gaussian noise that was generated. That is it follows a very nice an clear bell curve, though it is very narrow to what I need.

Increasing the noise factor and instead of a steadily increasing the value works but only until it reaches a value of 0.125, where it suddenly goes crazy!

Code: Select all

   convert -size 100x100 xc:gray50 -evaluate gaussian-noise 0.125 histogram:gaussian_noise_0.125.gif
Image
A valus of 0.124 produces a result similar to the previous example. But as you can see a value of 0.125 suddenly produces a result where most values are being clipped to the range limits (the sides of the above histogram). Almost like the value suddely becomes very very large!

Just to give you something to compare too. This is the histogram of purely random noise, without any clipping.

Code: Select all

convert -size 100x100 xc:gray50 +noise random histogram:random_noise.gif
Image

Something is not right with the handling of the value in -evaluate Gaussian-noise.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Evaluate Gaussian Noise

Post by fmw42 »

it is a narrow gaussian, but could be correct as we only have control over the amplitude and not the width (rollo-off) ie sigma.

shows the same thing with

-attenuate 0.1 +noise Gaussian
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Evaluate Gaussian Noise

Post by anthony »

But isn't the value adjusting the amount that is added/subtracted from the existing values? In that case the histogram should show the width changing. It doesn't.

The histogram of the image without any changes is a single value 'impulse' for the solid color that is present. Small gaussian values produce a small curve.

But then why the sudden change from a nice guassian curve to a clipped numbers (most number suddenly becomming maximum and minimum values) somewhere between 0.124 and 0.125 that does not make sense! gaussian is a smooth function so should smoothly change regardless of what the value is adjusting!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Evaluate Gaussian Noise

Post by anthony »

this bug has come up in a user discussion...
viewtopic.php?f=1&t=14850
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Evaluate Gaussian Noise

Post by magick »

We can reproduce the problem you posted and will have a patch in the Subversion trunk by sometime tomorrow. Thanks.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Evaluate Gaussian Noise

Post by anthony »

With the fix now provided the 'small' gaussian values now produce a small gaussian distribution. VERY small. A value of 15 now produces a gaussian distribution with some pixels 'clipped' but covering the full range of values.

Code: Select all

convert -size 100x100 xc:gray50 \
     -evaluate gaussian-noise 15 histogram:gaussian_noise_fixed_15.gif
Image

And this is what a strong gaussian random image of looks like...

Code: Select all

convert -size 100x100 xc:gray50 \
     -evaluate gaussian-noise 5 gaussian_noise.png
Image

Note that the colors are all 'grayish' on average.

So the question is what does '15' mean? It does not seem to mean sigma in color distance, or perhaps it is a percentage of color range? That looks about right.

NOTE: you can get the same effect using +noise and -attenuate

Code: Select all

convert -size 100x100 xc:gray50 -attenuate 5 +noise gaussian gaussian_noise.png
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Evaluate Gaussian Noise

Post by magick »

Gaussian noise requires 2 sigma values. Unfortunately the command line only accepts one so we default sigma1 to 4 and sigma2 to 20 and use the command line parameter as an attenuation factor. Use it to spread or narrow the gaussian distribution.
Post Reply