Facemorph.aam
Class GLAAM

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

public class GLAAM
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
GLAAM(MaskInterface mask, ASM asm, PCI pci, int type)
          Creates a new instance of AAM
GLAAM(MaskInterface mask, ASM asm, PCI pci, int type, javax.media.opengl.GLAutoDrawable canv)
          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()
          Builds an AAM for the appearance algorithm
 void buildAAMspan()
          Builds an AAM for the projected out appearance algorithm
 void buildCAAM()
          Builds a Correlated Active Appearance Model
static float[] concatenateParameters(float[] newparams, Template template, Template avrg)
          Concatenate the parameters
 double[] convertFloatImage(FloatImage[] img)
          Converts a FloatImage to a double array
 void disposeWarp()
          Dispose of the warp
 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 setGLAutoDrawable(javax.media.opengl.GLAutoDrawable drawable)
          set the Opengl canvas
 void test(java.lang.String imageList, java.lang.String resultsFile, java.lang.String outDir)
          Run a set of tests.
static void writeImage(FloatImage[] img, float shift, float scale, java.lang.String outFileName)
          Writes the FloatImage to a file
 
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

GLAAM

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

Parameters:
mask - MaskInterface 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

GLAAM

public GLAAM(MaskInterface mask,
             ASM asm,
             PCI pci,
             int type,
             javax.media.opengl.GLAutoDrawable canv)
Creates a new instance of AAM

Parameters:
mask - MaskInterface 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
canv - the opengl canvas to use
Method Detail

disposeWarp

public void disposeWarp()
Dispose of the warp


setGLAutoDrawable

public void setGLAutoDrawable(javax.media.opengl.GLAutoDrawable drawable)
set the Opengl canvas

Parameters:
drawable - the new OpenGL canvas

buildAAMappearance

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


buildAAMspan

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


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

concatenateParameters

public static float[] concatenateParameters(float[] newparams,
                                            Template template,
                                            Template avrg)
Concatenate the parameters

Parameters:
newparams - the new parameters
template - the current template
avrg - the average template
Returns:
returns the concatenated parameters

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()
Builds a Correlated Active Appearance Model


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

writeImage

public static void writeImage(FloatImage[] img,
                              float shift,
                              float scale,
                              java.lang.String outFileName)
Writes the FloatImage to a file

Parameters:
img - the image to write (as an array of 3 FloatImage)
shift - the amount to add to each pixel (after scaling)
scale - the amount to scale weach pixel
outFileName - the output file name

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.