Facemorph
Class Template

java.lang.Object
  extended by Facemorph.Template
All Implemented Interfaces:
Vectorisable

public class Template
extends java.lang.Object
implements Vectorisable

A Template of points and lines passing through the points, used to outline the facial features


Nested Class Summary
protected  class Template.TemplateError
           
 
Field Summary
static java.awt.Color lineColour
           
static java.awt.Color lineMouseOverColour
           
static java.awt.Color lineSelectedColour
           
static java.awt.Color pointColour
           
static java.awt.Color pointMouseOverColour
           
static java.awt.Color pointSelectedColour
           
static java.awt.Color rectColour
           
static java.awt.Color threePointColour
           
 
Constructor Summary
Template()
          Create an empty Template
 
Method Summary
 int addChimeric(Template t, float l1, float l2, float w)
          Adds different amounts to the left and right side the points 0 and 1 are used to define the eyes, and hence the symmetry line
 void addContour(float x, float y, boolean closed)
          Creates a new point and a line that starts at this point
 void addContour(int i, boolean closed)
          Creates a new curve starting at the point specified
 void addContour(int x, int y, boolean closed)
          Creates a new point and a line that starts at this point
 boolean addContourPoint(float x, float y)
          Creates a new point and adds it to the end of the current contour (the most recently created)
 void addContourPoint(int i)
          Adds the point specified to the end of the current line
 boolean addContourPoint(int line, float x, float y)
          Creates a new point and adds it to the end of the current contour (the most recently created)
 boolean addContourPoint(int x, int y)
          Creates a new point and adds it to the end of the current contour (the most recently created)
 void addPoint(float x, float y)
          Adds a point to the Template
 void addPoint(int x, int y)
          Adds a point to the Template
 boolean addToAverage(Template t, int n)
          Adds the n'th template to this average
 void addWeighted(Template t, Complex z)
          this = this + z*t
 void addWeighted(Template t, float s)
          this = this + s*t
 void affineFit(java.awt.geom.Point2D.Float leftEye, java.awt.geom.Point2D.Float rightEye, java.awt.geom.Point2D.Float mouth, int leftIndex, int rightIndex, int mouthIndex)
          Performs an affine (linear) operation on this Template, specified by 3 points
 float[][] affineFit(Template tem, int[] normalisationPoints)
          Performs an affine fit of this to Template tem using the normalisation points specified
 int affineFit2(java.awt.geom.Point2D.Float leftEye, java.awt.geom.Point2D.Float rightEye, java.awt.geom.Point2D.Float mouth, int leftIndex, int rightIndex, int mouthIndex1, int mouthIndex2)
          Performs an affine fit of this template to the points given, using the midpoint of mouthIndex1 and mouthIndex2 to match to mouth point
static Template autoDelineate(java.awt.Image subjectImage, java.awt.Image averageImage, Template averageTemplate, java.awt.geom.Point2D.Float leftEye, java.awt.geom.Point2D.Float rightEye, java.awt.geom.Point2D.Float mouth, int leftIndex, int rightIndex, int mouthIndex, java.awt.image.ImageObserver ob, PCA pca)
          Automatically delineates the image given returning a Template outlining the facial features
 boolean autoSize(int width, int height)
          Resize the template to fit in an image of width by height with a small border
 int average(java.util.ArrayList<Template> t, boolean normalise)
          Constructs the average of the array of templates given
 int average(java.util.ArrayList<Template> t, int normalise, int[] normPoints)
          Constructs the average of the array of templates given
 int average(Template[] t)
          Constructs the average of the array of templates given
 int average(Template[] templates, boolean normalise)
          Calculates the average of the Templates
 int calculateAffineMatrix(java.awt.geom.Point2D.Float p1, java.awt.geom.Point2D.Float p2, java.awt.geom.Point2D.Float p3, java.awt.geom.Point2D.Float q1, java.awt.geom.Point2D.Float q2, java.awt.geom.Point2D.Float q3, float[][] mat)
          Calcualtes the best affine transform matrix (rotation, translation, scale and shear)
static float[][] calculateInverseNormalisationMatrix(double[][] R, double[] T, double scale)
          Calculats the inverse of the normalisation matrix
static float[][] calculateNormalisationMatrix(double[][] R, double[] T, double scale)
          Calculates a 3 by 2 rigid body matrix from the rotation, translation and scale specified
static float[][] calculateNormalisationMatrix(java.awt.geom.Point2D.Float p1, java.awt.geom.Point2D.Float p2, java.awt.geom.Point2D.Float q1, java.awt.geom.Point2D.Float q2)
          Calculates the rigid body matrix (rotation, translation and scale) given two matching point pairs
 double calculateRigidBodyFit(Template tmplt, double[][] R, double[] T)
          Calculates and performs a least-square error rigid-body transform on this Template
 Template clone()
           
static Template complexAverage(java.util.ArrayList<Template> origTemplates)
          Calculates the full procrustes average using complex maths
 void complexAverage(Template[] templates)
          Calculates the full procrustes average using complex maths
 Complex complexDotProduct(Template t)
          Complex dot product of this with t, treating (x,y) coords of each point as complex number x+iy
 FloatImage[] constructMultilinearFitter(int warpType, java.awt.Image averageImage, Template avrg, MaskInterface mask, Multilinear shapeMultilinear, Multilinear imageMultilinear, float scale)
          Constructs the data needed for fitting a multilinear AAM to an image using efficient reverse method, with linear projection model, includes colour information
 boolean convert(java.lang.String stringData)
          Parses this Template from the text string in some suitable format
 void copy(Template t)
          Copies the Template given into this
 boolean copySamples(Template t)
          Make each contour have the same number of samples as Template t
 void deleteLine(int lineNum)
          Delete a line
 void deletePoint(int PointNum)
          Deletes the specified point from the Template
 double dotProduct(Template t)
          Calcualtes the dot product of the templates given
 void draw(java.awt.Graphics g, int x_off, int y_off)
          Draws the Template as a series of points (+) and curved lines on the Graphics provided
 void drawZoomed(java.awt.Graphics g, int x_off, int y_off, float xs, float ys)
          Draw this Template to the Graphics provided as a series of curved lines and points (+), scaled by the amounts given
 void fitAAM(int warpType, java.awt.Image subject, java.awt.Image average, MaskInterface mask, PCA pca, PCI pci)
          Fits a Template to this FloatImage using a multiscale method
 void fitAAMappearance(int warpType, java.awt.Image subject, java.awt.Image averageImg, MaskInterface mask, PCA pca, PCI pci, float scale)
          Attempt at fitting an AAM to an image using efficient reverse method, includes colour information
 void fitAAMbayesian(int warpType, java.awt.Image subject, java.awt.Image averageImg, MaskInterface mask, PCA pca, PCI pci, float scale)
          Attempt at fitting an AAM to an image using efficient reverse method, includes colour information
 void fitAAMforward(java.awt.Image subjectImg, java.awt.Image averageImg, MaskInterface mask, PCA pca, PCI pci, float scale)
          Attempt at fitting an AAM to an image using inefficient, but more reliable forward method, includes colour information
 void fitAAMshape(int warpType, FloatImage average, FloatImage subject, Template avrg, MaskInterface mask, PCA pca, float scale)
          First attempt at fitting an AAM to an image, does not include colour information, not recommended to use!
 int fitAAMspan(int warpType, java.awt.Image subject, java.awt.Image averageImg, MaskInterface mask, PCA pca, PCI pci, FloatImage[] smallPCIcomps, float scale, int counter)
          Attempt at fitting an AAM to an image using efficient reverse method, colour information is projected out
 int fitAAMspanLM(int warpType, java.awt.Image subject, java.awt.Image averageImg, MaskInterface mask, PCA pca, PCI pci, float scale, int counter)
          Attempt at fitting an AAM to an image using efficient reverse method, includes colour information
 void fitMultilinear(java.awt.Image subject, java.awt.Image averageImage, Template avrg, MaskInterface mask, Multilinear shapeMultilinear, Multilinear imageMultilinear, FloatImage[] diffImg, float scale)
          Uses a multilinear fitting model to try a fit a template to the image
 void fitMultilinear(int warpType, java.awt.Image subject, java.awt.Image averageImage, Template avrg, MaskInterface mask, Multilinear shapeMultilinear, Multilinear imageMultilinear, float scale)
          Attempt at fitting an Multilinear AAM to an image using efficient reverse method, with linear projection model, includes colour information
 void fitPCA(FloatImage average, FloatImage subject, Template avrg, PCA pca)
          Fits a Template to this FloatImage
 void fitPCA(FloatImage average, FloatImage subject, Template avrg, PCA pca, int leftIndex, int rightIndex, int mouthIndex)
          Fits a Template to this FloatImage
 boolean fitPCA(java.awt.Image subjectImage, java.awt.Image averageImage, Template averageTemplate, java.awt.geom.Point2D.Float leftEye, java.awt.geom.Point2D.Float rightEye, int leftIndex, int rightIndex, java.awt.image.ImageObserver ob, PCA pca)
          Automatically delineates the image given using this Template to outline the facial features
 boolean fitPCA(java.awt.Image subjectImage, java.awt.Image averageImage, Template averageTemplate, java.awt.geom.Point2D.Float leftEye, java.awt.geom.Point2D.Float rightEye, java.awt.geom.Point2D.Float mouth, int leftIndex, int rightIndex, int mouthIndex, java.awt.image.ImageObserver ob, PCA pca)
          Automatically delineates the image given using this Template to outline the facial features
 boolean fitPCAColourSegment(java.awt.Image subjectImage, java.awt.Image averageImage, Template averageTemplate, java.awt.geom.Point2D.Float leftEye, java.awt.geom.Point2D.Float rightEye, java.awt.geom.Point2D.Float mouth, int leftIndex, int rightIndex, int mouthIndex, java.awt.image.ImageObserver ob, PCA pca, MaskInterface mask)
          Automatically delineates the image given using this Template to outline the facial features Tries to segment out the face from the background using colour to help
 boolean fitPCARigid(java.awt.Image subjectImage, java.awt.Image averageImage, Template averageTemplate, java.awt.geom.Point2D.Float leftEye, java.awt.geom.Point2D.Float rightEye, java.awt.geom.Point2D.Float mouth, int leftIndex, int rightIndex, int mouthIndex, java.awt.image.ImageObserver ob, PCA pca)
          Automatically delineates the image given using this Template to outline the facial features
 void fitTensor(int warpType, java.awt.Image subject, java.awt.Image averageImage, Template avrg, MaskInterface mask, Tensor shapeTensor, Tensor imageTensor, BigMat shapeLinearModel, BigMat shapeAverage, BigMat imageLinearModel, BigMat imageAverage, float scale)
          Attempt at fitting an Tensor AAM to an image using efficient reverse method, with linear projection model, includes colour information
 void fixDatMouth()
          Checks if the usual top mouth line is swapped with the bottom mouth line, and fixes it if true.
 int get_x(int i)
          Gets the x-coord of the ith face point
 int get_y(int i)
          Gets the y-coord of the ith face point
