Facemorph.tensor
Class Multilinear

java.lang.Object
  extended by Facemorph.tensor.Multilinear
All Implemented Interfaces:
java.io.Serializable

public class Multilinear
extends java.lang.Object
implements java.io.Serializable

Multilinear model class

See Also:
Serialized Form

Constructor Summary
Multilinear(Tensor T, int dataDim, double maxvar)
          Creates a new instance of Multilinear Performs PCA along each of the plane average vectors Replace residuals with best linear fit etc etc
 
Method Summary
 double[][] convertParams(double[] params)
          Convert the parameters to multi-linear
static double dotProduct(double[] v1, double[] v2)
          Find the dot product between two vectors
 double[][] getALSParams(double[] test)
          Get Alternating Least Squares (ALS) parameters
 double[] getAverage()
          Get the average
 double[][] getBestFitEdgeParams(double[] test)
          Gets the best parameters from the edge (linear) components
 double[] getEdgeComp(int index)
          Get a component along the edges
static Multilinear getImageMultilinear(int[] dims, java.util.Vector<java.awt.Image> images, double maxvar)
          Get a multilinear model from a set of images
static Multilinear getTemplateMultilinear(int[] dims, java.util.Vector<Template> templates, double maxvar)
          Get a MultiLinear object from the Templates
 int getTotalParams()
          Get the total number of parameters
static void main(java.lang.String[] args)
          Main method for testing
static int[] readImagesAndTemplates(java.lang.String listFile, java.util.Vector<Template> templates, java.util.Vector<java.awt.Image> images, java.util.Vector<java.lang.String> temNames, java.util.Vector<java.lang.String> imgNames)
          Read images and templates from a file
 double[] reconstruct(double[][] params)
          Reconstruct from parameters
 double[] reconstructEdgeParams(double[][] params)
          Reconstruct using only the edge parameters
 double[] reconvertParams(double[][] params)
          Creates a single vector from the edge parameters
static void testLinear(java.lang.String[] args)
          Test of linear building method
static FloatImage[] unvectoriseColourFloatImage(double[] rgb, int width, int height)
          Unvectorise an image to an array of FloatImage
static java.awt.Image unvectoriseImage(double[] rgb, int width, int height)
          Unvectorise an image
static double[] vectoriseColourFloatImage(FloatImage[] rgb)
          Vectorise 3 plane RGB image into a 1D vector
static double[] vectoriseImage(java.awt.Image img)
          Vectorise an image into a 1D vector
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Multilinear

public Multilinear(Tensor T,
                   int dataDim,
                   double maxvar)
            throws BigMatException
Creates a new instance of Multilinear Performs PCA along each of the plane average vectors Replace residuals with best linear fit etc etc

Parameters:
T - the input Tensor
dataDim - the data dimension
maxvar - the maximum variance to explain in any dimension
Throws:
BigMatException
Method Detail

getAverage

public double[] getAverage()
Get the average

Returns:
return the average

dotProduct

public static double dotProduct(double[] v1,
                                double[] v2)
Find the dot product between two vectors

Parameters:
v1 - the first vector
v2 - the second vector
Returns:
returns the dot product

getEdgeComp

public double[] getEdgeComp(int index)
Get a component along the edges

Parameters:
index - the index of the component
Returns:
returns the edge component

reconstructEdgeParams

public double[] reconstructEdgeParams(double[][] params)
Reconstruct using only the edge parameters

Parameters:
params - the parameters
Returns:
return the reconstructed vector

getTotalParams

public int getTotalParams()
Get the total number of parameters

Returns:
return the total number of parameters

getBestFitEdgeParams

public double[][] getBestFitEdgeParams(double[] test)
Gets the best parameters from the edge (linear) components

Parameters:
test - the vector to analyse
Returns:
return the linear model parameters

getALSParams

public double[][] getALSParams(double[] test)
Get Alternating Least Squares (ALS) parameters

Parameters:
test - the intput vector
Returns:
returns the ALS estimated parameters

reconstruct

public double[] reconstruct(double[][] params)
                     throws BigMatException
Reconstruct from parameters

Parameters:
params - the parameters
Returns:
return the reconstructed vector
Throws:
BigMatException

reconvertParams

public double[] reconvertParams(double[][] params)
Creates a single vector from the edge parameters

Parameters:
params - the intpu Tensor paraameters
Returns:
the vectorised parameters

convertParams

public double[][] convertParams(double[] params)
Convert the parameters to multi-linear

Parameters:
params - the parameters to convert
Returns:
returns the converted parameters

getTemplateMultilinear

public static Multilinear getTemplateMultilinear(int[] dims,
                                                 java.util.Vector<Template> templates,
                                                 double maxvar)
                                          throws BigMatException
Get a MultiLinear object from the Templates

Parameters:
dims - the number of dimensions
templates - the templates
maxvar - the maximum variation to explain
Returns:
return the constructed MultiLinear model
Throws:
BigMatException

vectoriseImage

public static double[] vectoriseImage(java.awt.Image img)
Vectorise an image into a 1D vector

Parameters:
img - the image to vectorise
Returns:
return the vectorised image

unvectoriseImage

public static java.awt.Image unvectoriseImage(double[] rgb,
                                              int width,
                                              int height)
Unvectorise an image

Parameters:
rgb - the data vector to unvectorise
width - the width of the output image
height - the height of the output image
Returns:
return the unvectorised image

unvectoriseColourFloatImage

public static FloatImage[] unvectoriseColourFloatImage(double[] rgb,
                                                       int width,
                                                       int height)
Unvectorise an image to an array of FloatImage

Parameters:
rgb - the vector
width - the output width
height - the output height
Returns:
return the unvectorised image

vectoriseColourFloatImage

public static double[] vectoriseColourFloatImage(FloatImage[] rgb)
Vectorise 3 plane RGB image into a 1D vector

Parameters:
rgb - the intput image in 3 planes
Returns:
return the vectorised image

getImageMultilinear

public static Multilinear getImageMultilinear(int[] dims,
                                              java.util.Vector<java.awt.Image> images,
                                              double maxvar)
                                       throws BigMatException
Get a multilinear model from a set of images

Parameters:
dims - the size of each dimension
images - the images
maxvar - the maximum variance to explain along each dimension
Returns:
returns the multiline model
Throws:
BigMatException

readImagesAndTemplates

public static int[] readImagesAndTemplates(java.lang.String listFile,
                                           java.util.Vector<Template> templates,
                                           java.util.Vector<java.awt.Image> images,
                                           java.util.Vector<java.lang.String> temNames,
                                           java.util.Vector<java.lang.String> imgNames)
Read images and templates from a file

Parameters:
listFile - the file containing the file names
templates - the vector to put the templates in
images - the array to put the images in
temNames - the output vector of template names
imgNames - the output vector of image names
Returns:
returns the model dimensions

main

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

Parameters:
args - the program args (currently testLinear)
Throws:
BigMatException

testLinear

public static void testLinear(java.lang.String[] args)
                       throws BigMatException
Test of linear building method

Parameters:
args - args[0] - list file, args[1] - width, args[2] - height, args[3] - mask, args[4] - test list
Throws:
BigMatException