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.

RANDOMBLOB


Creates an image composed of a moderate sized black random blob shape on a white background.

Download Script

last modified: December 15, 2018



USAGE: randomblob [-n numpts] [-l linewidth] [-i isize] [-o osize]
[-s shape] [-b blur] [-t threshold] [-k kind] [-g gsigma] [-c constrain]
[-d drawtype] [-T tension] [-C continuity] [-B bias] [-S seed] [-p pixinc]
[-f file1] [-F file2] [maskfile] outfile

USAGE: randomblob [-h or -help]

-n ... numpts ....... number of random points; integer>0; default=12;
..................... ignored if parameter -f file1 is present
-l ... linewidth .... width of lines or curves drawn between points;
..................... integer>0; default=13
-i ... isize ........ pixel size for inner region and limits for points;
..................... width=height=diameter; ignored when mask;
..................... integer>0; default=400
-o ... osize ........ pixel size of (outer) output image; widthxheight;
..................... if only one value, then it is used for both;
..................... integers>0; default=512
-s ... shape ........ shape of inner region; square or (circular) disk;
..................... ignored when mask provided; default=disk
-b ... blur ......... gaussian blur sigma; nominal value isize/12;
..................... float>0; default=33
-t ... threshold .... percent threshold applied to gaussian blurring;
..................... 0<integer<100; default=25
-k ... kind ......... kind of point distribution; uniform or gaussian;
..................... efault=uniform
-g ... gsigma ....... gaussian distribution sigma; nominal value isize/6;
..................... float>0; default=67
-c ... constrain .... constrain gaussian distribution to inner region;
..................... yes or no; default=yes
-d ... drawtype ..... (straight) line or (KB) spline to connect the points;
..................... default=spline
-T ... tension ...... tension parameter for spline; float; default=0
-C ... continuity ... continuity parameter for spline; float; default=0
-B ... bias ......... bias parameter for spline; float; default=0
-S ... seed ......... seed for random number generator; integer>0;
..................... ignored if paramete -f file1 is present; default=1
-p ... pixinc ....... increment in pixels for spline interpolation;
..................... coarser is faster; but too coarsemay lead long
..................... straight sections; integer>0; default=2
-f ... file1 ........ file containing the desired number of comma separated
..................... pairs of random numbers in range [0,1) with one pair
..................... per line; If provided, it then avoids internal
..................... computation of random numbers; Default is no point file
-F ... file2 ........ file containing the desired number or more comma
..................... separated pairs of random numbers in range [0,1) with
..................... one pair per line; If provided, then the -S seed
..................... parameter is used as and index into the file to locate
..................... the first point pair to use and -n numpts parameter
..................... will be used as the number of successive point pairs
..................... to extract; Default is no point file

If a maskfile is provided, then it should be a white region on a black
background that is trimmed to the minimum bounding box of the white
region, since it supercedes the inner region parameter.

PURPOSE: To create an image composed of a moderate sized black random blob shape on a white background.

DESCRIPTION: RANDOMBLOB creates an image composed of a moderate sized black random blob shape on a white background from a set of uniformly or Gaussian distributed random points. The points are connected by either thick straight lines or thick spline curves, then Gaussian blurred and thresholded to a binary image.

ARGUMENTS:

-l linewidth ... LINEWIDTH is the width of lines or spline drawn between points. Values are integers greater than zero. The default=13.

-i isize ... ISIZE is the pixel size for the inner region where the black blob will be contained. One value is to be provided which will be the width=height=diameter depending upon the shape (square or disk). This parameter is ignored when mask is provided. Values are integers greater than zero. The default=400.

-o osize ... OSIZE is the pixel size of the outer region, i.e. the output image. One or two values may be provided as widthxheight. If only one value is provided, then it is used for both width and height. Values are integers greater than zero. The default=512.

-s shape ... SHAPE is the shape of inner region. Choices are either square [s] or (circular) disk [d]. This parameter is ignored when a mask image is provided. The default=disk.

-b blur ... BLUR is the value for the gaussian blur sigma. The nominal value is about isize/12. Values are floats greater than zero. The default=33.

-t threshold ... THRESHOLD is the percent threshold applied to gaussian blurring. Values are integers greater than zero and less than 100. The default=25.

-k kind ... KIND is the kind of random point distribution. Choices are either uniform [u] or gaussian [g]. The default=uniform.

-g gsigma ... GSIGMA is the gaussian distribution sigma value. The nominal value is about isize/6. Values are floats greater than zero. The default=67.

-c constrain ... CONSTRAIN the gaussian distribution to the inner region. Choices are yes [y] or no [n]. The default=yes.

-d drawtype ... DRAWTYPE is the method to connect the random points. The choices are either (straight) line [l] or (KB) spline [s]. The default=spline.

-T tension ... TENSION is the tension parameter for the spline. Values are floats. Negative values are permitted. The default=0.

-C continuity ... CONTINUITY is the continuity parameter for the spline. Values are floats. Negative values are permitted. The default=0.

-B bias ... BIAS is the bias parameter for the spline. Values are floats. Negative values are permitted. The default=0.

-S seed ... SEED for random number generator or if -F file2 parameter is used, it is the index into the file to access the first desired point pair to use and the -n numpts parameter will identify the successive number of point pairs to extract from the file. Values are integers greater than zero. Ignored if argument -f file1 is present. The default=1.