static float[][] getAffineMatrix(java.awt.geom.Point2D.Float[] source, java.awt.geom.Point2D.Float[] target)
          Get the affine transform matrix that map the 3 points specified in source onto 3 points target
 java.awt.Rectangle getBoundingBox()
          Gets a bounding rectangle for the Template
 java.awt.Rectangle getBoundingSquare()
          Gets a bounding square for the Template
 Contour getContour(int i)
          Get the ith contour in this template
 java.util.Vector<Contour> getContours()
          Get the list of contours through face points
 boolean getDrawLabels()
           
 java.awt.Color getLineColour(int i)
          Gets the colour of a line
 java.awt.Polygon getMask(Mask msk)
          Deprecated. This method will removed in the near future.
 java.awt.Polygon getMask(Mask msk, int xoff, int yoff, float zoom)
          Deprecated. This method will removed in the near future.
 FloatImage getMask(Mask mask, int w, int h, float min, float max)
          Deprecated. This method will removed in the near future.
 FloatImage getMask(java.util.Vector<java.lang.Integer> maskConts, java.util.Vector<java.lang.Integer> maskDirections, int w, int h, float min, float max)
          Deprecated. This method will removed in the near future.
 double[] getMultilinearandRBparameters(Multilinear shapeMultilinear)
          Analyses this Template using a Multilinear (project out) model
 float[] getPCAandNormParameters(PCA pca, Template average, int normalisation, int[] normPoints)
          Gets the pca and normalisation parameters in a single vector
 float[] getPCAandRBparameters(PCA pca, Template average)
          Analyses this Template using a set of principal components
 float[] getPCAparameters(PCA pca, Template average, int leftIndex, int rightIndex, int mouthIndex)
          Analyses this Template using a set of principal components
 java.awt.geom.Point2D.Float getPoint(int i)
          Gets the feature point requested
 java.awt.Color getPointColour(int i)
          Gets the colour of the point
 java.util.Vector<java.awt.geom.Point2D.Float> getPoints()
          Gets a list of all the points in this Template as a Vector
 java.util.Vector<java.awt.geom.Point2D.Float> getPoints(boolean contourPoints)
          Gets a Vector containing the points and samples along the lines
 java.util.ArrayList<java.awt.geom.Point2D.Float> getPointsInBox(float x, float y, float w, float h)
          Gets the points in an axis aligned rectangle
 double[] getTensorandRBparameters(BigMat shapeModel, BigMat shapeAverage, Template average, Tensor shapeTensor)
          Analyses this Template using a tensor model
 int hitLine(int x, int y, float zoom)
          Returns the index if there is a line near (x,y) (+/-5 pixels) or -1
 int hitPoint(int x, int y)
          Returns the index if there is a point near (x,y) (+/-5 pixels) -1
 int hitZoomedPoint(int x, int y, float zoom)
          Returns the index if there is a point near (x,y) (+/-5 pixels) -1
 boolean isLineSelected(int i)
           
 boolean isPointSelected(int i)
           
 java.awt.Image maskImage(java.awt.Image img, MaskInterface mask, java.awt.Color col, boolean reverse)
          Deprecated. This method will removed in the near future.
 void move(float x, float y)
          Shifts this by (x,y)
 void moveLine(int i, float dx, float dy)
          Moves the point to the specified position
 void movePoint(int i, int x, int y)
          Moves the point to the specified position
 int noContours()
           
 void normalise()
          Normalise the mean to zero and the magnitude to 1
 int normaliseEyes(java.awt.geom.Point2D.Float leftEye, java.awt.geom.Point2D.Float rightEye, int leftIndex, int rightIndex)
          Normalise the rotation, translation and scale so that two specified points are in a given place
 float[][] normaliseEyes(Template target)
          Performs 2 point normalisation using points 0 and 1
 float[][] normaliseEyes(Template target, int[] normPoints)
          Performs 2 point normalisation using the points indicated in the normPoints array
 boolean read(java.io.DataInputStream in)
          Read this Template from the DataInputStream provided
 boolean read(java.lang.String file)
          Reads this Template from the file given
 boolean read(java.lang.String file, int h)
          Reads this Template from the file given
 boolean readASF(java.io.DataInputStream in, int w, int h)
          Read this Template from the DataInputStream provided
 boolean readASF(java.lang.String file, int w, int h)
          Reads this Template from the file given
 boolean readDAT(java.io.DataInputStream in, int h)
          Read a DAT format template
 boolean readDAT(java.lang.String file, int h)
          Reads this Template from the file given
 boolean readPCA(java.io.DataInputStream in, Template average, PCA pca, int le, int re, int m)
          Reads in 3 normalisation points and some PCA parameters and reconstructs the Template (I think!)
 boolean readPTS(java.io.DataInputStream in)
          Read this Template from the DataInputStream provided
 boolean readPTS(java.lang.String file)
          Reads this Template from the file given
