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.

CRYSTALLIZE


Creates random crystal-like regions in an image

Download Script

last modified: May 07, 2019



USAGE: crystallize [-n number] [-s seed] infile outfile
USAGE: crystallize [-h|help]

-n ... number ... number of randomly placed crystals; integer>0; default=500
-s ... seed ..... seed to randomize placement of crystal; integer>=0; default
................. is totally random and result will not duplicate

PURPOSE: Creates random crystal-like regions in an image.

DESCRIPTION: CRYSTALLIZE creates random crystal-like regions in an image. Each crystal will have a constant color found from the input image at random coordinates. The number of crystals can be adjusted.

ARGUMENTS:

-n number ... NUMBER of randomly placed crystals. Values are integers>0. The default=500.

-s seed ... SEED to randomize the placement of the crystal. Values are integers>=0. The default is totally random placement such that the resulting image will not duplicate.

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

Arguments:
-n 500 -s 1
(defaults)

 

Arguments:
-n 100 -s 1



Example 2

Original Image

Arguments:
-n 500 -s 1
(defaults)

 

Arguments:
-n 100 -s 1



Example 2

Original Image

Arguments:
-n 500 -s 1
(defaults)

 

Arguments:
-n 100 -s 1



What the script does is as follows:

  • Reads the input image
  • Computes the desired number of random x,y pairs
  • Creates a black image with white points drawn at the x,y pair locations
    and puts that image into the alpha channel of the input
  • Exports all the opaque colors with their x,y coordinates using sparse-color:
  • Use those values with -sparse-color voronoi to fill in the transparent pixels
    with the color from the nearest location.
  • Writes the output

This is equivalent to the following IM commands when no mask is used:

  • WxH=`convert -ping $tmpA1 -format "%wx%h" info:`
  • ww=`echo $WxH | cut -dx -f1`
  • hh=`echo $WxH | cut -dx -f2`
  • wwm1=$((ww-1))
  • hhm1=$((hh-1))
  • list=""
  • xseed=$seed
  • yseed=$((seed+1))
  • for ((i=0; i<number; i++)); do
    if [ "$seed" != "" ]; then
    x=`convert xc: -seed $xseed -format "%[fx:round($wwm1*random())]" info:`
    y=`convert xc: -seed $yseed -format "%[fx:round($hhm1*random())]" info:`
    else
    x=`convert xc: -format "%[fx:round($wwm1*random())]" info:`
    y=`convert xc: -format "%[fx:round($hhm1*random())]" info:`
    fi
    list="$list point $x,$y"
    j=$((i+1))
    xseed=$((xseed+i*i))
    yseed=$((yseed+j*j))
    done
  • convert "$infile" \
    \( -clone 0 -fill black -colorize 100 \
    -fill white -draw "$list" \) \
    -alpha off -compose copy_opacity -composite \
    sparse-color:- | \
    convert -size ${ww}x${hh} xc: -sparse-color Voronoi @- "$outfile"