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.

REDEYE


Removes redeye from an image.

Download Script

last modified: December 15, 2018



USAGE: redeye [-k kind] [-l light] [-s sat] [-f fuzz] [-i inc] [-b begin] [-e end] [-d dilate] [-t type] [-r rad] "x1,y1 x2,y2 ..." infile outfile

USAGE: redeye [-k kind] [-l light] [-s sat] [-f fuzz] [-i inc] [-b begin] [-e end] [-d dilate] [-t type] [-r rad] -p point_file infile outfile

USAGE: redeye [-h or -help]

"x1,y1 x2,y2 ..." ... x,y coordinates in image where redeye needs
..................... to be corrected; one or more point pairs
..................... are allowed; atleast one pair must be provided;
..................... list pair list must be specified just prior
..................... to the infile
-p ... point_file ... text file containing list of point pairs;
..................... one x,y pair per line
-k ... kind ......... kind of image to process for redeye region:
..................... 1 is image or 2 is HSB saturation channel;
..................... default=1
-l ... light ........ desired lightness; 0<=integer<=100; default=15
-s ... sat .......... desired saturation; 0<=integer<=100; default=0
-f ... fuzz ......... fuzz value for redeye floodfill; 0<=float<=100;
..................... nominal 15 to 20; default is for automatic
..................... detection of optimal fuzz value
-i ... inc .......... fuzz iteration increment in automatic mode;
..................... 0<integer<100; default=5
-b ... begin ........ fuzz interation begin value in automatic mode;
..................... 0<integer<100; default=10
-e ... end .......... fuzz interation end value in automatic mode;
..................... 0<integer<100; default=50
-d ... dilate ....... dilation amount to increase the size of the
..................... detected redeye areas; integer>=0; default=1
-t ... type ......... type of white specular reflection processing;
..................... choices are: desat or remove; default=desat
-r ... rad .......... radius of white specular reflection region
..................... float>0; default=3

PURPOSE: To remove redeye from an image.

DESCRIPTION: REDEYE removes redeye from an image. It does so by the user specifying coordinates in each redeye area. Processing then floodfills at those coordinates either in the image or the saturation channel to create a mask. The mask is then used with a desaturated version of the image and the original image to modify the color of the redeye areas. The white specular component inside the redeye region may optionally be removed. The user may specify a particular fuzz value to use or let the script attempt to find an optimal value.

ARGUMENTS:

"x1,y1 x2,y2" ... x,y coordinates in the image where redeye needs to be corrected. One or more point pairs are allowed. Atleast one pair must be provided. IMPORTANT: the list of point pairs must be specified just prior to infile.

-f point_file ... point-file is a text file containing the list of point pairs, one x,y pair per line. Atleast one pair must be provided.

-k kind ... KIND of image to process for redeye region. Choices are: 1 for input image or 2 for the HSB saturation channel. The default=1

-l light ... LIGHT is the desired lightness in the redeye area. Values are 0<=integer<=100. The default=15

-s sat ... SAT is the desired saturation in the redeye area. Values are 0<=integer<=100. The default=0

-f fuzz ... FUZZ is the desired fuzz value for the redeye floodfill. Values are in the range of 0<=float<=100 . Nominal values appear to be about 15 to 20 from limited testing. The default is for automatic interative detection of an optimal fuzz value. This usually works reasonably well, but tends to be an under estimate. It seems to work better for the saturation channel than the image, but tends to be more underestimated in the former case. In the latter case, it can overestimates more frequently than in the former case. To correct for understimation either increase the value reported or increase the dilation argument. For overstimation reduce the fuzz value.

-i inc ... INC is the fuzz iteration increment in automatic mode. Values are 0<integer<100. The default=5

-b begin ... BEGIN is the fuzz interation begin value in automatic mode. Values are 0<integer<100. The default=10

-e end ... END is the fuzz interation end value in automatic mode. Values are 0<integer<100. The default=50

-d dilate ... DILATE is the dilation amount to increase the size of the detected redeye areas. Values are integers>=0. The default=1

-t type ... TYPE of white specular reflection processing. The choices are: desat (d) for desaturation or remove (r). The default=desat

-r rad ... RAD is the radius of the white specular reflection region. Values are floats>0. The default=3

REQUIREMENTS: IM 6.5.9-0 in order to support the -morphology methods used in the script. However, due to possible bugs, it may require at least IM 6.5.9-3

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

(Image Source)

Arguments:
-t desat -d 0

Arguments:
-t remove -d 0



Example 2

(Image Source)

Arguments:
-t desat

Arguments:
-t remove



Example 3

(Image Source)

Arguments:
-t desat

Arguments:
-t remove



Example 4

(Image Source)

Arguments:
-t desat -f 15 -r 4

Arguments:
-t remove -f 15 -r 4



What the script does is as follows for type=desat and fuzz specified:

  • Create a desaturate copy of the input image
  • Perform a fuzzy floodfill to create a mask image
  • Composite the original with the desaturated image using the mask image
  • Apply a morphologic close operation to fill in the specular hole in the mask
    and then create a difference operation to create a new mask of just the hole
  • Apply the new mask to composite the previous result with a full lightness,
    zero saturation version of the original image

This is equivalent to the following IM commands for type=desat and fuzz specified:

  • convert -quiet -regard-warnings "$infile" +repage "$tmpA1"
  • convert $tmpA1 -modulate $light,$sat,100 $tmpA2
  • proc=""
  • for ((i=0; i<np; i++)); do
    proc="$proc matte ${pairArray[i]} floodfill"
    done
  • convert $tmpA5 -fuzz $fuzz% -fill none -draw "$proc" \
    -fill "rgba(255,255,255,1)" +opaque "rgba(0,0,0,0)" \
    -fill "rgba(0,0,0,1)" -opaque "rgba(0,0,0,0)" \
    -alpha off -negate $tmpA3
  • if [ "$dilate" = 0 ]; then
    dilation=""
    else
    dilation="-morphology dilate disk:$dilate"
    fi
  • convert $tmpA1 $tmpA2 $tmpA3 -compose over -composite $tmpA2
  • convert $tmpA3 \( +clone -morphology close disk:$rad $dilation \) \
    -compose difference -composite -auto-level \
    -negate -threshold 0 -negate $tmpA4
  • convert $tmpA2 \( $tmpA1 -modulate 100,0,100 \) $tmpA4 \
    -compose over -composite $outfile