Facemorph.aam
Class AAM

java.lang.Object
  extended by Facemorph.aam.AAM

public class AAM
extends java.lang.Object

Active Appearance Model Implementation


Field Summary
static int APPEARANCE
          Specifies the algorithm with the pre-calculated derivatives and Hessian, but in which the appearance is updated each iteration
static int CAAM
          Specifies to use the correlated active appearance model (NCC) algorithm
static int CAAMSHAPE
          NCC fiting with pre-calculated derivatives and Hessian
static int SIMULTANEOUS
          Specifies to use a variation on the simultaneuous (derivative and Hessian regularly updated) algorithm
static int SPAN
          Specifies the algorithm with precaculated derivatives and Hessian and the appearance variation projected out.
 
Constructor Summary
AAM(Mask mask, ASM asm, PCI pci, int type, int warpType)
          Creates a new instance of AAM
 
Method Summary
 float[] analyseAppearance(FloatImage[] data)
          reconstructs an image given the component weightings, using avrg instead of the built in average
 void buildAAMappearance(int warpType)
          Builds an AAM for the appearance algorithm
 void buildAAMspan(int warpType)
          Builds an AAM for the projected out appearance algorithm
 void buildCAAM(int warpType)
          Builds a Correlated Active Appearance Model
 double[] convertFloatImage(FloatImage[] img)
          Converts a FloatImage to a double array
 Template fitAAM(java.awt.Image subject, Template template, float scale, int maxIts, int maxLoops, int start)
          Attempt at fitting an AAM to an image using the currently selected method
 Template fitAAMappearance(java.awt.Image subject, Template template, float scale, int maxIts, int start)
          Attempt at fitting an AAM to an image using the APPEARANCE method
 Template fitAAMSimultaneous(java.awt.Image subject, Template template, float scale, int maxIts, int maxLoops, int start)
          Attempt at fitting an AAM to an image using the SIMULTANEOUS method
 Template fitAAMspan(java.awt.Image subject, Template template, float scale, int maxIts, int start)
          Attempt at fitting an AAM to an image using the SPAN method
 Template fitCAAM(java.awt.Image subject, Template template, float scale, int maxIts, int maxLoops, int start)
          Attempt at fitting an AAM to an image using the CAAM method
 Template fitCAAMshape(java.awt.Image subject, Template template, float scale, int maxIts, int start)
          Attempt at fitting an AAM to an image using the CAAMSHAPE method
static void main(java.lang.String[] args)
          Main method for testing
 void projectOut(FloatImage[] diffImg, PCI pci, FloatImage mask)
          Projects the appearance variation out the derivative image
 void readAAM(java.lang.String file)
          Reads an AAM as created in psychomorph
 FloatImage[] reconstructAppearance(float[] params)
          reconstructs an image given the component weightings, using avrg instead of the built in average
 void test(java.lang.String imageList, java.lang.String resultsFile, java.lang.String outDir)
          Run a set of tests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APPEARANCE

public static final int APPEARANCE
Specifies the algorithm with the pre-calculated derivatives and Hessian, but in which the appearance is updated each iteration

See Also:
Constant Field Values

SPAN

public static final int SPAN
Specifies the algorithm with precaculated derivatives and Hessian and the appearance variation projected out.

See Also:
Constant Field Values

CAAM

public static final int CAAM
Specifies to use the correlated active appearance model (NCC) algorithm

See Also:
Constant Field Values

SIMULTANEOUS

public static final int SIMULTANEOUS
Specifies to use a variation on the simultaneuous (derivative and Hessian regularly updated) algorithm

See Also:
Constant Field Values

CAAMSHAPE

public static final int CAAMSHAPE
NCC fiting with pre-calculated derivatives and Hessian

See Also:
Constant Field Values
Constructor Detail

AAM

public AAM(Mask mask,
           ASM asm,
           PCI pci,
           int type,
           int warpType)
Creates a new instance of AAM

Parameters:
mask - Mask file to restrict changes to one part of the face
asm - Active shape model data (Template, Principal Component Analysis (PCA) and Image) shape data
pci - PCA image data
type - Indicates the algorithm to use
warpType - the type of warp to use
See Also:
Warp.createWarp(int, int, int, int, int, boolean)
Method Detail

buildAAMappearance

public void buildAAMappearance(int warpType)
Builds an AAM for the appearance algorithm

Parameters:
warpType - the type of warp to use
See Also:
Warp.createWarp(int, int, int, int, int, boolean)

buildAAMspan

public void buildAAMspan(int warpType)
Builds an AAM for the projected out appearance algorithm

Parameters:
warpType - the type of warp to use
See Also:
Warp.createWarp(int, int, int, int, int, boolean)

projectOut

public void projectOut(FloatImage[] diffImg,
                       PCI pci,
                       FloatImage mask)
Projects the appearance variation out the derivative image

Parameters:
diffImg - The derivative to remove appearance variation from
pci - The PCA image data
mask - The mask to apply

readAAM

public void readAAM(java.lang.String file)
Reads an AAM as created in psychomorph

Parameters:
file - Name of file to load

fitAAM

public Template fitAAM(java.awt.Image subject,
                       Template template,
                       float scale,
                       int maxIts,
                       int maxLoops,
                       int start)
                throws java.lang.RuntimeException
