Monochromatic Noise

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Monochromatic Noise

Post by fmw42 »

OK. I figured out how to do monochromatic noise. You have to separate channels and use the same seed on all channels and then combine. But note you need to be sure to use -set colorspace RGB so that the channels are kept as non-linear rather than as linear grayscale. Otherwise, the result is too dark


convert zelda3.png -set colorspace RGB -separate -seed 1000 -attenuate 1 +noise gaussian -combine zelda_gaussian_mono_1a.png

or

convert zelda3.png -set colorspace RGB -separate -seed 1000 -attenuate 1 +noise gaussian -combine -colorspace RGB zelda_gaussian_mono_1b.png

Image


P.S.:

This also works, but is ever so slightly darker. So I am not sure which is the better approach.

convert zelda3.png -separate -seed 1000 -attenuate 1 +noise gaussian -combine -colorspace sRGB zelda_gaussian_1d.png


Image
Last edited by fmw42 on 2012-07-08T12:23:43-07:00, edited 2 times in total.
djkprojects
Posts: 21
Joined: 2012-07-06T04:44:48-07:00
Authentication code: 13

Re: Monochromatic Noise

Post by djkprojects »

fmw42 wrote:
and I thought that that might be the way to go so could you please tell me how this could be implemented? I understand that the line length would then work as radius in the example above.
Note sure if this would be radius 2
filt="\
1 0 0 0 0 \
0 1 0 0 0 \
0 0 1 0 0 \
0 0 0 1 0 \
0 0 0 0 1 "

or (one sided) as

filt="\
0 0 0 0 0 \
0 0 0 0 0 \
0 0 1 0 0 \
0 0 0 1 0 \
0 0 0 0 1 "


convert image -convolve $filt result

You can do similarly with -morphology convolve/correlate
For big radius values the kernel would be a pretty big array. I've seen somewhere in the Docs here example of transforming one image based on another where the second image was a straight line - I think it was sine + line - can't find it !!! :(
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Monochromatic Noise

Post by fmw42 »

See my post above as I solved the monochromatic noise issue.
I've seen somewhere in the Docs here example of transforming one image based on another where the second image was a straight line - I think it was sine + line - can't find it !!!
I am not sure how this relates to noise?

But perhaps you are thinking about my histmatch script at the link below. But it uses the histograms to generate a 1D lut image that allows one to change the histogam of one image to match that of another.
djkprojects
Posts: 21
Joined: 2012-07-06T04:44:48-07:00
Authentication code: 13

Re: Monochromatic Noise

Post by djkprojects »

fmw42 wrote:See my post above as I solved the monochromatic noise issue.
I've seen somewhere in the Docs here example of transforming one image based on another where the second image was a straight line - I think it was sine + line - can't find it !!!
I am not sure how this relates to noise?

But perhaps you are thinking about my histmatch script at the link below. But it uses the histograms to generate a 1D lut image that allows one to change the histogam of one image to match that of another.
I was referring to Motion-blur problem I have :)

As for the noise discussion:

Code: Select all

-set colorspace RGB -separate -seed 1000 -attenuate 1 +noise gaussian -combine -colorspace RGB


gives pretty good mono noise!!! Thank you.

The:

Code: Select all

-separate -seed 1000 -attenuate 1 +noise gaussian -combine
gives me same results as your syntax for RGB and Gray colorspace images.

If split it into:

Code: Select all

-channel R -seed 1000 -attenuate 1 +noise uniform \
-channel G -seed 1000 -attenuate 1 +noise uniform \
-channel B -seed 1000 -attenuate 1 +noise uniform
I'm getting results identical to PS :o Not sure how this is different from -separate/-combine. It shouldn't - should it ? :shock:

I don't quite understand what -seed does. The manual says "seed a new sequence of pseudo-random numbers" but whatever I set it to 1 or 100000 I can't see any difference plus the noise gets generated only once so if I call the above command twice I get the same noise result (the visible noise pixels stay in same position on the image), without it though i get color noise which is random every time I call the command :shock:
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Monochromatic Noise

Post by fmw42 »

-separate -seed 1000 -attenuate 1 +noise gaussian -combine
If you are on an old IM, then -set colorspace RGB is not needed. Also in my alternate at the end after the combine, -colorspace sRGB may not be needed.

On current IM systems, -separate is now making linear gray rather than non-linear gray.

If I do


convert zelda3.png -separate -seed 1000 -attenuate 1 +noise gaussian -combine zelda_gaussian_mono_1e.png


The result is very dark on my IM 6.7.8.1 Q16.


-seed only chooses the seed value for the random number. if you change it, the distribution will be different, that is the noise will be the same but in different places on the image. if you leave it off, then you get different noise distributions each time you run the command.

Test by just creating noise images with different seeds and then alternate the images rapidly. You will see the noise pattern change.

If you do this, you get colored noise.

convert zelda3.png -channel rgb -seed 1000 -attenuate 1 +noise gaussian +channel zelda_gaussian_mono_1f.png

But if you do this, you get monochromatic noise,

convert zelda3.png \
-channel r -seed 1000 -attenuate 1 +noise gaussian \
-channel g -seed 1000 -attenuate 1 +noise gaussian \
-channel b -seed 1000 -attenuate 1 +noise gaussian \
+channel zelda_gaussian_mono_1h.png

but the distribution is different from my earlier forms, namely,

convert zelda3.png -set colorspace RGB -separate -seed 1000 -attenuate 1 +noise gaussian -combine zelda_gaussian_mono_1a.png
and
convert zelda3.png -separate -seed 1000 -attenuate 1 +noise gaussian -combine -colorspace sRGB zelda_gaussian_mono_1d.png


I am not sure why that would be.

Answer from magick:

Its the interlace pattern.  For the first command you draw from the random pool in RGB order.  First red, then green, then blue.  For the first command you draw from the random pool in channel order.  We first update the red channel for pixel 1, then the red channel for pixel 2, etc.  So we're drawing the same random numbers but applying them in a differ interlace order.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Monochromatic Noise

Post by fmw42 »

I have posted to my web site below a filmgrain (noise) script to add film grain noise to an image.
Post Reply