static int[] readSymFile(java.lang.String name)
          Read a symmetry (.sym) file
 void recalculateContours()
          Recalculates the curves through the control points after they have setLocationd.
 void reconstructMultilinearandRB(Multilinear shapeMultilinear, Template average, double[] PCAandRBparams, boolean edgeOnly)
          Builds a Template from a set of Multilinear and Rigid Body parameters and data
 void reconstructPCA(PCA pca, Template average, float[] pcaParams, int toskip)
          Reconstruct this Template from PCA data
 void reconstructPCA(PCA pca, Template average, java.awt.geom.Point2D.Float left, java.awt.geom.Point2D.Float right, java.awt.geom.Point2D.Float mouth, float[] pcaParams, int leftIndex, int rightIndex, int mouthIndex)
          Builds a Template from a set of PCA parameters and data
 void reconstructPCAandNorm(PCA pca, Template average, float[] PCAandRBparams, int normalisation, int[] normPoints)
          Reconstructs this Template from the PCA data using the parameters and normalisation specified
 void reconstructPCAandRB(PCA pca, Template average, float[] PCAandRBparams)
          Builds a Template from a set of PCA and Rigid Body parameters and data
 void reconstructTensorandRB(Tensor shapeTensor, Template average, double[] PCAandRBparams)
          Builds a Template from a set of Tensor and Rigid Body parameters and data
 void reflect(int[] plist, int width)
          Reflect the template using the symetry data given i.e.
 double rigidBodyFit(Template tmplt, double[][] R, double[] T)
          Calculates and performs a least-square error rigid-body transform on this Template
 Template scale(double s)
          Return a new Template as a copy of this one scaled by s
 void setDrawLabels(boolean drawLabels)
           
 void setLineColour(int i, java.awt.Color c)
          Set the colour of a line
 void setLineSelected(int i, boolean s)
           
 void setLocationPoint(int i, int x, int y)
          setLocations the point to the specified position
 void setPointColour(int i, java.awt.Color c)
          Set the colour of a point
 void setPointSelected(int i, boolean s)
           
 void setStandardColours()
          Sets the colours to the standard
 int size()
          Get the number of points in this Template
 Template subtract(Template rhs)
          Creates a new template by subtracting the positions of two input templates output = this - rhs
 void symmetrise(Template t, int[] plist, int w)
          Makes this template a symmetrical version of t
 java.lang.String toString()
          Convert this Template to a textual format for writing / display
 java.lang.String toURLString()
          Converts this Template to a String, replacing spaces with + etc
 void trackASM(FloatImage average, FloatImage subject, Template avrg, PCA pca, float scale, int its, int[] normalisePointIndex)
          Fits a PCA model to an image using edge normal profiles
 void transform(float[][] mat)
          Performs a matrix transform on this Template
 Template transform(Template sourceTemplate, Template destTemplate, double s, float scale)
          Transforms this Template using the formula this = this + s*(sourceTemplate - destTemplate)
 Template transform(Template sourceTemplate, Template destTemplate, double s, float scale, boolean conts)
          Transforms this Template using the formula this = this + s*(sourceTemplate - destTemplate)
 Template transform(Template sourceTemplate, Template destTemplate, double s, float scale, boolean conts, int normalisation, int[] normPoints)
          Transforms this Template using the formula this = this + s*(sourceTemplate - destTemplate)
 Template transformChimeric(Template sourceTemplate, Template destTemplate, float l1, float l2, float w)
          Transforms the left and right face sides separately
 void unvectorise(double[] vec)
          Turns an array representation back into a a template.
 double[] vectorise()
          Turns a template into a 1D array, used in tensor
 double[] vectorise(boolean contourPoints)
          Turns a template into a 1D array, used in tensor
 void warp(TPSWarp warp)
          Warp the template with the warp given
 void warp(Warp warp)
          Warp the template with the warp given
static Template weightedAverage(java.util.List<Template> templates, float[] weights, int iterations)
          Makes a weighted average of the templates given
static Template weightedAverage(Template t1, float w1, Template t2, float w2)
          Makes a weighted average of the templates given
 boolean write(java.io.PrintStream out)
          Writes this Template to file (via a PrintStream)
 boolean write(java.lang.String s)
          Writes to the file specified
 void zoom(float zoomx, float zoomy, float crop_x, float crop_y)
          Magnify and shift this Template
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pointColour

public static java.awt.Color pointColour

pointMouseOverColour

public static java.awt.Color pointMouseOverColour

pointSelectedColour

public static java.awt.Color pointSelectedColour

lineColour

public static java.awt.Color lineColour

lineMouseOverColour

public static java.awt.Color lineMouseOverColour

lineSelectedColour

public static java.awt.Color lineSelectedColour

rectColour

public static java.awt.Color rectColour

threePointColour

public static java.awt.Color threePointColour
Constructor Detail

Template

public Template()
Create an empty Template

Method Detail

size

public int size()
Get the number of points in this Template

Returns:
The number of points in this template

getContours

public java.util.Vector<Contour> getContours()
Get the list of contours through face points

Returns:
the list of contours through face points

copySamples

public boolean copySamples(Template t)
Make each contour have the same number of samples as Template t

Parameters:
t - The template to copy the number of samples from
Returns:
true if the samples were copied successfully, false otherwise (e.g. different numbers of contours etc)

getPoints

public java.util.Vector<java.awt.geom.Point2D.Float> getPoints()
Gets a list of all the points in this Template as a Vector

Returns:
A Vector containing all the points in this Template

getPoints

public java.util.Vector<java.awt.geom.Point2D.Float> getPoints(boolean contourPoints)
Gets a Vector containing the points and samples along the lines

Parameters:
contourPoints - Flag to indicate if the points along the lines should also be returned
Returns:
The points, with or without the contour samples.

vectorise

public double[] vectorise()
Turns a template into a 1D array, used in tensor

Specified by:
vectorise in interface Vectorisable
Returns:
returns the vectorised template

vectorise

public double[] vectorise(boolean contourPoints)
Turns a template into a 1D array, used in tensor

Parameters:
contourPoints - flag indicating if to sample contours
Returns:
returns the vectorised template

unvectorise

public void unvectorise(double[] vec)
Turns an array representation back into a a template. This template should have the same structure (number of points lines etc) as the vectorised representation.

Specified by:
unvectorise in interface Vectorisable
Parameters:
vec - The array representation of the vector

get_x

public int get_x(int i)
Gets the x-coord of the ith face point

Parameters:
i - Index of coord to get
Returns:
the x-coord of point i

get_y

public int get_y(int i)
Gets the y-coord of the ith face point

Parameters:
i - Index of coord to get
Returns:
the y-coord of point i

getPoint

public java.awt.geom.Point2D.Float getPoint(int i)
Gets the feature point requested

Parameters:
i - The index of the feature point
Returns:
The point requested

movePoint

public void movePoint(int i,
                      int x,
                      int y)
Moves the point to the specified position

Parameters:
i - The index of the point to move
x - The new x-coord
y - The new y-coord

moveLine

public void moveLine(int i,
                     float dx,
                     float dy)
Moves the point to the specified position

Parameters:
i - The index of the point to move
dx - The x shift
dy - The y shift

move

public void move(float x,
                 float y)
Shifts this by (x,y)

Parameters:
x - the x displacement
y - the y displacement

fixDatMouth

public void fixDatMouth()
Checks if the usual top mouth line is swapped with the bottom mouth line, and fixes it if true.


getContour

public Contour getContour(int i)
Get the ith contour in this template

Parameters:
i - The index of the contour to get
Returns:
The contour

addPoint

public void addPoint(float x,
                     float y)
Adds a point to the Template

Parameters:
x - The x-coord of the new point
y - The y-coord of the new point

addPoint

public void addPoint(int x,
                     int y)
Adds a point to the Template

Parameters:
x - The x-coord of the new point
y - The y-coord of the new point

deletePoint

public void deletePoint(int PointNum)
Deletes the specified point from the Template

Parameters:
PointNum - The index of the point to delete

deleteLine

public void deleteLine(int lineNum)
Delete a line

Parameters:
lineNum - the index of the contour to delete

setLocationPoint

public void setLocationPoint(int i,
                             int x,
                             int y)
setLocations the point to the specified position

Parameters:
i - The index of the point to setLocation
x - The new x-coord
y - The new y-coord

getBoundingBox

public java.awt.Rectangle getBoundingBox()
Gets a bounding rectangle for the Template

Returns:
The bounding rectangle

getBoundingSquare

public java.awt.Rectangle getBoundingSquare()
Gets a bounding square for the Template

Returns:
The bounding square

maskImage

public java.awt.Image maskImage(java.awt.Image img,
                                MaskInterface mask,
                                java.awt.Color col,
                                boolean reverse)
Deprecated. This method will removed in the near future.

Masks an image using the mask object specified/

Parameters:
img - The image to mask
mask - The mask to use
col - The colour to draw in the masked regions
reverse - If true draw outside the polygon defined by the mask, otherwise draw inside
Returns:
return the masked image, the original is unmodified

getMask

public java.awt.Polygon getMask(Mask msk)
Deprecated. This method will removed in the near future.

Constructs a masking polygon from this Template and MaskInterface

Parameters:
msk - The mask defining the lines to use in this mask
Returns:
Return the masking polygon

getMask

public java.awt.Polygon getMask(Mask msk,
                                int xoff,
                                int yoff,
                                float zoom)
Deprecated. This method will removed in the near future.

Constructs a masking polygon from this Template and MaskInterface

Parameters:
msk - The mask defining the lines to use in this mask
xoff - the x-offset
yoff - the y-offset
zoom - the zoom
Returns:
Return the masking polygon

hitPoint

public int hitPoint(int x,
                    int y)
