Simulating Film Grain

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?".
quickbrownfox

Simulating Film Grain

Post by quickbrownfox »

Hi all,

I've been working on a script to create old-looking Holga-style photos. I'm pretty happy with the results so far, but I think some film grain might be in order. I've spent quite a bit of time googling, but haven't found a way to add film grain with Imagemagick. Does anyone know of a good way to do this?

Thanks in advance,

Mike
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Simulating Film Grain

Post by fmw42 »

see http://en.wikipedia.org/wiki/Image_noise#Film_grain

+noise gaussian

or

+noise poisson

should do it
quickbrownfox

Re: Simulating Film Grain

Post by quickbrownfox »

fmw42 wrote:see http://en.wikipedia.org/wiki/Image_noise#Film_grain

+noise gaussian

or

+noise poisson

should do it
Thanks for the reply. Is there a way to change the amount of noise? Both gaussian and poisson gave me an image that was way too noisy. Maybe I need to composite the result onto a copy of my original?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Simulating Film Grain

Post by magick »

Try -attenuate.
quickbrownfox

Re: Simulating Film Grain

Post by quickbrownfox »

Thanks, but even the lowest value of attenuate that would do anything is far too noisy. Using "-attenuate 0.1249" gave me an image with no noise whatsoever while "-attenuate 0.1250" produced an image that was almost completely noise. Am I doing something wrong here?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Simulating Film Grain

Post by fmw42 »

you can also build a noise image separate from your image, then use convert image noiseimage -compose mathematics "A,B,C,D" -composite result

you want to mix the two images as image + atten*(noiseimage - 0.5) as you want positive and negative noise relative to midgray. So I believe that means A=0, B=atten, C=1, D=-0.5*atten


see http://www.imagemagick.org/script/comma ... hp#compose
and http://www.imagemagick.org/Usage/compose/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Simulating Film Grain

Post by anthony »

I noted the 0.125 fault for gaussian noise generation in the Bugs forum...
viewtopic.php?f=3&t=14863
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
vale

Re: Simulating Film Grain

Post by vale »

Hi.

To simulate film grain try:
  • ( +clone +level-colors GREY50 -attenuate 6 +noise Poisson -colorspace Gray ) -compose Overlay -composite
The above should be placed last in the command sequence.

'attenuate'
means (in this context) 'thin out'. Consequently, the smaller the factor; the more tenuous the result. For a simulation of film grain you need dense, closely packed grain. More noise; not spread out (attenuated) noise. This may be counter-intuitive; try the command.

(Edit: hangover caused nonsense to appear. Apologies for the original version if you saw it)

V.
Last edited by vale on 2009-10-22T01:38:18-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Simulating Film Grain

Post by anthony »

Using 6 only makes it worse!!!!

Their is something not right in the code.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
vale

Re: Simulating Film Grain

Post by vale »

I should have added that the above commands are for BW. Remove the -colorspace Gray bit, for colour.

V.
quickbrownfox

Re: Simulating Film Grain

Post by quickbrownfox »

Thanks, Vale. I'll give this a shot.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Simulating Film Grain

Post by fmw42 »

here is another approach from GIMP, see http://www.gimpguru.org/Tutorials/FilmGrain/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Simulating Film Grain

Post by anthony »

The gaussian noise has been fixed, though the 'attenuation' value meaning has changed slightly.

See viewtopic.php?f=3&t=14863
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: Simulating Film Grain

Post by fmw42 »

so what does the new "attenuate" mean for gaussian and other noise?

The options page says,

"Lessen (or intensify) when adding noise to an image."

but does this mean amplitude or sigma? Perhaps Anthony could make an example on his pages and explain this.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Simulating Film Grain

Post by anthony »

the attenuate is supposed to adjust the amount of 'error' added. this in term equates to the difference between the original value and the final value. As such the larger the attenuation the larger the 'sigma' of the error.

As for the actual meaning. I asked Magick about that in the other thread, and he wasn't very clear, saying that two sigma values are involved, though I can't see how that could be.

However looking at things for Gaussian it looks like the attenuation is roughly a percentage of the value range. which makes some sense. However this is only guess on my part. It looks like some source diving will be needed to actually find out its correctly meaning.

At least it now does not just 'go crazy' at a value of 1.25
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply