Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial (non-profit) 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

    Please read the Pointers For Use on my home page to properly install and customize my scripts.

GREENSCREEN


Removes background green color in a green screen image.

Download Script

last modified: May 03, 2019



USAGE: greenscreen [-t thresh] [-a area] [-s sat] [-b bgcolor] [-A antialias] infile [bgfile] outfile
USAGE: greenscreen [-h or -help]

-t ... thresh ...... threshold of mask image used to remove green; 0<=integer<=100;
.................... default=0
-a ... area ........ area threshold for removal of remnant areas in mask image;
.................... integer>=0; default=2000
-s ... sat ......... saturation of remnant green color; 0<=integer<=100; default=0
-b ... bgcolor ..... background color; any opaque Imagemagick color may be specified
.................... the default=none
-A ... antialias ... antialias amount; integer>=0; default=2

PURPOSE: Removes background green color in a green screen image.

DESCRIPTION: GREENSCREEN removes background green color in a green screen image. The background may be replace with transparency, another color or an optional second image.

Arguments:

-t thresh ... THRESH is the threshold value used to create the mask image used to remove green. Values are 0<=integer<=100. The default=0.

-a area ... AREA threshold value for removal of remnant areas in the mask image. Values are integer>=0. The default=2000.

-s sat ... SAT is the desired saturation of remnant green color. Value are 0<=integer<=100. The default=0.

-b bgcolor ... BGCOLOR is the desired background color. Any opaque Imagemagick color may be specified. The default=none (transparent).

-A antialias ... ANTIALIAS amount. Values are integer>=0. The default=2.

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
(source)

Arguments:
-t 22 -a 2000 -s 0 -A 2 -b none
(defaults)

Arguments:
-t 22 -a 2000 -s 0 -A 2 -b pink



Example 2

Original
(source)

Arguments:
-t 22 -a 1000 -s 0 -A 2 -b none
(defaults)



Example 3

Original
(source)

Arguments:
-t 22 -a 2000 -s 0 -A 2 -b none
(defaults)



What the script does is as follows:

  • Read the input
  • Converts the image to LAB
  • Negates the B channel and multiplies it with the A channel
  • Thresholds the product
  • Uses connected components processing to remove small regions
  • Puts the result into the alpha channel of the input
  • Desaturates green
  • Saves the output