Returns the index if there is a point near (x,y) (+/-5 pixels) -1

Parameters:
x - The x-coord of the test point
y - The y-coord of the test point
Returns:
The index of the point or -1

hitLine

public int hitLine(int x,
                   int y,
                   float zoom)
Returns the index if there is a line near (x,y) (+/-5 pixels) or -1

Parameters:
x - The x-coord of the test point
y - The y-coord of the test point
zoom - the current zoom level
Returns:
The index of the line or -1

hitZoomedPoint

public int hitZoomedPoint(int x,
                          int y,
                          float zoom)
Returns the index if there is a point near (x,y) (+/-5 pixels) -1

Parameters:
x - The x-coord of the point to test
y - The y-coord of the point to test
zoom - The zoom factor
Returns:
The index of the point hit or -1

getPointsInBox

public java.util.ArrayList<java.awt.geom.Point2D.Float> getPointsInBox(float x,
                                                                       float y,
                                                                       float w,
                                                                       float h)
Gets the points in an axis aligned rectangle

Parameters:
x - x coord box corner
y - y coord of box corner
w - width of box
h - height of box
Returns:
returns the list of points in the box

addContour

public void addContour(int x,
                       int y,
                       boolean closed)
Creates a new point and a line that starts at this point

Parameters:
x - The x-coord of the new point
y - The y-coord of the new point
closed - A flag to indicate if the contour is open or a closed loop

addContour

public void addContour(float x,
                       float y,
                       boolean closed)
Creates a new point and a line that starts at this point

Parameters:
x - The x-coord of the new point
y - The y-coord of the new point
closed - A flag to indicate if the contour is open or a closed loop

addContour

public void addContour(int i,
                       boolean closed)
Creates a new curve starting at the point specified

Parameters:
i - The index of the start point
closed - Flag indicating if the curve is an open line or a closed loop

addContourPoint

public boolean addContourPoint(int x,
                               int y)
Creates a new point and adds it to the end of the current contour (the most recently created)

Parameters:
x - The x-coord of the new point
y - The y-coord of the new point
Returns:
true if the line was succesfully created

addContourPoint

public boolean addContourPoint(float x,
                               float y)
Creates a new point and adds it to the end of the current contour (the most recently created)

Parameters:
x - The x-coord of the new point
y - The y-coord of the new point
Returns:
true if the line was succesfully created

addContourPoint

public boolean addContourPoint(int line,
                               float x,
                               float y)
Creates a new point and adds it to the end of the current contour (the most recently created)

Parameters:
line - The line to add the point to
x - The x-coord of the new point
y - The y-coord of the new point
Returns:
true if the line was succesfully created

addContourPoint

public void addContourPoint(int i)
Adds the point specified to the end of the current line

Parameters:
i - The index of the point to connect this line to.

copy

public void copy(Template t)
Copies the Template given into this

Parameters:
t - The Template to copy

clone

public Template clone()
Overrides:
clone in class java.lang.Object

addToAverage

public boolean addToAverage(Template t,
                            int n)
Adds the n'th template to this average

Parameters:
t - The Template to add
n - The number previously added to the average
Returns:
true if added successfully, false other wise (due to different numbers of points in the templates)

average

public int average(Template[] templates,
                   boolean normalise)
Calculates the average of the Templates

Parameters:
templates - the templates to average
normalise - indicates 2 point normalisation should be used (or no normalisation)
Returns:
the number of template in the average on return

average

public int average(Template[] t)
Constructs the average of the array of templates given

Parameters:
t - the array of templates to average
Returns:
the number successfully added to the template

average

public int average(java.util.ArrayList<Template> t,
                   boolean normalise)
Constructs the average of the array of templates given

Parameters:
t - the array of templates to average
normalise - indicates 2 point normalisation should be applied, other wise no normalisation
Returns:
the number successfully added to the template

average

public int average(java.util.ArrayList<Template> t,
                   int normalise,
                   int[] normPoints)
Constructs the average of the array of templates given

Parameters:
t - the array of templates to average
normalise - should be ASM.RIGID_BODY_NORMALISATION, ASM.TWO_POINT_NORMALISATION or ASM.RIGID_BODY_NORMALISATION
normPoints - indicates the normalisation point indices for 2 or 3 point normalisation
Returns:
the number successfully added to the template

weightedAverage

public static Template weightedAverage(Template t1,
                                       float w1,
                                       Template t2,
                                       float w2)
Makes a weighted average of the templates given

Parameters:
t1 - The first template to add
w1 - The weight of the first template in this average
t2 - The second template to add
w2 - The weight of the second template
Returns:
The weighted average Template

weightedAverage

public static Template weightedAverage(java.util.List<Template> templates,
                                       float[] weights,
                                       int iterations)
                                throws java.lang.Exception
Makes a weighted average of the templates given

Parameters:
templates - The list of templates to average
weights - The weight of the each template in this average
iterations - the number of iterations to perform, 0 mean straight average (no normalisation), 1 means normalise to first in set, N means iterate
Returns:
The weighted average Template
Throws:
java.lang.Exception - if the templates are not all the same size (same number of points)

complexAverage

public void complexAverage(Template[] templates)
Calculates the full procrustes average using complex maths

Parameters:
templates - the templates to average

complexAverage

public static Template complexAverage(java.util.ArrayList<Template> origTemplates)
Calculates the full procrustes average using complex maths

Parameters:
origTemplates - the templates to average
Returns:
returns the estimated average

addWeighted

public void addWeighted(Template t,
                        Complex z)
this = this + z*t

Parameters:
t - the Template to add to this
z - the weighting to multiply t by before adding

addWeighted

public void addWeighted(Template t,
                        float s)
this = this + s*t

Parameters:
t - the Template to add to this
s - the weighting to multiply t by before adding

addChimeric

public int addChimeric(Template t,
                       float l1,
                       float l2,
                       float w)
Adds different amounts to the left and right side the points 0 and 1 are used to define the eyes, and hence the symmetry line

Parameters:
t - the template to add
l1 - the amount to add on the (viewers) left
l2 - the amount to add on the (viewers) right
w - the width of the smoothing band
Returns:
returns 1 if successful, 0 otherwise

complexDotProduct

public Complex complexDotProduct(Template t)
Complex dot product of this with t, treating (x,y) coords of each point as complex number x+iy

Parameters:
t - the template to dot product with
Returns:
returns the reult as a complex number

normalise

public void normalise()
Normalise the mean to zero and the magnitude to 1


subtract

public Template subtract(Template rhs)
Creates a new template by subtracting the positions of two input templates output = this - rhs

Parameters:
rhs -
Returns:
returns the difference between this and rhs

scale

public Template scale(double s)
Return a new Template as a copy of this one scaled by s

Parameters:
s - scale factor
Returns:
new template

dotProduct

public double dotProduct(Template t)
Calcualtes the dot product of the templates given

Parameters:
t - The template to dot product with
Returns:
The scalar product of the two templates

transformChimeric

public Template transformChimeric(Template sourceTemplate,
                                  Template destTemplate,
                                  float l1,
                                  float l2,
                                  float w)
Transforms the left and right face sides separately

Parameters:
sourceTemplate - the source Template
destTemplate - the target Template
l1 - the amount to transform the (viewers) left side
l2 - the amount to transform the (viewers) right side
w - the width of the smoothing band
Returns:
returns the transformed template

transform

public Template transform(Template sourceTemplate,
                          Template destTemplate,
                          double s,
                          float scale)
Transforms this Template using the formula this = this + s*(sourceTemplate - destTemplate)

Parameters:
sourceTemplate - The source group's average Template
destTemplate - The destination group's average Template
s - The size of the transform to perform
scale - The amount to magnify the result by
Returns:
The transformed Template

transform

public Template transform(Template sourceTemplate,
                          Template destTemplate,
                          double s,
                          float scale,
                          boolean conts)
Transforms this Template using the formula this = this + s*(sourceTemplate - destTemplate)

Parameters:
sourceTemplate - The source group's average Template
destTemplate - The destination group's average Template
s - The size of the transform to perform
scale - The amount to magnify the result by
conts - Flag specifying if contour samples should be recalculated
Returns:
The transformed Template

transform

public Template transform(Template sourceTemplate,
                          Template destTemplate,
                          double s,
                          float scale,
                          boolean conts,
                          int normalisation,
                          int[] normPoints)
Transforms this Template using the formula this = this + s*(sourceTemplate - destTemplate)

