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.

SHAPEMORPH


Creates a shape morphing animation sequence between two images.

Download Script

last modified: December 15, 2018



USAGE: shapemorph [-f frames] [-d delay] [-p pause] [-r] [-m] "x1,y1 x2,y2" infile1 infile2 outfile
USAGE: shapemorph [-h or -help]

-f .... frames number of frames in animation; frames>1; default=20
-d .... delay delay between frames; delay>0; default=10
-p .... pause pause delay for two undistorted input images;
...................... pause>0; default=100
-r ................... reverse the animation sequence and append it to the end
-m ................... enable progress monitoring of the generation of each frame
"x1,y1 x2,y2" ........ control point location in infile1 and infile2, respectively;
...................... MUST be specified just prior to infile1 and outfile1 and
...................... enclosed in quotes

PURPOSE: To create a shape morphing animation sequence between two images.

DESCRIPTION: SHAPEMORPH creates a shape morphing animation sequence between two images using one corresponding control point specified from each of the input images. The control point along with the fixed corners actually form 5 control points that are used to fill out X and Y displacement maps (images) that are then used to transform the geometry of each image to the other. The corresponding frames from the transformation of each image are then blended proportional to the progression of frames.

ARGUMENTS:

-f frames ... FRAMES is the total number of frames in the animation (including infile1 and infile2 as the start and end frames. Values are integers > 1. The default is 20.

-d delay ... DELAY between frames. Values are integers>0. The default=10

-p pause ... PAUSE is the delay to use for the first and last frame of the animation, i.e. the delay for each of the input images. The default=100

-r ... If supplied, then reverse the animation sequence, remove the first and last frames of the reversed sequence and append these reversed frames to the end of the animation.

-m ... If supplied, then enable monitoring of -fx as it creates each frame.

"x1,y1 x2,y2" ... The corresponding control point locations in infile1 and infile2 respectively. Only one control point in each image may be used. These coordinates MUST be provided after all the optional arguments and just prior to the declaration of infile1 infile2.

NOTE: Thanks to Anthony Thyssen's improvements, the script has a 10x speed increase for IM version prior to 6.4.3-4 and is now even faster for IM version after 6.4.3-4 due to the use of the new -distort shepards.

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


Morphing Image 1 To Image 2

Image 1

Image 2

Arguments:
"73,56 57,68"
(control points at the
noses on the faces)



Morphing Image 1 To Image 2 And Back Again To Image 1

Image 1

Image 2

Arguments:
-r "73,56 57,68"
(control points at the
noses on the faces)



What the script does is as follows:

  • Creates an X and a Y Displacement Map (Image) for transforming
    each image to the other using Shepard's method of inverse
    weighted averaging of the control points to fill out the maps
  • Use the displacement maps with -fx to transform each of the
    two input images progressively according to the frame in the sequence
  • Blend each pair of transformed images to form a frame of the output animation


  • Use -fx to do an inverse weighted average interpolation of the
    control points to fill out the displacement maps
  • Loop over the desired number of frames
  • For each iteration:
  • Use -fx and the displacement maps to warp each of the two images
    a fractional amount of the displacement proportional to the frame
    number in the animation sequence
  • Use composite -blend to blend the two images together an amount
    proportional to the frame in the sequence.