-p pixinc ... PIXINC is the increment or separation in pixels for the spline interpolated points. Larger values will produce faster results, but too large a value may lead long straight sections. Values are integers greater than zero. The default=2.

-f file1 ... file1 is a simple text file containing comma separate pairs of random numbers in the range [0,1) with one pair per line. If provided, it then avoids internal computation of random numbers. The default is no text file.

-F file2 ... file2 is a simple text file containing the desired number or more comma separated pairs of random numbers in range [0,1) with one pair per line. If provided, then the -S seed parameter is used as and index into the file to locate the first point pair to use and -n numpts parameter will be used as the number of successive point pairs to extract. The Default is no point file. A file with 10,000 random point pairs computed from the number pi is available as pipoints.csv from: http://www.vips.ecs.soton.ac.uk/index.php?title=Random_Generation_of_Mildly_Irregular_Shapes_for_Cognitive_Experiments

Note: When using the Gaussian distribution, the results will be the same whether the shape of the inner region is square or disk, unless the points exceed the inner region and the constrain parameter is on.

Note: When using a circular mask, the results for a uniform distribution of points will be different from using shape=disk with no mask, because different algorithms are used for limiting the points to either disk region. A square mask will produce the same results as using shape=square for the uniform distribution of points.

This script is based upon the following paper:
N. Robidoux, P. Stelldinger and J. Cupitt, "Simple Random Generation
of Smooth Connected Irregular Shapes for Cognitive Studies",
C3S2E'11 Proceedings, May 16--18, 2011, Concordia University,
Montreal, Canada, 17-24, 2011.

Nicolas Robidoux Dept of Mathematics and Computer Science Laurentian University Sudbury, ON Canada nicolas.robidoux@gmail.com

References for the Kochaneck-Bartels Spline are:
http://en.wikipedia.org/wiki/Kochanek%E2%80%93Bartels_spline
http://www.shaneaherne.com/research/splines.html

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


Variation In Seed

Uniform Distribution On Square: Seed=1
Arguments:
-o 256 -i 200 -s square -k uniform
-n 12 -l 7 -b 16 -g 33 -S 1

Uniform Distribution On Square: Seed=1003
Arguments:
-o 256 -i 200 -s square -k uniform
-n 12 -l 7 -b 16 -g 33 -S 1003

Uniform Distribution On Disk: Seed=1
Arguments:
-o 256 -i 200 -s disk -k uniform
-n 12 -l 7 -b 16 -g 33 -S 1

Uniform Distribution On Disk: Seed=1003
Arguments:
-o 256 -i 200 -s disk -k uniform
-n 12 -l 7 -b 16 -g 33 -S 1003

Gaussian Distribution On Square: Seed=1
Arguments:
-o 256 -i 200 -s square -k gaussian
-n 12 -l 7 -b 16 -g 33 -S 1

Gaussian Distribution On Square: Seed=1003
Arguments:
-o 256 -i 200 -s square -k gaussian
-n 12 -l 7 -b 16 -g 33 -S 1003

Gaussian Distribution On Disk: Seed=1
Arguments:
-o 256 -i 200 -s disk -k gaussian
-n 12 -l 7 -b 16 -g 33 -S 1

Gaussian Distribution On Disk: Seed=1003
Arguments:
-o 256 -i 200 -s disk -k gaussian
-n 12 -l 7 -b 16 -g 33 -S 1003



Variation In Number Of Points

Uniform Distribution On Square: 12 Points
Arguments:
-o 256 -i 200 -s square -k uniform
-n 12 -l 7 -b 16 -g 33 -S 1

Uniform Distribution On Square: 16 Points
Arguments:
-o 256 -i 200 -s square -k uniform
-n 16 -l 7 -b 16 -g 33 -S 1

Uniform Distribution On Disk: 12 Points
Arguments:
-o 256 -i 200 -s disk -k uniform
-n 12 -l 7 -b 16 -g 33 -S 1

Uniform Distribution On Disk: 16 Points
Arguments:
-o 256 -i 200 -s disk -k uniform
-n 16 -l 7 -b 16 -g 33 -S 1

Gaussian Distribution On Square: 12 Point
Arguments:
-o 256 -i 200 -s square -k gaussian
-n 12 -l 7 -b 16 -g 33 -S 1

Gaussian Distribution On Square: 16 Points
Arguments:
-o 256 -i 200 -s square -k gaussian
-n 16 -l 7 -b 16 -g 33 -S 1

Gaussian Distribution On Disk: 12 Points
Arguments:
-o 256 -i 200 -s disk -k gaussian
-n 12 -l 7 -b 16 -g 33 -S 1

Gaussian Distribution On Disk: 16 Points
Arguments:
-o 256 -i 200 -s disk -k gaussian
-n 16 -l 7 -b 16 -g 33 -S 1



What the script does is as follows:

  • Draws a set of uniform or gaussian distributed random points
    on a white background within either a square or circular disk area
  • Successively connects the points with either thick black straight lines
    or thick black spline curve segments
  • Gaussian blurs the (lines in the) image
  • Thresholds the resulting image to a black blob shape on a white background