Attempt at fitting an AAM to an image using the currently selected method

Parameters:
template - Initial point configuration
maxIts - maximum number of iterations to perform
maxLoops - maximum number of recalculations of the derivatives and Hessian (if supported by the algorithm)
start - Start value of counter for debugging
subject - The image to fit too
scale - the scale todo this search at (should be 1!)
Returns:
Returns the fitted template
Throws:
java.lang.RuntimeException - Exception thrown if the AAM is not correctly initialised

fitAAMappearance

public Template fitAAMappearance(java.awt.Image subject,
                                 Template template,
                                 float scale,
                                 int maxIts,
                                 int start)
                          throws java.lang.RuntimeException
Attempt at fitting an AAM to an image using the APPEARANCE method

Parameters:
template - Initial point configuration
maxIts - maximum number of iterations to perform
start - Start value of counter for debugging
subject - The image to fit too
scale - the scale todo this search at (should be 1!)
Returns:
Returns the fitted template
Throws:
java.lang.RuntimeException - Exception thrown if the AAM is not correctly initialised

fitAAMspan

public Template fitAAMspan(java.awt.Image subject,
                           Template template,
                           float scale,
                           int maxIts,
                           int start)
                    throws java.lang.RuntimeException
Attempt at fitting an AAM to an image using the SPAN method

Parameters:
template - Initial point configuration
maxIts - maximum number of iterations to perform
start - Start value of counter for debugging
subject - The image to fit too
scale - the scale todo this search at (should be 1!)
Returns:
Returns the fitted template
Throws:
java.lang.RuntimeException - Exception thrown if the AAM is not correctly initialised

reconstructAppearance

public FloatImage[] reconstructAppearance(float[] params)
reconstructs an image given the component weightings, using avrg instead of the built in average

Parameters:
params - the component weightings
Returns:
the reconstructed image as an array of FloatImages in the order R,G,B

analyseAppearance

public float[] analyseAppearance(FloatImage[] data)
reconstructs an image given the component weightings, using avrg instead of the built in average

Parameters:
data - The image to analyse
Returns:
the reconstructed image as an array of FloatImages in the order R,G,B

buildCAAM

public void buildCAAM(int warpType)
Builds a Correlated Active Appearance Model

Parameters:
warpType - the type of warp to use
See Also:
Warp.createWarp(int, int, int, int, int, boolean)

fitCAAM

public Template fitCAAM(java.awt.Image subject,
                        Template template,
                        float scale,
                        int maxIts,
                        int maxLoops,
                        int start)
                 throws java.lang.RuntimeException
Attempt at fitting an AAM to an image using the CAAM method

Parameters:
template - Initial point configuration
maxIts - maximum number of iterations to perform
maxLoops - maximum number of recalculations of the derivatives and Hessian (if supported by the algorithm)
start - Start value of counter for debugging
subject - The image to fit too
scale - the scale todo this search at (should be 1!)
Returns:
Returns the fitted template
Throws:
java.lang.RuntimeException - Exception thrown if the AAM is not correctly initialised

fitCAAMshape

public Template fitCAAMshape(java.awt.Image subject,
                             Template template,
                             float scale,
                             int maxIts,
                             int start)
                      throws java.lang.RuntimeException
Attempt at fitting an AAM to an image using the CAAMSHAPE method

Parameters:
template - Initial point configuration
maxIts - maximum number of iterations to perform
start - Start value of counter for debugging
subject - The image to fit too
scale - the scale todo this search at (should be 1!)
Returns:
Returns the fitted template
Throws:
java.lang.RuntimeException - Exception thrown if the AAM is not correctly initialised

fitAAMSimultaneous

public Template fitAAMSimultaneous(java.awt.Image subject,
                                   Template template,
                                   float scale,
                                   int maxIts,
                                   int maxLoops,
                                   int start)
                            throws java.lang.RuntimeException
Attempt at fitting an AAM to an image using the SIMULTANEOUS method

Parameters:
template - Initial point configuration
maxIts - maximum number of iterations to perform
maxLoops - maximum number of recalculations of the derivatives and Hessian (if supported by the algorithm)
start - Start value of counter for debugging
subject - The image to fit too
scale - the scale todo this search at (should be 1!)
Returns:
Returns the fitted template
Throws:
java.lang.RuntimeException - Exception thrown if the AAM is not correctly initialised

convertFloatImage

public double[] convertFloatImage(FloatImage[] img)
Converts a FloatImage to a double array

Parameters:
img - The image to convert
Returns:
Returns the vectorised image

main

public static void main(java.lang.String[] args)
Main method for testing

Parameters:
args - The parameters

test

public void test(java.lang.String imageList,
                 java.lang.String resultsFile,
                 java.lang.String outDir)
Run a set of tests. A list of images are loaded along with the templates. The eye points from the loaded templates are used to initialise the rotation, scaling and shifting Each template is then fitted to the image and written to file The error of each point is calculated and written to a histogram file in csv format.

Parameters:
imageList - The text file listing the images and templates to test on
resultsFile - The name of a CSV file to write the error histogram to
outDir - The name of the directory to write the adapted templates to.