Facemorph
Class ASM

java.lang.Object
  extended by Facemorph.ASM

public class ASM
extends java.lang.Object

AN Active Shape Model (ASM) contains the average shape, image and shape eigenvalues


Field Summary
static int NO_NORMALISATION
          Indicates no normalisation
static int RIGID_BODY_NORMALISATION
          indicates that this ASM uses rigid body + scale (procrustes) normalisation
static int THREE_POINT_NORMALISATION
          Indicates normalisation based on 3 points (affine)
static int TWO_POINT_NORMALISATION
          Indicates normalisation based on 2 points
 
Constructor Summary
ASM()
          Creates a new instance of ASM
ASM(Template template, PCA pca, java.awt.Image image, int normalisation, int[] pindex)
          Creates a new instance of an ASM using the data specified
 
Method Summary
 Template delineate(java.awt.Image subjectImage, java.awt.geom.Point2D.Float... points)
          Delineate an image using this ASM
 java.awt.Image getImage()
          Gets the average Image
 int getNormalisation()
          Gets the current normalisation constant
 int[] getNormalisationPoints()
          Returns the array of normalisation point indices
 PCA getPCA()
          Return the PCA data currently being used
 ASM getReduced(int comps)
          Gets a version of this ASM scaled down by 50% in size
 Template getTemplate()
          Gets the average Template
static void main(java.lang.String[] args)
          Main method for testing
 void read(java.lang.String file, double maxVar)
          Reads an ASM from file
 void readResources(java.lang.String folder, java.lang.String file, double maxVar)
          Reads an ASM from file
 Template reconstruct(float[] params)
          Reconstructs a Template from a set of shape parameters
 void replaceMean(Template temp, boolean project)
          Replaces the mean with the Template specified
 void setPoints(int[] pindex)
           
 void setTemplate(Template template)
          Changes the average shape to the provided template.
 void write(java.lang.String file)
          Writes this ASM to file
 void write(java.lang.String file, boolean text)
          Writes this ASM to file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TWO_POINT_NORMALISATION

public static final int TWO_POINT_NORMALISATION
Indicates normalisation based on 2 points

See Also:
Constant Field Values

THREE_POINT_NORMALISATION

public static final int THREE_POINT_NORMALISATION
Indicates normalisation based on 3 points (affine)

See Also:
Constant Field Values

RIGID_BODY_NORMALISATION

public static final int RIGID_BODY_NORMALISATION
indicates that this ASM uses rigid body + scale (procrustes) normalisation

See Also:
Constant Field Values

NO_NORMALISATION

public static final int NO_NORMALISATION
Indicates no normalisation

See Also:
Constant Field Values
Constructor Detail

ASM

public ASM()
Creates a new instance of ASM


ASM

public ASM(Template template,
           PCA pca,
           java.awt.Image image,
           int normalisation,
           int[] pindex)
Creates a new instance of an ASM using the data specified

Parameters:
template - The average Template
pca - The PCA data representing the principal shape eigen values
image - The average image
normalisation - Should be one of TWO_POINT_NORMALISATION, THREE_POINT_NORMALISATION or RIGID_BODY_NORMALISATION
pindex - An array of the point indeces to use, 2 for two point, 3 for 3 point and none required for rigid body normalisation
Method Detail

getPCA

public PCA getPCA()
Return the PCA data currently being used

Returns:
Returns the PCA data

getTemplate

public Template getTemplate()
Gets the average Template

Returns:
Returns the average template

setTemplate

public void setTemplate(Template template)
Changes the average shape to the provided template. It is up to the user of this function to ensure that the template is compatable, i..e. a one-to-one correpondence between template points.

Parameters:
template -

getNormalisation

public int getNormalisation()
Gets the current normalisation constant

Returns:
one of TWO_POINT_NORMALISATION, THREE_POINT_NORMALISATION, RIGID_BODY_NORMALISATION or NO_NORMALISATION

getNormalisationPoints

public int[] getNormalisationPoints()
Returns the array of normalisation point indices

Returns:
the array of normalisation point indices (either 2, 3 or empty, depending on the normalisation)

getImage

public java.awt.Image getImage()
Gets the average Image

Returns:
Returns the average image

getReduced

public ASM getReduced(int comps)
Gets a version of this ASM scaled down by 50% in size

Parameters:
comps - The number of components to use in the output model
Returns:
Returns a new ASM whose average is 0.5*0.5 the size of this, with at most the number of components specified

write

public void write(java.lang.String file)
           throws java.io.IOException
Writes this ASM to file

Parameters:
file - The name of the file to write to
Throws:
java.io.IOException - IOException is thrown e.g. if the file is not found

write

public void write(java.lang.String file,
                  boolean text)
           throws java.io.IOException
Writes this ASM to file

Parameters:
file - The name of the file to write to
text - indicates that the PCA data should be written in a text (not binary) format
Throws:
java.io.IOException - IOException is thrown e.g. if the file is not found

read

public void read(java.lang.String file,
                 double maxVar)
          throws java.io.FileNotFoundException,
                 java.io.IOException
Reads an ASM from file

Parameters:
file - The name of the file to read, this should just be the text based part that contains the names of the image, template and asm, and the type of normalisation and points to use.
maxVar - The maximum amount of variance to explain in this model
Throws:
java.io.FileNotFoundException - Thrown if the file is not found
java.io.IOException - thrown if some other IOException occurs

readResources

public void readResources(java.lang.String folder,
                          java.lang.String file,
                          double maxVar)
                   throws java.io.FileNotFoundException,
                          java.io.IOException
Reads an ASM from file

Parameters:
folder - The name of the folder (the path) containing the model
file - The name of the file to read, this should just be the text based part that contains the names of the image, template and asm, and the type of normalisation and points to use.
maxVar - The maximum amount of variance to explain in this model
Throws:
java.io.FileNotFoundException - Thrown if the file is not found
java.io.IOException - thrown if some other IOException occurs

replaceMean

public void replaceMean(Template temp,
                        boolean project)
Replaces the mean with the Template specified

Parameters:
temp - The new Template to use as the mean
project - Indicates that the template should be projected into the current PCA space

setPoints

public void setPoints(int[] pindex)

delineate

public Template delineate(java.awt.Image subjectImage,
                          java.awt.geom.Point2D.Float... points)
Delineate an image using this ASM

Parameters:
subjectImage - The image to auto delineate
points - The target position of the normalisation points
Returns:
The estimate of the delineation for the image

reconstruct

public Template reconstruct(float[] params)
Reconstructs a Template from a set of shape parameters

Parameters:
params - the parameters
Returns:
returns the reconstructed Template

main

public static void main(java.lang.String[] args)
                 throws java.io.FileNotFoundException,
                        java.io.IOException
Main method for testing

Parameters:
args - args[0] = name of ASM file to read, args[1] = name of small file to write
Throws:
java.io.FileNotFoundException
java.io.IOException