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.

TEXTURIZE


Creates a texture pattern and optionally applies it to the background of an input image.

Download Script

last modified: December 16, 2018



USAGE: texturize [-d dimensions] [-n newseed] [-t threshold] [-b blur]
[-w widen] [-s spread] [-g gnoise] [-f format] [-m mix] [-c contrast]
[infile] outfile

USAGE: texturize [-help or -h]

-d ... dimensions ... dimensions of texture image to create if no input
..................... image is provided; WIDTHxHEIGHT; default=128x128
-n ... newseed ...... seed value to use for random noise generator;
..................... integer>0; default=1
-t ... threshold .... white-threshold percent applied to random noise;
..................... 0<=float<=100; default=2
-b ... blur ......... sigma of 1D Gaussian blur used to create cross-hatch
..................... pattern from the random noise; float>=0; default=9
-w ... widen ........ sigma of 2D blur to apply to noise as a widening
..................... effect; float>=0; default=0 (no widenning)
-s ... spread ....... amount of spread to apply; float>=0; default=0
-g ... gnoise ....... amplitude of additive Gaussian noise added to final
..................... effect; float>=0; default=5
-f ... format ....... format of texture patten; choices are: plain or bump;
..................... default=bump
-m ... mix .......... mix percent of texture with the infile; 0<=float<=100;
..................... default=25; ignored if no infile
-c ... contrast ..... percent contrast increase of image prior to mixing;
..................... float>=0; ignored if no infile

If infile is provided, then -d dimensions will be ignored.

PURPOSE: To create a texture pattern and optionally apply it to the background of an input image

DESCRIPTION: TEXTURIZE creates a noise or cross-hatch texture pattern that can be saved or applied to the background of an image. The cross-hatch pattern is generated from 1D vertical and horizontal blurring of thresholded random noise. The pattern may be widened some or spread to make it more noisy.

ARGUMENTS:

-d dimensions ... DIMENSIONS of texture image to create if no input image is provided. Dimensions are specified as integers WIDTHxHEIGHT. The default=128x128.

-n newseed ... NEWSEED is the seed value to use for the random noise generator. Values are integers>0. The default=1.

-t threshold ... THRESHOLD is the white-threshold percent to apply to the random noise. Values are in the range from 0 to 100. The default=2.

-b blur ... BLUR is the sigma of 1D Gaussian blur used to create the cross-hatch pattern from the random noise. It is applied both vertically and horizontally. Values are floats>=0. The default=9.

-w widen ... WIDEN is the sigma of 2D Gaussian blur used to create a widening effect on the pattern. Values are floats>=0; The default=0.

-s spread ... SPREAD is the amount of the spread effect to apply to the pattern. More spread will dissolve the cross-hatch and create more of a random noise pattern. Values are floats>=0. The default=0.

-g gnoise ... GNOISE is the amplitude of additive Gaussian noise added to the final effect. Values are floats>=0. The default=5.

-f format ... FORMAT is the format of the texture patten. Choices are: plain (p) or bump (b). The default=bump.

-m mix ... MIX is mixing percentage of the texture with the infile. Values are in the range from 0 to 100. The default=25. Mix is ignored, if an infile is not provided.

-c contrast ... CONTRAST is the percent contrast increase of the image prior to mixing. Values are floats>=0. The default=0. Contrast is ignored, if an infile is not provided.

REQUIREMENTS: 1D morphology convolution kernels which probably were introduced at about IM 6.6.2.0

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


Original

Arguments:
-t 0.5 -b 9 -g 5 -f plain

Arguments:
-t 1 -b 9 -g 5 -f plain

Arguments:
-t 2 -b 9 -g 5 -f plain

Arguments:
-t 0.5 -b 9 -g 5 -f bump

Arguments:
-t 1 -b 9 -g 5 -f bump

Arguments:
-t 2 -b 9 -g 5 -f bump

Arguments:
-t 0.5 -b 5 -g 5 -f bump

Arguments:
-t 0.5 -b 9 -g 5 -f bump

Arguments:
-t 0.5 -b 15 -g 5 -f bump

Arguments:
-t 1 -b 5 -g 5 -f bump

Arguments:
-t 1 -b 9 -g 5 -f bump

Arguments:
-t 1 -b 15 -g 5 -f bump

Arguments:
-t 2 -b 5 -g 5 -f bump

Arguments:
-t 2 -b 9 -g 5 -f bump

Arguments:
-t 2 -b 15 -g 5 -f bump

Arguments:
-t 2 -b 5 -g 5 -f bump -w 1

Arguments:
-t 2 -b 9 -g 5 -f bump -w 1

Arguments:
-t 2 -b 15 -g 5 -f bump -w 1

Arguments:
-t 2 -b 5 -g 5 -f bump -w 2

Arguments:
-t 2 -b 9 -g 5 -f bump -w 2

Arguments:
-t 2 -b 15 -g 5 -f bump -w 2

Arguments:
-t 2 -b 9 -g 5 -f bump -s 1

Arguments:
-t 2 -b 9 -g 5 -f bump -s 2

Arguments:
-t 2 -b 9 -g 5 -f bump -s 3



Original

Arguments:
-t 0.5 -b 9 -g 5 -f bump -m 25

Arguments:
-t 1 -b 9 -g 5 -f bump -m 25

Arguments:
-t 1 -b 9 -g 5 -f bump -m 25

Arguments:
-t 2 -b 9 -g 5 -f bump -m 25 -s 1

Arguments:
-t 2 -b 9 -g 5 -f bump -m 25 -s 2

Arguments:
-t 2 -b 9 -g 5 -f bump -m 25 -s 3

Arguments:
-t 2 -b 9 -g 5 -f bump -m 25 -c 0

Arguments:
-t 2 -b 9 -g 5 -f bump -m 25 -c 10

Arguments:
-t 2 -b 9 -g 5 -f bump -m 25 -c 20



What the script does is as follows:

  • Creates a gray random noise pattern image
  • Applies a white threshold to it
  • Applies a 2D Gaussian blur to the previous result
  • Independently applies a vertical and horizontal Gaussian blur
    to the previous result
  • Multiplies the two 1D Gaussian blur results together
  • Stretches the product result to full dynamic range
  • Adds 2D Gaussian noise to the previous result
  • Optionally applies some spread to the previous result
  • Applies shading to the previous result to create a bump effect
  • Optionally increases the image contrast to make up for the
    decrease due to the mixing of a color image with the
    grayscale noise image.
  • Blends the previous result with any input image provided

This is equivalent to the following IM commands

  • ww=`identify -ping -format "%w" $infile`
  • hh=`identify -ping -format "%h" $infile`
  • convert -size ${ww}x${hh} xc:gray -seed 1000 +noise random \
    -channel g -separate +channel \
    -white-threshold $thresh% \
    -blur 0x$widen \
    \( -clone 0 -virtual-pixel mirror -morphology Convolve Blur:0x${blur} \) \
    \( -clone 0 -virtual-pixel mirror -morphology Convolve Blur:0x${blur},90 \) \
    -delete 0 -compose multiply -composite -auto-level \
    -evaluate GaussianNoise $gnoise \
    -channel g -separate +channel \
    -spread $spread \
    -shade 135x45 \
    $tmpA2
  • convert $infile \( $tmpA2 -brightness-contrast 0,$contrast \) \ -compose blend -define compose:args=$mix% -composite \
    $outfile