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

OUTFIT


Transforms a pattern image to place it over an image of some piece of clothing or outfit

Download Script

last modified: January 05, 2018



USAGE: outfit [-e extract] [-f fuzzval] [-b bgcolor] [-p position] [-a antialias] [-n] [-c reduce] [-m modulate] [-x xroll] [-y yroll] [-o orientation] [-l lightval] [-c contrast] [-d displace] [-s smooth] [-E] [-D directory] infile bgfile [maskfile] outfile

USAGE: outfit [-help|-h]

-e ... extract ....... method of providing a mask of object vs background; choices
...................... are: floodfill, refill or alpha; default=floodfill; the mask
...................... will become black at the background color and white elsewhere
-f ... fuzzval ....... fuzz value for the extract method of floodfill or refill;
...................... float>=0; default=5
-b ... bgcolor ........ background color to use for extracting the mask when using
...................... extract=refill; any valid IM opaque color is allowed;
...................... default=white
-p ... position ...... positional coordinates to extract the background color when
...................... creating the mask using extract=floodfill; values are one
...................... integer x,y pair or a compass direction for one corner, side
...................... or middle of the image; default="0,0" (northwest corner of
...................... the image)
-a ... antialias ..... mask boundary antialias blur amount; float>=0; default=1
-n ................... negate (invert) the mask image
-r ... reduce ........ reduction amount as percent for the infile (pattern image)
...................... before tiling it; integer>=0; default=10
-m ... modulate ...... modulation (lightness, saturation, hue) for the infile
...................... (pattern image) before tiling it; comma separate triplet
...................... L,S,H; integers>=0; default="100,100,100" (no change)
-x ... xroll ........ roll amount in pixels for the tiled image in the horizontal
...................... dimension; integer; default=0
-y ... xroll ........ roll amount in pixels for the tiled image in the vertical
...................... dimension; integer; default=0
-o ... orientation ... orientation angle for rotation of the tiled image;
...................... -360<=integer<=360; default=0
-l ... lightval ...... average brightness in percent for the lighting image;
...................... integer>=0; default=40
-c ... contrast ...... shading contrast adjustment for the lighting image; integer>=0;
...................... default=5
-d ... displace ...... displacement amount when applying the displacement image;
...................... integer>=0; default=5
-s ... smooth ........ smoothing distance to apply to the perimeter between object
...................... and background of displacement image in order to reduce edge
...................... artifacts from too dark a region near the object perimenter;
...................... integer>=0; default=0
-E ................... export the lighting image, displacement map and other
...................... needed parameters to be able to use a condensed outfitwarp
...................... script to repeat the processing on the same size and style
...................... outfit image for faster subsequent processing.
-D ... directory ..... directory to write all the exported data, including a text file
...................... called outfit.txt containing the same textual parameter data
...................... sent to terminal. The directory can be specified in the
...................... outfitwarp script to import all the needed images and textual
...................... data.

infile is the pattern image to be applied to the background outfit (clothing) image

PURPOSE: Transforms a pattern image to place it over an image of some piece of clothing or outfit.

DESCRIPTION: OUTFIT transforms a pattern image to place it over an image of some piece of clothing or outfit. The transformed image will display hightlights from the outfit image and be distorted to match the wrinkles in the outfit image. The process requires a mask image, which can be provided externally or created internally using either a floodfill or refill process. The floodfill or refill process change the background area to black and the rest to white. Floodfill requires a seed coordinate, and fuzz value and replaces color locally. Refill requires a background color and fuzz value and replaces color globally. The mask image or alpha channel must be a binary image (black/white) with at most the edges antialiased. Special processing such as at http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=23348 will be needed, or alternately, use separate masks for each part that requires a different pattern orientation.

ARGUMENTS:

-e extract ... EXTRACT is the method of extracting or providing a mask of object vs background. The choices are: floodfill (f), refill (r) or alpha (a). Floodfill generates the mask locally with a seed coordinate, background color and fuzz value. Refill generates a mask globally with a background color and fuzz value. Alpha gets the mask from the alpha channel of the background image. The default=floodfill. The mask will become black at the background color and white elsewhere. If maskfile is provide, it overrides this option.

-f fuzzval ... FUZZVAL is the fuzz value for the extract method of floodfill or refill. Values are floats>=0. The default=5.

-b bgcolor ... BGCOLOR is the background color to use for extracting the mask when using extract=refill. Any valid IM opaque color is allowed. The default=white. Note, extracting the mask when the background is very dark and the object (outfit) is very dark will not work well. Good separation of color is needed between the background and the object (outfit/clothing)

-p position ... POSITION is the positional coordinated to use to extract the mask when using extract=floodfill. Values are either one integer x,y pair or a compass direction for a corner, side or middle of the background image. The default="0,0" (northwest corner of the background image).

-a antialias ... ANTIALIAS is the mask boundary antialias (blur sigma) amount. Values are floats>=0. The default=1.

-n ... NEGATE (invert) the mask image.

-r reduce ... REDUCE is the reduction amount as percent for the infile (pattern image) before tiling it. Values are integers>=0. The default=10.

-m modulate ... MODULATE is the modulation (lightness, saturation, hue) applied to the infile (pattern image) before tiling it. Values are a comma separate triplet L,S,H of integers>=0. The default="100,100,100" (no change).

-x xroll ... XROLL is the roll amount in pixels for the tiled image in the horizontal dimension. Values are integers. The default=0.

-x yroll ... YROLL is the roll amount in pixels for the tiled image in the vertical dimension. Values are integers. The default=0.

-o orientation ... ORIENTATION angle in degrees for rotation of the tiled pattern image. Values are -360<=integer<=360; default=0.

-l lightval ... LIGHTVAL is the average brightness in percent for the lighting image. Values are integers>=0. The default=40.

-c contrast ... CONTRAST is the shading contrast adjustment for the lighting image. Values are integers>=0. The default=5.

-d displace ... DISPLACE is the displacement amount when applying the displacement image to distort the pattern on the background image. Values are integers>=0. The default=5.

-s smooth ... SMOOTH is the smoothing distance to apply to the perimeter between object and background of the displacement image in order to reduce edge artifacts from too dark a region near the object perimenter. Values are integers>=0. The default=0.

-E ... EXPORT the lighting image, the displacement image and other needed parameters to be able to use a condensed outfitwarp script to repeat the processing on the same size and style outfit image for faster subsequent processing.

-D directory ... DIRECTORY to write all the exported data, including a text file called outfit.txt containing the same textual parameter data as sent to terminal. The directory can be specified later in the outfitwarp script to import all the needed images and textual data.

NOTE: The mask image or alpha channel must be a binary image (black/white) with at most the edges antialiased.

NOTE: This script will not bend textures to conform to curved or bent arms. Special processing such as at http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=23348 will be needed, or alternately, use separate masks for each part that requires a different pattern orientation.

REQUIREMENTS: IM 6.5.3.4 due to the use of -compose displace.

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 -- Men's Hoodie with Plaid Pattern

Input (Pattern) Image
(source)

Background (Hoodie) Image
(source)

Arguments:
-e floodfill -b white -f 0.2

Arguments:
-e floodfill -b white -f 0.2 -s 10

Arguments:
-e floodfill -b white -f 0.2 -s 10 -o 20

Arguments:
-e floodfill -b white -f 0.2 -s 10 -o 20 -m 100,100,0



What the script does is as follows:

  • Converts the outfit image to grayscale
  • Adjust the grayscale image so that the average is mid gray
  • Modifies the mid gray image by adjusting the contrast to create the lighting image
  • Saves the mid gray image to create the displacement image
  • Resizes and tiles the pattern image
  • Applies the lighting image to the tiled pattern image image
  • Applies the displacement image to the lighting adjusted pattern image
  • Composites the final pattern image onto the outfit image