Facemorph.psm
Class PSMNode

java.lang.Object
  extended by Facemorph.psm.PSMNode

public class PSMNode
extends java.lang.Object

PSMNode: an implementation of Pictorial Structure Models


Constructor Summary
PSMNode()
          PSMNode constructor
PSMNode(int start, BigMat mst, Feature appGauss, DiagonalGaussian[][] gauss, boolean[] visited, int w, int h)
          Contruct a PSMNode
 
Method Summary
 void batchTest(java.lang.String outfold, java.util.ArrayList<java.lang.String> imageNames, java.util.ArrayList<java.lang.String> templateNames, int w, HaarReader haar)
          Batch testing method
 FloatImage evaluateProbability(java.awt.Image img)
          Evaluate the probability of this feature in the image supplied
static int findBestRoot(BigMat tree, BigMat graph)
          Finds the "best" root of the tree
static Feature getFeature(java.lang.String className)
          Dynamically loads the Feature given its class name
 java.util.ArrayList<java.awt.geom.Point2D.Float> getFeatures()
          Get the feature points
 Template getFeatures(java.awt.image.BufferedImage bimg, HaarReader haar)
          Detect the deature in the image using this model
 java.util.ArrayList<java.awt.geom.Point2D.Float> getFeatures(java.awt.Image source)
          Get the feature points in the image
static void main(java.lang.String[] args)
          Main method for testing
static BigMat minimumSpanningTree(BigMat graph)
          Get the minimum spanning tree of the graph
static double ncc(double[] v1, double[] v2)
          The normalised cross correlation
 void read(java.io.InputStream in, java.lang.String folder, boolean url)
          Read from the named input stream
 void read(java.io.StreamTokenizer st, Feature app, java.lang.String folder, boolean url)
          Read a PSM
 void read(java.lang.String fileName)
          Read from a file
 void read(java.lang.String fileName, boolean url)
          Read a PSMNode from file
 double shapeError(java.util.ArrayList<java.awt.geom.Point2D.Float> detectedPoints, Template template, int[] pointList)
          Find the RMS error
static PSMNode train(java.util.ArrayList<java.lang.String> imageNames, java.util.ArrayList<java.lang.String> templateNames, int[] pointList, int w, int enrich, java.lang.String featureClassName, HaarReader haar)
          Train a PSM model
 void write(java.io.PrintStream ps, boolean writeApp, java.lang.String folder)
          Write a PSMNode
 void write(java.lang.String fileName)
          Write a PSMNode to the file named
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PSMNode

public PSMNode()
PSMNode constructor


PSMNode

public PSMNode(int start,
               BigMat mst,
               Feature appGauss,
               DiagonalGaussian[][] gauss,
               boolean[] visited,
               int w,
               int h)
Contruct a PSMNode

Parameters:
start - the node to start at
mst - the minimum spanning tree
appGauss - the appearance
gauss - the conditional positional probability model of the nodes
visited - indicates which nodes have been visited
w - the width
h - the height
Method Detail

write

public void write(java.lang.String fileName)
Write a PSMNode to the file named

Parameters:
fileName - the name of the file

write

public void write(java.io.PrintStream ps,
                  boolean writeApp,
                  java.lang.String folder)
Write a PSMNode

Parameters:
ps - the print stream to write to
writeApp - Should the appearance be written
folder - the folder to write to

read

public void read(java.lang.String fileName,
                 boolean url)
Read a PSMNode from file

Parameters:
fileName - the name of the file or URL
url - if true the name referes to a URL

read

public void read(java.lang.String fileName)
Read from a file

Parameters:
fileName - the name of the file

read

public void read(java.io.InputStream in,
                 java.lang.String folder,
                 boolean url)
          throws java.io.IOException
Read from the named input stream

Parameters:
in - the input stream
folder - folder to read (children) from
url - indicates that the children should be read from a URL
Throws:
java.io.IOException

getFeature

public static Feature getFeature(java.lang.String className)
Dynamically loads the Feature given its class name

Parameters:
className - Name of the class to load, must implement the Feature interface and be in the class path to be loaded
Returns:
returns the Feature of the given name

read

public void read(java.io.StreamTokenizer st,
                 Feature app,
                 java.lang.String folder,
                 boolean url)
          throws java.io.IOException
Read a PSM

Parameters:
st - the stream tokenizer to read from
app - the appearance of this node
folder - indicates the base folder/url to read children from
url - indicates children should be read from a URL
Throws:
java.io.IOException

train

public static PSMNode train(java.util.ArrayList<java.lang.String> imageNames,
                            java.util.ArrayList<java.lang.String> templateNames,
                            int[] pointList,
                            int w,
                            int enrich,
                            java.lang.String featureClassName,
                            HaarReader haar)
Train a PSM model

Parameters:
imageNames - the list of training images
templateNames - the list of training template names
pointList - the list of points to use from the template
w - the desired width for training the appearance model
enrich - the amount of enrichment of the training data to use (currently disabled)
featureClassName - the name of the feature model to use
haar - the face detector to use
Returns:
returns the trained model

findBestRoot

public static int findBestRoot(BigMat tree,
                               BigMat graph)
Finds the "best" root of the tree

Parameters:
tree - contains the MST, with 1 or 0 to indicate tree edges
graph - the graph contains the edge weights of the complete graph
Returns:
returns the index of the most conected / central node

minimumSpanningTree

public static BigMat minimumSpanningTree(BigMat graph)
Get the minimum spanning tree of the graph

Parameters:
graph - the edge weight matrix
Returns:
return the MST as a matrix

evaluateProbability

public FloatImage evaluateProbability(java.awt.Image img)
Evaluate the probability of this feature in the image supplied

Parameters:
img - the image to test, or if null the currently set image is used
Returns:
returns the probability of the feature location, recursing down and back up the feature tree

getFeatures

public java.util.ArrayList<java.awt.geom.Point2D.Float> getFeatures(java.awt.Image source)
Get the feature points in the image

Parameters:
source - the input image
Returns:
the estimated feature locations

getFeatures

public java.util.ArrayList<java.awt.geom.Point2D.Float> getFeatures()
Get the feature points

Returns:
return the most likely feature points

ncc

public static double ncc(double[] v1,
                         double[] v2)
The normalised cross correlation

Parameters:
v1 - the first vector
v2 - the second vector
Returns:
returns the ncc between the two vectors

shapeError

public double shapeError(java.util.ArrayList<java.awt.geom.Point2D.Float> detectedPoints,
                         Template template,
                         int[] pointList)
Find the RMS error

Parameters:
detectedPoints - the detected points
template - the ground truth
pointList - the list of points in template that correspond to the detected points
Returns:
return the RMS error

batchTest

public void batchTest(java.lang.String outfold,
                      java.util.ArrayList<java.lang.String> imageNames,
                      java.util.ArrayList<java.lang.String> templateNames,
                      int w,
                      HaarReader haar)
Batch testing method

Parameters:
outfold - the output folder
imageNames - the names of the images to test
templateNames - the names of the templates
w - the desired appearance image size
haar - the face detector

getFeatures

public Template getFeatures(java.awt.image.BufferedImage bimg,
                            HaarReader haar)
Detect the deature in the image using this model

Parameters:
bimg - the image to search
haar - the face detector
Returns:
returns a Template containin the detected features, or null if the face detection failed

main

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

Parameters:
args - the program args