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

NIGHTVISION


Simulates a picture as viewed through night vision goggles.

Download Script

last modified: April 25, 2015



USAGE: nightvision [-b brightness] [-d diameter] [-r rolloff] [-n noise] [-s seed] infile outfile
USAGE: nightvision [-help]

-b ... brightness ... brightness of night view; 0<=integer<=200; default=100
-d ... diameter ..... vignette diameter expressed as a percent of the image
..................... dimensions; 0<=integer<=100; default=60
-r ... rolloff ...... vignette ramp rolloff; -100<=integer<=100;
..................... larger values lengthen the ramp and shorter values
..................... shorten the ramp; default=0 is linear ramp to most
..................... distant image point.
-n ... noise ........ noise amount; float>=0; default=2
-s ... seed ......... seed value for noise; integer>=0; default=100
-B ... blooming ..... include blooming effect; choices are yes or no;
..................... default=no
-T ... threshold .... blooming threshold; 0<=float<=100; default=5

PURPOSE: To simulate a picture as viewed through night vision goggles.

DESCRIPTION: NIGHTVISION simulates a picture as viewed through night vision goggles. The brightness and noise in the view may be adjusted as well as vignetting and blooming.

ARGUMENTS:

-b brightness ... BRIGHTNESS of the night view. Values are integers between 0 and 200. The default=100.

-d diameter ... DIAMETER of the vignetting. It is a relative size expressed as a percent of the image dimensions. Values are integers between 0 and 100. The default=60.

-r rolloff ... ROLLOFF of the vignette ramping. Values are integers between 0 and 100. Larger values lengthen the ramp and shorter values shorten the ramp. The default=0 is a linear ramp to the most distant image point.

-n noise ... NOISE amount added to the image. Values are floats>=0. The default=2.

-s seed ... SEED value for the random noise. Values are integers>=0. The default=100.

-B blooming ... BLOOMING is a flag to include/exclude a blooming effect at very bright locations. The choices are yes or no. The default=no.

-T threshold ... THRESHOLD locates some pixels that are the brightest for for use with the blooming effect. Value are floats between 0 and 100. The default=5.

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

Original

Arguments:
(defaults)



Example 2 - Variation of Arguments

Original

Arguments:
-b 100 -d 60 -r 0 -n 2 -s 100
(defaults)

Arguments:
-b 50 -d 60 -r 0 -n 2 -s 100
(darker)

Arguments:
-b 100 -d 60 -r -20 -n 2 -s 100
(shorter vignette rolloff)



Example 3 - Variation of Blooming

Original
(source)

Arguments:
-b 100 -d 60 -r 0 -n 2 -s 100 -B no
(defaults)

Arguments:
-b 100 -d 60 -r 0 -n 2 -s 100 -B yes -T 5



What the script does is as follows:

  • Adds noise to the image and converts it to grayscale
  • Composites the grayscale image with a green image according to the brightness
  • Creates a ramped elliptical mask
  • Composites black with the image according to the mask to create the vignetting

This is equivalent to the following IM commands.

  • convert -quiet -regard-warnings "$infile" +repage "$tmpA1"
  • ww=`identify -ping -format "%w" $tmpA1`
  • hh=`identify -ping -format "%h" $tmpA1`
  • ww2=`convert xc: -format "%[fx:$ww/2]" info:`
  • hh2=`convert xc: -format "%[fx:$hh/2]" info:`
  • xc=$ww2
  • yc=$hh2
  • ww2=`convert xc: -format "%[fx:$ww2*$diameter/100]" info:`
  • hh2=`convert xc: -format "%[fx:$hh2*$diameter/100]" info:`
  • args="0,0 $ww2,$hh2 0,360"
  • rampval=`convert xc: -format "%[fx:100-abs($rolloff)]" info:`
  • test=`convert xc: -format "%[fx:sign($rolloff)<0?0:1]" info:`
  • if [ $test -eq 0 ]; then
    leveling="-level 0x$rampval%"
    else
    leveling="+level 0x$rampval%"
    fi
  • convert \( $tmpA1 -attenuate $noise -seed $seed +noise gaussian \
    $setcspace -colorspace gray \) \
    \( -clone 0 -fill green1 -colorize $brightness% \) \
    -compose multiply -composite \
    \( -clone 0 -fill white -colorize 100% -fill black \
    -draw "translate $xc,$yc ellipse $args" -alpha off \
    -morphology Distance Euclidean:4 \
    -auto-level $leveling \) \
    \( -clone 0 -fill black -colorize 100% \) \
    +swap -compose over -composite \
    $outfile