Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php

FILMGRAIN


Applies film grain noise to an image.

Download Script

last modified: September 26, 2017



USAGE: filmgrain [-n noise] [-a amount1] [-A amount2] [-d density1]
[-D density2] [-s seed1] [-S seed2] [-c compose1] [-C compose2]
[-b blur] [-m monotone] infile outfile

USAGE: filmgrain [-h or -help]

-n ... noise ...... type of noise; any valid IM noise, except random;
................... default=gaussian
-a ... amount1 .... amount of the first layer of noise; integer>=0;
................... default=100
-A ... amount2 .... amount of the second layer of noise; integer>=0;
................... default=50
-d ... density1 ... density of the first layer of noise; 0<=integer<=100
................... default=100
-D ... density2 ... density of the second layer of noise; 0<=integer<=100
................... default=100
-s ... seed1 ...... seed value for the first layer of noise; integer>=0;
................... default=100
-S ... seed2 ...... seed value for the second layer of noise; integer>=0;
................... default=200
-c ... compose1 ... compose method for the first layer of noise; choices are:
................... overlay, softlight, hardlight, linearlight, vividlight;
................... default=overlay
-C ... compose2 ... compose method for the second layer of noise; choices are:
................... overlay, softlight, hardlight, linearlight, vividlight;
................... default=overlay
-b ... blur ....... blur amount to soften noise; float>=0; default=0.5
-m ... monotone ... use monotone (grayscale) noise rather than color noise;
................... choices are yes or no.

PURPOSE: To apply film grain noise to an image.

DESCRIPTION: FILMGRAIN applies film grain noise to an image. One or two layers of noise may be applied. The amount and density of each layer of noise may be controlled separately as well as the compose methods.

ARGUMENTS:

-n noise ... NOISE is the type of noise; any valid IM noise, except random is allowed. The default=gaussian. Most of the noise types look rather similar on first glance with the appropriate amounts. Isolated noise can be simulated by reducing the density on the other noise types. Actual film grain is closestly approximated by the gaussian noise.

-a amount1 ... AMOUNT1 is the amount of the first layer of noise. Value are integers>=0. The default=100.

-A amount2 ... AMOUNT2 is the amount of the second layer of noise. Value are integers>=0. The default=50.

-d density1 ... DENSITY1 is the density (spacing) of the first layer of noise. Values are 0<=integers<=100. The default=100.

-D densityD ... DENSITY2 is the density (spacing) of the second layer of noise. Values are 0<=integers<=100. The default=100.

-s seed1 ... SEED1 is the seed value for the first layer of noise. Values are integers>=0. The default=100.

-S seed2 ... SEED2 is the seed value for the second layer of noise. Values are integers>=0. The default=200.

-c compose1 ... COMPOSE1 is the compose method for the first layer of noise. Choices are: overlay, softlight, hardlight, linearlight and vividlight. The default=overlay.

-C compose2 ... COMPOSE2 is the compose method for the second layer of noise. Choices are: overlay, softlight, hardlight, linearlight and vividlight. The default=overlay.

-b blur ... BLUR amount to soften noise. Values are floats>=0. The default=0.5.

-m monotone ... MONOTONE indicates to use monotone (grayscale) noise rather than color noise. Choices are: yes or no.

REFERENCES:
http://en.wikipedia.org/wiki/Image_noise#Film_grain
http://www.ephotozine.com/article/photoshop-tutorial--add-film-grain-to-images-13443
http://www.photoshopessentials.com/photo-effects/film-grain/
http://photoshoptutorials.ws/photoshop-tutorials/photo-effects/natural-film-grain/?singlepage=1
http://www.digiretus.com/tippek/cikkiro.php?SORSZAM=79

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


EXAMPLES

Example 1 - Default

Original
(image)

Arguments:
(default)
-a 100 -A 50 -d 100 -D 100



Example 2 - Variation In Second Layer Noise Amount

Original

Arguments:
-a 100 -A 0

Arguments:
-a 100 -A 100



Example 3 - Variation In First Layer Density

Original

Arguments:
-a 100 -A 0 -d 100

Arguments:
-a 100 -A 0 -d 70

Arguments:
-a 200 -A 0 -d 100

Arguments:
-a 200 -A 0 -d 30



Example 4 - Variation In First Layer Compose Method

Original

Arguments:
(softer noise)
-a 100 -A 0 -c softlight

Arguments:
(normal noise)
-a 100 -A 0 -d overlay

Arguments:
(brighter noise)
-a 100 -A 0 -c vividlight

Arguments:
(darker noise)
-a 100 -A 0 -c hardlight

Arguments:
(brighter and darker noise)
-a 100 -A 0 -c linearlight

 

 


Example 5 - Variation In First Layer Noise Type

Original

Arguments:
-a 50 -A 0 -n impulse

Arguments:
-a 125 -A 0 -n gaussian

Arguments:
-a 200 -A 0 -n laplacian

Arguments:
-a 75 -A 0 -n multiplicative

Arguments:
-a 100 -A 0 -n poisson

Arguments:
-a 2000 -A 0 -n uniform



Example 6 - Grayscale vs Color Noise

Original

Arguments:
(grayscale)
-a 100 -A 50 -d 100 -D 100 -m yes

Arguments:
(color)
-a 100 -A 50 -d 100 -D 100 -m no



What the script does is as follows:

  • Create a 50% gray image the same size as the input image
  • Apply the desired amount of (gaussian) noise
  • Extract one channel as grayscale
  • Reduce the density of the noise if desired
  • Blur a slight amount to soften the noise
  • Composite the noise image with the input image
  • Repeat with a new noise image for the second layer of noise

This is equivalent to the following IM commands

  • convert -quiet -regard-warnings "$infile" +repage "$dir/tmpI.mpc"
  • amt1=`convert xc: -format "%[fx:$amount1/100]" info:`
  • amt2=`convert xc: -format "%[fx:$amount2/100]" info:`
  • convert $dir/tmpI.mpc -fill "gray(50%)" -colorize 100% $dir/tmpG.mpc
  • fuzzval1=`convert xc: -format "%[fx:(100-$density1)/2]" info:`
  • densityproc1="-fuzz $fuzzval1% -fill gray(50%) -opaque gray(50%)"
  • fuzzval2=`convert xc: -format "%[fx:(100-$density2)/2]" info:`
  • densityproc2="-fuzz $fuzzval2% -fill gray(50%) -opaque gray(50%)"
  • if [ "$monotone" = "yes" ]; then
    monoproc="-set colorspace RGB -channel G -separate +channel"
    else
    monoproc=""
    fi
  • convert $dir/tmpI.mpc \
    \( $dir/tmpG.mpc -attenuate $amt1 -seed $seed1 +noise $noise $monoproc $densityproc1 -blur 0x$blur \) \
    -compose $compose1 -composite \
    \( $dir/tmpG.mpc -attenuate $amt2 -seed $seed2 +noise $noise $monoproc $densityproc2 -blur 0x$blur \) \
    -compose $compose2 -composite $outfile