Parameters:
sourceTemplate - The source group's average Template
destTemplate - The destination group's average Template
s - The size of the transform to perform
scale - The amount to magnify the result by
conts - Flag specifying if contour samples should be recalculated
normalisation - indicates the kind of normalisation to use, one of ASM.RIGID_BODY_NORMALISATION, ASM.TWO_POINT_NORMALISATION, ASM.THREE_POINT_NORMALISATION or ASM.NO_NORMALISATION
normPoints - the normalisation points to use for ASM.TWO_POINT_NORMALISATION or ASM.THREE_POINT_NORMALISATION
Returns:
The transformed Template

getMask

public FloatImage getMask(Mask mask,
                          int w,
                          int h,
                          float min,
                          float max)
Deprecated. This method will removed in the near future.

Constructs a FloatImage with values of 0 (masked) and max (not masked)

Parameters:
min - The values to draw outside the masked regions
mask - the MaskInterface that specifies the contours and directions
w - The width of the output mask image
h - The height of the output mask image
max - The values to draw in the masked regions
Returns:
The mask as a FloatImage, this allows it to be smoothed for softer edges

getMask

public FloatImage getMask(java.util.Vector<java.lang.Integer> maskConts,
                          java.util.Vector<java.lang.Integer> maskDirections,
                          int w,
                          int h,
                          float min,
                          float max)
Deprecated. This method will removed in the near future.

Constructs a FloatImage with values of 0 (masked) and max (not masked)

Parameters:
min - The values to draw outside the masked regions
maskConts - The contour numbers making up the boundary of this mask
maskDirections - Flag indicating the directions in which to traverse the contours
w - The width of the output mask image
h - The height of the output mask image
max - The values to draw in the masked regions
Returns:
The mask as a FloatImage, this allows it to be smoothed for softer edges

draw

public void draw(java.awt.Graphics g,
                 int x_off,
                 int y_off)
Draws the Template as a series of points (+) and curved lines on the Graphics provided

