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

VARIABLEBLUR


Applies a variable blur to an image based upon a mask image.

Download Script

last modified: June 02, 2015



USAGE: variableblur [-m maxblur] [-n numblurs] infile maskfile outfile
USAGE: variableblur [-h or -help]

-m .... maxblur ....... maximum blur amount in pixels; integer>1;
....................... recommend even values; default=16
-n .... numblurs ...... number of blur increments; 2<=integer<maxblur;
....................... default=maxblur-1

PURPOSE: To apply a variable blur to an image based upon a mask image.

DESCRIPTION: VARIABLEBLUR applies a variable blur to an image based upon a mask image. The brighter the mask image the larger the blur. Limiting factors are determined by the user supplied parameters: maxblur and numblurs. This is most useful when the mask is a radial gradient. It then blurs around the main subject of the image.

ARGUMENTS:

-m maxblur ... MAXBLUR is the maximum amount of blur in pixels when the mask image is fully white. No blur is applied where the image is fully black. Values must be integers>1. Typical values are less than or equal to 32. The default is 16.

-n numblurs ... NUMBLURS is the number of evenly spaced blur increments up to maxblur. Values are integers between 2 and maxblur-1. The default=maxblur-1. For improved performance with slight loss of quality when maxblur is large, use numblurs=maxblur/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


Flower 1
http://www.jhlabs.com/ip/filters/

Flower 1

Mask - Radial Gradient
convert -size 240x160 xc: -fx \
"xx=i-w/2; yy=j-h/2; rr=hypot(xx,yy); rr/hypot(w/2,h/2)" \
maskfile.jpg

 

 

Arguments:
-m 8 -n 4

Arguments:
-m 16 -n 8

Arguments:
-m 32 -n 16



Zelda

Flower 1

Mask - Exponentiated Radial Gradient
convert -size 128x128 xc: -fx \
"xx=i-w/2; yy=j-h/2; rr=hypot(xx,yy); uu=rr/hypot(w/2,h/2) (10^(uu)-1)/9" \
maskfile.jpg

 

 

Arguments:
-m 8 -n 4

Arguments:
-m 12 -n 6

Arguments:
-m 16 -n 8



Flower 2
http://www.jhlabs.com/ip/filters/

Flower 2

Red Channel

Mask - White Thresholded Red Channel
convert flower_rose.jpg -channel Red \
-separate -white-threshold 50% \
maskfile.jpg

Arguments:
-m 8 -n 4

Arguments:
-m 16 -n 8

Arguments:
-m 32 -n 16



Flower 2
http://www.jhlabs.com/ip/filters/

Flower 2

Red Channel

Mask - Negated White Thresholded Red Channel
convert flower_rose.jpg -channel Red \
-separate -white-threshold 50% -negate \
maskfile.jpg

Arguments:
-m 8 -n 4

Arguments:
-m 16 -n 8

Arguments:
-m 32 -n 16



What the script does is as follows:

  • Creates up to 16 incrementally increasing blurred versions of the image
  • Interpolates between the blurred images

This is equivalent to the following IM commands

  • ww=`convert $tmp0 -format "%w" info:`
  • hh=`convert $tmp0 -format "%h" info:`
  • blurinc=`convert xc: -format "%[fx:$maxblur/$numblurs]" info:`
  • images="$tmp0"
  • blur=$blurinc
  • j=1
  • while [ $j -le $numblurs ]; do
  • eval img=\$tmp$j
  • max=`convert xc: -format "%[fx:100*$blur]" info:`
  • min=`convert xc: -format "%[fx:100/$blur]" info:`
  • convert $tmp0 -filter box -resize $min% -filter lanczos -resize ${ww}x${hh}! $img
  • images="$images $img"
  • blur=`convert xc: -format "%[fx:$blur + $blurinc]" info:`
  • blurc=`convert xc: -format "%[fx:ceil($blur)]" info:`
  • [ $blurc -gt $maxblur ] && break
  • j=`expr $j + 1`
  • done
  • images="$images $tmpM"
  • count=$j
  • count1=`expr $j + 1`
  • convert $images -monitor -fx \
    "aa=$count*u[$count1]; xx=floor(aa); ff=aa-xx; yy=xx+1; u[xx]+ff*(u[yy]-u[xx])" \
    $outfile