Parameters:
g - The Graphics onto which this Template should be drawn
x_off - The x-offset (shift
y_off - The y-offset (shift)

drawZoomed

public void drawZoomed(java.awt.Graphics g,
                       int x_off,
                       int y_off,
                       float xs,
                       float ys)
Draw this Template to the Graphics provided as a series of curved lines and points (+), scaled by the amounts given

Parameters:
g - The Graphics to draw to
x_off - The x-offset
y_off - The y-offset
xs - The x-scale factor
ys - he y-scale factor

read

public boolean read(java.lang.String file)
Reads this Template from the file given

Parameters:
file - The name of the file to read
Returns:
true if the file was read successfully, false otherwise

readDAT

public boolean readDAT(java.lang.String file,
                       int h)
Reads this Template from the file given

Parameters:
file - The name of the file to read
h - height of the image
Returns:
true if the file was read successfully, false otherwise

read

public boolean read(java.lang.String file,
                    int h)
Reads this Template from the file given

Parameters:
file - The name of the file to read
h - height of the image
Returns:
true if the file was read successfully, false otherwise

read

public boolean read(java.io.DataInputStream in)
Read this Template from the DataInputStream provided

Parameters:
in - The DataInputStream to read from
Returns:
true if the Template was successfully read.

readASF

public boolean readASF(java.lang.String file,
                       int w,
                       int h)
Reads this Template from the file given

Parameters:
file - The name of the file to read
w - width of the image
h - height of the image
Returns:
true if the file was read successfully, false otherwise

readASF

public boolean readASF(java.io.DataInputStream in,
                       int w,
                       int h)
Read this Template from the DataInputStream provided

Parameters:
in - The DataInputStream to read from
w - width of the image
h - height of the image
Returns:
true if the Template was successfully read.

readPTS

public boolean readPTS(java.lang.String file)
Reads this Template from the file given

Parameters:
file - The name of the file to read
Returns:
true if the file was read successfully, false otherwise

readPTS

public boolean readPTS(java.io.DataInputStream in)
Read this Template from the DataInputStream provided

Parameters:
in - The DataInputStream to read from
Returns:
true if the Template was successfully read.

getPointColour

public java.awt.Color getPointColour(int i)
Gets the colour of the point

Parameters:
i - the index of the point
Returns:
returns the point's colour

getLineColour

public java.awt.Color getLineColour(int i)
Gets the colour of a line

Parameters:
i - the index of the line
Returns:
return the line's colour

setPointColour

public void setPointColour(int i,
                           java.awt.Color c)
Set the colour of a point

Parameters:
i - the index of the point
c - the new colour of the point

isPointSelected

public boolean isPointSelected(int i)

setPointSelected

public void setPointSelected(int i,
                             boolean s)

setLineColour

public void setLineColour(int i,
                          java.awt.Color c)
Set the colour of a line

Parameters:
i - the index of the line
c - the new colour of the line

isLineSelected

public boolean isLineSelected(int i)

setLineSelected

public void setLineSelected(int i,
                            boolean s)

noContours

public int noContours()

setStandardColours

public void setStandardColours()
Sets the colours to the standard


readDAT

public boolean readDAT(java.io.DataInputStream in,
                       int h)
Read a DAT format template

Parameters:
in - the DataInputStream to read from
h - the image height
Returns:
returns true if read OK

readPCA

public boolean readPCA(java.io.DataInputStream in,
                       Template average,
                       PCA pca,
                       int le,
                       int re,
                       int m)
Reads in 3 normalisation points and some PCA parameters and reconstructs the Template (I think!)

Parameters:
in - The DataInputStream to read from
average - The average Template corresponding to this PCA
pca - The PCA file used to reconstruct this Template
le - the index of the left eye (first normalisation point)
re - the index of the right eye (second normalisation point)
m - the index of the mouth (third normalisation point)
Returns:
true if it all works

write

public boolean write(java.lang.String s)
Writes to the file specified

Parameters:
s - the name of the file to write to
Returns:
returns true if all is OK

write

public boolean write(java.io.PrintStream out)
Writes this Template to file (via a PrintStream)

Parameters:
out - The output PrintStream
Returns:
if written successfully

toString

public java.lang.String toString()
Convert this Template to a textual format for writing / display

Overrides:
toString in class java.lang.Object
Returns:
This Template as a String

toURLString

public java.lang.String toURLString()
Converts this Template to a String, replacing spaces with + etc

Returns:
This Template as a URL writeable String

convert

public boolean convert(java.lang.String stringData)
Parses this Template from the text string in some suitable format

Parameters:
stringData - The String containg the text description of this Template
Returns:
true if it was parsed successfully

autoDelineate

public static Template autoDelineate(java.awt.Image subjectImage,
                                     java.awt.Image averageImage,
                                     Template averageTemplate,
                                     java.awt.geom.Point2D.Float leftEye,
                                     java.awt.geom.Point2D.Float rightEye,
                                     java.awt.geom.Point2D.Float mouth,
                                     int leftIndex,
                                     int rightIndex,
                                     int mouthIndex,
                                     java.awt.image.ImageObserver ob,
                                     PCA pca)
Automatically delineates the image given returning a Template outlining the facial features

Parameters:
subjectImage - The image containing the face to whose features you want to delineate
averageImage - The average image corresponding to the PCA data
averageTemplate - The average Template corresponding to the PCA data
leftEye - The position of the left eye in subjectImage
rightEye - The position of the right eye in subjectImage
mouth - The position of the mouth in subjectImage
leftIndex - The index of the left eye point in this (and the average) Template
rightIndex - The index of the right eye point in this (and the average) Template
mouthIndex - The index of the mouth point in this (and the average) Template
ob - The ImageObserver is used when finding the width and height of the image
pca - The Principal Component Analysis data learnt from example face shapes.
Returns:
The Template adapted to the subjectImage, with the three points fixed as specified.

fitPCA

public boolean fitPCA(java.awt.Image subjectImage,
                      java.awt.Image averageImage,
                      Template averageTemplate,
                      java.awt.geom.Point2D.Float leftEye,
                      java.awt.geom.Point2D.Float rightEye,
                      java.awt.geom.Point2D.Float mouth,
                      int leftIndex,
                      int rightIndex,
                      int mouthIndex,
                      java.awt.image.ImageObserver ob,
                      PCA pca)
Automatically delineates the image given using this Template to outline the facial features

Parameters:
subjectImage - The image containing the face to whose features you want to delineate
averageImage - The average image corresponding to the PCA data
averageTemplate - The average Template corresponding to the PCA data
leftEye - The position of the left eye in subjectImage
rightEye - The position of the right eye in subjectImage
mouth - The position of the mouth in subjectImage
leftIndex - The index of the left eye point in this (and the average) Template
rightIndex - The index of the right eye point in this (and the average) Template
mouthIndex - The index of the mouth point in this (and the average) Template
ob - The ImageObserver is used when finding the width and height of the image
pca - The Principal Component Analysis data learnt from example face shapes.
Returns:
true if the fitting didn't thow an error

fitPCARigid

public boolean fitPCARigid(java.awt.Image subjectImage,
                           java.awt.Image averageImage,
                           Template averageTemplate,
                           java.awt.geom.Point2D.Float leftEye,
                           java.awt.geom.Point2D.Float rightEye,
                           java.awt.geom.Point2D.Float mouth,
                           int leftIndex,
                           int rightIndex,
                           int mouthIndex,
                           java.awt.image.ImageObserver ob,
                           PCA pca)
Automatically delineates the image given using this Template to outline the facial features

Parameters:
subjectImage - The image containing the face to whose features you want to delineate
averageImage - The average image corresponding to the PCA data
averageTemplate - The average Template corresponding to the PCA data
leftEye - The position of the left eye in subjectImage
rightEye - The position of the right eye in subjectImage
mouth - The position of the mouth in subjectImage
leftIndex - The index of the left eye point in this (and the average) Template
rightIndex - The index of the right eye point in this (and the average) Template
mouthIndex - The index of the mouth point in this (and the average) Template
ob - The ImageObserver is used when finding the width and height of the image
pca - The Principal Component Analysis data learnt from example face shapes.
Returns:
true if the fitting didn't thow an error

normaliseEyes

public int normaliseEyes(java.awt.geom.Point2D.Float leftEye,
                         java.awt.geom.Point2D.Float rightEye,
                         int leftIndex,
                         int rightIndex)
Normalise the rotation, translation and scale so that two specified points are in a given place

Parameters:
leftEye - The position of the first point
rightEye - The position of the second point
leftIndex - The index of the point we want positioned at leftEye
rightIndex - The index of the point we want positioned at rightEye
Returns:
1

autoSize

public boolean autoSize(int width,
                        int height)
Resize the template to fit in an image of width by height with a small border

Parameters:
width - The width of the image to fit this into
height - The height of the image to fit this into
Returns:
Return true if this was succesfully fit into the image dimensions given

fitPCAColourSegment

public boolean fitPCAColourSegment(java.awt.Image subjectImage,
                                   java.awt.Image averageImage,
                                   Template averageTemplate,
                                   java.awt.geom.Point2D.Float leftEye,
                                   java.awt.geom.Point2D.Float rightEye,
                                   java.awt.geom.Point2D.Float mouth,
                                   int leftIndex,
                                   int rightIndex,
                                   int mouthIndex,
                                   java.awt.image.ImageObserver ob,
                                   PCA pca,
                                   MaskInterface mask)
Automatically delineates the image given using this Template to outline the facial features Tries to segment out the face from the background using colour to help

Parameters:
mouth - The mouth point
mouthIndex - The index of the mouth point in the template
mask - The mask file to use to estimate face and non face points
subjectImage - The image containing the face to whose features you want to delineate
averageImage - The average image corresponding to the PCA data
averageTemplate - The average Template corresponding to the PCA data
leftEye - The position of the left eye in subjectImage
rightEye - The position of the right eye in subjectImage
leftIndex - The index of the left eye point in this (and the average) Template
rightIndex - The index of the right eye point in this (and the average) Template
ob - The ImageObserver is used when finding the width and height of the image
pca - The Principal Component Analysis data learnt from example face shapes.
Returns:
true if the fitting didn't thow an error

fitPCA

public boolean fitPCA(java.awt.Image subjectImage,
                      java.awt.Image averageImage,
                      Template averageTemplate,
                      java.awt.geom.Point2D.Float leftEye,
                      java.awt.geom.Point2D.Float rightEye,
                      int leftIndex,
                      int rightIndex,
                      java.awt.image.ImageObserver ob,
                      PCA pca)
Automatically delineates the image given using this Template to outline the facial features

Parameters:
subjectImage - The image containing the face to whose features you want to delineate
averageImage - The average image corresponding to the PCA data
averageTemplate - The average Template corresponding to the PCA data
leftEye - The position of the left eye in subjectImage
rightEye - The position of the right eye in subjectImage
leftIndex - The index of the left eye point in this (and the average) Template
rightIndex - The index of the right eye point in this (and the average) Template
ob - The ImageObserver is used when finding the width and height of the image
pca - The Principal Component Analysis data learnt from example face shapes.
Returns:
true if the fitting didn't thow an error

fitPCA

public void fitPCA(FloatImage average,
                   FloatImage subject,
                   Template avrg,
                   PCA pca,
                   int leftIndex,
                   int rightIndex,
                   int mouthIndex)
Fits a Template to this FloatImage

Parameters:
average - The average FloatImage corresponding to the PCA data
subject - The subject to delineate
avrg - The average template corresponding to the PCA data
pca - The Principal Component Analysis data learnt from example face shapes.
leftIndex - the index of the left eye (first normalisation point)
rightIndex - the index of the right eye (second normalisation point)
mouthIndex - the index of the mouth (third normalisation point)

fitPCA

public void fitPCA(FloatImage average,
                   FloatImage subject,
                   Template avrg,
                   PCA pca)
Fits a Template to this FloatImage

Parameters:
average - The average FloatImage corresponding to the PCA data
subject - The subject to delineate
avrg - The average template corresponding to the PCA data
pca - The Principal Component Analysis data learnt from example face shapes.

calculateNormalisationMatrix

public static float[][] calculateNormalisationMatrix(java.awt.geom.Point2D.Float p1,
                                                     java.awt.geom.Point2D.Float p2,
                                                     java.awt.geom.Point2D.Float q1,
                                                     java.awt.geom.Point2D.Float q2)
Calculates the rigid body matrix (rotation, translation and scale) given two matching point pairs

Parameters:
p1 - the first point to setLocation from
p2 - the second point to setLocation from
q1 - the first point to setLocation to
q2 - the second point to setLocation to
Returns:
the matrix as a 3 by 2 array

calculateNormalisationMatrix

public static float[][] calculateNormalisationMatrix(double[][] R,
                                                     double[] T,
                                                     double scale)
Calculates a 3 by 2 rigid body matrix from the rotation, translation and scale specified

Parameters:
R - the 2 by 2 rotation matrix
T - the 2 by 1 translation vector
scale - the scale factor
Returns:
returns the 3 by 2 rigid body matrix

calculateInverseNormalisationMatrix

public static float[][] calculateInverseNormalisationMatrix(double[][] R,
                                                            double[] T,
                                                            double scale)
Calculats the inverse of the normalisation matrix

Parameters:
R - the 2x2 rotation matrix
T - the 2x2 translation matrix
scale - the scale factor
Returns:
returns the 3x2 rigid body matrix

trackASM

public void trackASM(FloatImage average,
                     FloatImage subject,
                     Template avrg,
                     PCA pca,
                     float scale,
                     int its,
                     int[] normalisePointIndex)
Fits a PCA model to an image using edge normal profiles

Parameters:
average - The average image used for edge profiles
subject - the subject image to fit to
avrg - the average shape
pca - the pca data
scale - the current scale of the search
its - maximum number of iterations to perform
normalisePointIndex - the indexes of the normalisation points

normaliseEyes

public float[][] normaliseEyes(Template target)
Performs 2 point normalisation using points 0 and 1

Parameters:
target - the template to normalise to
Returns:
returns the normalisation matrix

normaliseEyes

public float[][] normaliseEyes(Template target,
                               int[] normPoints)
Performs 2 point normalisation using the points indicated in the normPoints array

Parameters:
target - the template to normalise to
normPoints - the array of normalisation point indices
Returns:
returns the normalisation matrix

getPCAandRBparameters

public float[] getPCAandRBparameters(PCA pca,
                                     Template average)
Analyses this Template using a set of principal components

Parameters:
pca - The principal components
average - The average corresponding to this PCA
Returns:
The weighting of each component

getPCAandNormParameters

public float[] getPCAandNormParameters(PCA pca,
                                       Template average,
                                       int normalisation,
                                       int[] normPoints)
Gets the pca and normalisation parameters in a single vector

Parameters:
pca - the PCA data to use
average - the average template
normalisation - the normalisation to use (ASM.TWO_POINT_NORMALISATION, ASM.THREE_POINT_NORMALISATION, ASM.RIGID_BODY_NORMALISATION, or none by default)
normPoints - the normalisation points to use for 2 or 3 point normalisation
Returns:
returns the array of parameters

getTensorandRBparameters

public double[] getTensorandRBparameters(BigMat shapeModel,
                                         BigMat shapeAverage,
                                         Template average,
                                         Tensor shapeTensor)
Analyses this Template using a tensor model

Parameters:
shapeModel - Used in the linear Tensor analysis
shapeAverage - Used in the linear Tensor analysis
shapeTensor - The shape tensor, used in the ALS Tensor analysis
average - The average corresponding to this Tensor
Returns:
The rigid body and tensor parameters for the given template

getMultilinearandRBparameters

public double[] getMultilinearandRBparameters(Multilinear shapeMultilinear)
Analyses this Template using a Multilinear (project out) model

Parameters:
shapeMultilinear - The shape analysis model
Returns:
The rigid body and Multilinear parameters

reconstructPCAandRB

public void reconstructPCAandRB(PCA pca,
                                Template average,
                                float[] PCAandRBparams)
Builds a Template from a set of PCA and Rigid Body parameters and data

Parameters:
pca - The Principal Component Analysis data learnt from example face shapes.
average - The average of the PCA data
PCAandRBparams - The principal component parameters with the first four giving the position of the eyes

reconstructPCAandNorm

public void reconstructPCAandNorm(PCA pca,
                                  Template average,
                                  float[] PCAandRBparams,
                                  int normalisation,
                                  int[] normPoints)
Reconstructs this Template from the PCA data using the parameters and normalisation specified

Parameters:
pca - the PCA data to use
average - the average to use
PCAandRBparams - the model parameters
normalisation - the type of normalisation (ASM.TWO_POINT_NORMALISATION, ASM.THREE_POINT_NORMALISATION, ASM.RIGID_BODY_NORMALISATION, or none by default)
normPoints - the normalisation points to use for 2 or 3 point normalisation

reconstructPCA

public void reconstructPCA(PCA pca,
                           Template average,
                           float[] pcaParams,
                           int toskip)
Reconstruct this Template from PCA data

Parameters:
pca - The PCA data to use
average - the average of the PCA model
pcaParams - the pca parameters
toskip - the first toskip elements from the pcaParams array are skipped (e.g. if they are normalisation parameters)

reconstructTensorandRB

public void reconstructTensorandRB(Tensor shapeTensor,
                                   Template average,
                                   double[] PCAandRBparams)
Builds a Template from a set of Tensor and Rigid Body parameters and data

Parameters:
shapeTensor - The shape Tensor to use for the reconstruction
average - The average of the PCA data
PCAandRBparams - The tensor parameters with the first four giving the position of the eyes

reconstructMultilinearandRB

public void reconstructMultilinearandRB(Multilinear shapeMultilinear,
                                        Template average,
                                        double[] PCAandRBparams,
                                        boolean edgeOnly)
Builds a Template from a set of Multilinear and Rigid Body parameters and data

Parameters:
shapeMultilinear - The shape multilinear model
edgeOnly - flag indicating if we only want to reconstruct from the outer edge components
average - The average of the PCA data
PCAandRBparams - The multilinear parameters with the first four giving the position of the eyes

fitAAMshape

public void fitAAMshape(int warpType,
                        FloatImage average,
                        FloatImage subject,
                        Template avrg,
                        MaskInterface mask,
                        PCA pca,
                        float scale)
First attempt at fitting an AAM to an image, does not include colour information, not recommended to use!

Parameters:
warpType - indicates the type of warp to use
average - The average image
subject - The image to fit too
avrg - the average shape
mask - defines the face pixels within the average image
pca - the principal component analysis of shape
scale - the scale todo this search at (should be 1!)
See Also:
Warp.createWarp(int, int, int, int, int, boolean)

fitAAM

public void fitAAM(int warpType,
                   java.awt.Image subject,
                   java.awt.Image average,
                   MaskInterface mask,
                   PCA pca,
                   PCI pci)
Fits a Template to this FloatImage using a multiscale method

Parameters:
warpType - indicates the type of warp to use
mask - defines the lines comprising the face border
pci - the principal components of the colour image data
average - The average FloatImage corresponding to the PCA data
subject - The subject to delineate
pca - The Principal Component Analysis data learnt from example face shapes.
See Also:
Warp.createWarp(int, int, int, int, int, boolean)

fitAAMappearance

public void fitAAMappearance(int warpType,
                             java.awt.Image subject,
                             java.awt.Image averageImg,
                             MaskInterface mask,
                             PCA pca,
                             PCI pci,
                             float scale)
Attempt at fitting an AAM to an image using efficient reverse method, includes colour information

Parameters:
warpType - indicates the type of warp to use
averageImg - The average image data
pci - The PCI (Principal component image) data
subject - The image to fit too
mask - defines the face pixels within the average image
pca - the principal component analysis of shape
scale - the scale todo this search at (should be 1!)
See Also:
Warp.createWarp(int, int, int, int, int, boolean)

fitTensor

public void fitTensor(int warpType,
                      java.awt.Image subject,
                      java.awt.Image averageImage,
                      Template avrg,
                      MaskInterface mask,
                      Tensor shapeTensor,
                      Tensor imageTensor,
                      BigMat shapeLinearModel,
                      BigMat shapeAverage,
                      BigMat imageLinearModel,
                      BigMat imageAverage,
                      float scale)
Attempt at fitting an Tensor AAM to an image using efficient reverse method, with linear projection model, includes colour information

Parameters:
warpType - indicates the type of warp to use
averageImage - The average image (unmasked)
avrg - The average template
shapeTensor - The shape tensor to use
imageTensor - The image tensor to use
shapeLinearModel - The matrix that performs the shape linear analysis
shapeAverage - The average shape
imageLinearModel - The linear model analysis matrix
imageAverage - The average image
subject - The image to fit too
mask - defines the face pixels within the average image
scale - the scale todo this search at (should be 1!)
See Also:
Warp.createWarp(int, int, int, int, int, boolean)

fitMultilinear

public void fitMultilinear(int warpType,
                           java.awt.Image subject,
                           java.awt.Image averageImage,
                           Template avrg,
                           MaskInterface mask,
                           Multilinear shapeMultilinear,
                           Multilinear imageMultilinear,
                           float scale)
Attempt at fitting an Multilinear AAM to an image using efficient reverse method, with linear projection model, includes colour information

Parameters:
warpType - indicates the type of warp to use
averageImage - The unmasked average image
avrg - The shape average
shapeMultilinear - The average Template
imageMultilinear - The multilinear image model
subject - The image to fit too
mask - defines the face pixels within the average image
scale - the scale todo this search at (should be 1!)
See Also:
Warp.createWarp(int, int, int, int, int, boolean)

constructMultilinearFitter

public FloatImage[] constructMultilinearFitter(int warpType,
                                               java.awt.Image averageImage,
                                               Template avrg,
                                               MaskInterface mask,
                                               Multilinear shapeMultilinear,
                                               Multilinear imageMultilinear,
                                               float scale)
Constructs the data needed for fitting a multilinear AAM to an image using efficient reverse method, with linear projection model, includes colour information

Parameters:
warpType - indicates the type of warp to use
averageImage - The uinmasked average image
avrg - Te average shape
shapeMultilinear - The multilinear shape analysis matrix
imageMultilinear - The image multilinear analysis matrix
mask - defines the face pixels within the average image
scale - the scale todo this search at (should be 1!)
Returns:
Return a set of images representing the fitter
See Also:
Warp.createWarp(int, int, int, int, int, boolean)

fitMultilinear

public void fitMultilinear(java.awt.Image subject,
                           java.awt.Image averageImage,
                           Template avrg,
                           MaskInterface mask,
                           Multilinear shapeMultilinear,
                           Multilinear imageMultilinear,
                           FloatImage[] diffImg,
                           float scale)
Uses a multilinear fitting model to try a fit a template to the image

Parameters:
subject - The image to fit to
averageImage - The unmasked average image
avrg - The average shape
mask - a mask that defines the face region
shapeMultilinear - the linear shape analysis matrix
imageMultilinear - the linear image analysis matrix
diffImg - The derivative images with repsect to the model parameters at the origin
scale - The scal to do the fitting at (currently unused)

fitAAMbayesian

public void fitAAMbayesian(int warpType,
                           java.awt.Image subject,
                           java.awt.Image averageImg,
                           MaskInterface mask,
                           PCA pca,
                           PCI pci,
                           float scale)
Attempt at fitting an AAM to an image using efficient reverse method, includes colour information

Parameters:
warpType - indicates the type of warp to use
averageImg - The average image data
pci - The PCI (Principal component image) data
subject - The image to fit too
mask - defines the face pixels within the average image
pca - the principal component analysis of shape
scale - the scale todo this search at (should be 1!)
See Also:
Warp.createWarp(int, int, int, int, int, boolean)

fitAAMspan

public int fitAAMspan(int warpType,
                      java.awt.Image subject,
                      java.awt.Image averageImg,
                      MaskInterface mask,
                      PCA pca,
                      PCI pci,
                      FloatImage[] smallPCIcomps,
                      float scale,
                      int counter)
Attempt at fitting an AAM to an image using efficient reverse method, colour information is projected out

Parameters:
warpType - indicates the type of warp to use
smallPCIcomps - image pca components to project out
counter -
averageImg - The average image data
pci - The PCI (Principal component image) data
subject - The image to fit too
mask - defines the face pixels within the average image
pca - the principal component analysis of shape
scale - the scale todo this search at (should be 1!)
Returns:
returns an int for some reason
See Also:
Warp.createWarp(int, int, int, int, int, boolean)

fitAAMspanLM

public int fitAAMspanLM(int warpType,
                        java.awt.Image subject,
                        java.awt.Image averageImg,
                        MaskInterface mask,
                        PCA pca,
                        PCI pci,
                        float scale,
                        int counter)
Attempt at fitting an AAM to an image using efficient reverse method, includes colour information

Parameters:
warpType - indicates the type of warp to use
averageImg - The average image data
pci - The PCI (Principal component image) data
subject - The image to fit too
mask - defines the face pixels within the average image
pca - the principal component analysis of shape
scale - the scale todo this search at (should be 1!)
counter - initial value for counter used in debugging
Returns:
returns the current value of counter
See Also:
Warp.createWarp(int, int, int, int, int, boolean)

fitAAMforward

public void fitAAMforward(java.awt.Image subjectImg,
                          java.awt.Image averageImg,
                          MaskInterface mask,
                          PCA pca,
                          PCI pci,
                          float scale)
Attempt at fitting an AAM to an image using inefficient, but more reliable forward method, includes colour information

Parameters:
subjectImg - The image to fit to.
averageImg - The average image data
pci - The PCI (Principal component image) data
mask - defines the face pixels within the average image
pca - the principal component analysis of shape
scale - the scale todo this search at (should be 1!)

reconstructPCA

public void reconstructPCA(PCA pca,
                           Template average,
                           java.awt.geom.Point2D.Float left,
                           java.awt.geom.Point2D.Float right,
                           java.awt.geom.Point2D.Float mouth,
                           float[] pcaParams,
                           int leftIndex,
                           int rightIndex,
                           int mouthIndex)
Builds a Template from a set of PCA parameters and data

Parameters:
pca - The Principal Component Analysis data learnt from example face shapes.
average - The average of the PCA data
left - The position of the left eye point after reconstruction
right - The position of the right eye after reconstruction
mouth - The position of the mouth after reconstruction
pcaParams - The principal component parameters
leftIndex - the index of the left eye (first normalisation point)
rightIndex - the index of the right eye (second normalisation point)
mouthIndex - the index of the mouth (third normalisation point)

getPCAparameters

public float[] getPCAparameters(PCA pca,
                                Template average,
                                int leftIndex,
                                int rightIndex,
                                int mouthIndex)
Analyses this Template using a set of principal components

Parameters:
pca - The principal components
average - The average corresponding to this PCA
leftIndex - the index of the left eye (first normalisation point)
rightIndex - the index of the right eye (second normalisation point)
mouthIndex - the index of the mouth (third normalisation point)
Returns:
The weighting of each component

calculateAffineMatrix

public int calculateAffineMatrix(java.awt.geom.Point2D.Float p1,
                                 java.awt.geom.Point2D.Float p2,
                                 java.awt.geom.Point2D.Float p3,
                                 java.awt.geom.Point2D.Float q1,
                                 java.awt.geom.Point2D.Float q2,
                                 java.awt.geom.Point2D.Float q3,
                                 float[][] mat)
Calcualtes the best affine transform matrix (rotation, translation, scale and shear)

Parameters:
p1 - the first point to setLocation from
p2 - the second point to setLocation from
p3 - the third point to setLocation from
q1 - the first point to setLocation to
q2 - the second point to setLocation to
q3 - the third point to setLocation to
mat - The matrix to fill in
Returns:
1

transform

public void transform(float[][] mat)
Performs a matrix transform on this Template

Parameters:
mat - The matrix to Transform this Template with

zoom

public void zoom(float zoomx,
                 float zoomy,
                 float crop_x,
                 float crop_y)
Magnify and shift this Template

Parameters:
zoomx - The amount to zoom in x
zoomy - The amount to zoom in y
crop_x - The amount to shift in x
crop_y - The amount to shift in y

affineFit

public float[][] affineFit(Template tem,
                           int[] normalisationPoints)
Performs an affine fit of this to Template tem using the normalisation points specified

Parameters:
tem - The templateto fit to
normalisationPoints - the indices of the 3 normalisation points to use
Returns:
returns the transformation matrix

affineFit

public void affineFit(java.awt.geom.Point2D.Float leftEye,
                      java.awt.geom.Point2D.Float rightEye,
                      java.awt.geom.Point2D.Float mouth,
                      int leftIndex,
                      int rightIndex,
                      int mouthIndex)
Performs an affine (linear) operation on this Template, specified by 3 points

Parameters:
leftEye - The desired position of the first point
rightEye - The desired position of the second point
mouth - The desired position of the third point
leftIndex - The index of the first point in this Template
rightIndex - The index of the second point in this Template
mouthIndex - The index of the third point in this Template

getAffineMatrix

public static float[][] getAffineMatrix(java.awt.geom.Point2D.Float[] source,
                                        java.awt.geom.Point2D.Float[] target)
Get the affine transform matrix that map the 3 points specified in source onto 3 points target

Parameters:
source - the 3 source points
target - the 3 target points
Returns:
returns the affine transform matrix as a [3][2] array

affineFit2

public int affineFit2(java.awt.geom.Point2D.Float leftEye,
                      java.awt.geom.Point2D.Float rightEye,
                      java.awt.geom.Point2D.Float mouth,
                      int leftIndex,
                      int rightIndex,
                      int mouthIndex1,
                      int mouthIndex2)
Performs an affine fit of this template to the points given, using the midpoint of mouthIndex1 and mouthIndex2 to match to mouth point

Parameters:
leftEye - point to match to
rightEye - point to match to
mouth - point to match to
leftIndex - index of point to shift
rightIndex - index of point to shift
mouthIndex1 - index of point to shift
mouthIndex2 - index of point to shift
Returns:
1

rigidBodyFit

public double rigidBodyFit(Template tmplt,
                           double[][] R,
                           double[] T)
Calculates and performs a least-square error rigid-body transform on this Template

Parameters:
tmplt - The Template to match position and scale to
R - The 2x2 rotation matrix
T - The 2x1 translation vector
Returns:
The scale factor

calculateRigidBodyFit

public double calculateRigidBodyFit(Template tmplt,
                                    double[][] R,
                                    double[] T)
Calculates and performs a least-square error rigid-body transform on this Template

Parameters:
tmplt - The Template to match position and scale to
R - The 2x2 rotation matrix
T - The 2x1 translation vector
Returns:
The scale factor

warp

public void warp(Warp warp)
Warp the template with the warp given

Parameters:
warp - The warp to apply to this Template

warp

public void warp(TPSWarp warp)
Warp the template with the warp given

Parameters:
warp - The warp to apply to this Template

recalculateContours

public void recalculateContours()
Recalculates the curves through the control points after they have setLocationd.


getDrawLabels

public boolean getDrawLabels()
Returns:
the drawLabels

setDrawLabels

public void setDrawLabels(boolean drawLabels)
Parameters:
drawLabels - the drawLabels to set

readSymFile

public static int[] readSymFile(java.lang.String name)
                         throws java.io.FileNotFoundException,
                                java.io.IOException
Read a symmetry (.sym) file

Parameters:
name - the name of the file to read
Returns:
returns the symmetry data as an array of ints
Throws:
java.io.FileNotFoundException
java.io.IOException

reflect

public void reflect(int[] plist,
                    int width)
Reflect the template using the symetry data given i.e. points on the left will stay on the left but move to the flipped location of the equivalent point on the right, and vice versa.

Parameters:
plist - the symmetry data
width - the width of the image being flipped

symmetrise

public void symmetrise(Template t,
                       int[] plist,
                       int w)
Makes this template a symmetrical version of t

Parameters:
t - the template to symmetrise
plist - the symmetry data
w - the width of the image