Facemorph.oesf
Class OESF

java.lang.Object
  extended by Facemorph.oesf.OESF

public class OESF
extends java.lang.Object

Implementation of Optimal Synthetic Exact Filters


Constructor Summary
OESF()
           
 
Method Summary
 FloatImage[] buildFilter(java.lang.String file, HaarReader haar, boolean orientation, int[] plist)
          Build a set of OESF filters
 FloatImage buildFilter(java.lang.String file, HaarReader haar, int[] plist)
          Build an OESF filter
static FloatImage centre(FloatImage fimg)
          Shift the origin to centre for easier human veiwing / interpretation
static FloatImage convert(Complex[] a, int w, int h)
          Converts an array of Complex back into a FloatImage, discarding imaginary components
static Complex[] convert(FloatImage fimg)
          Scan converts a FloatImage to an array of Complex
static Complex[] convert(FloatImage[] fimg)
          Converts a pair of FloatImages {real, imaginary} into a Complex array
static FloatImage[] convertComplex(Complex[] a, int w, int h)
          Convert a Complex array into a pair of FloatImages {real, imaginary}
static java.awt.Rectangle detectFace(java.awt.image.BufferedImage bimg, HaarReader haar)
          Detect a face
static java.awt.Rectangle detectFace(java.awt.image.BufferedImage bimg, HaarReader haar, java.awt.Rectangle prevRect)
          Detect a face
static FloatImage filter(FloatImage fimg, Complex[] filt, int[] dim)
          Apply a filter to an image
static FloatImage[] filterComplex(FloatImage fimg, Complex[] filt, int[] dim)
          Filters a real image with a complex filter
static Complex[] getMultiResponse(Template tem, int[] plist, int[] dim)
          Get an idealised response image for all listed features in the Template
static Complex[] getResponse(float x, float y, double angle, int[] dim)
          Get the response image with orientation information (trying to detect orientation doesn't seem to work all that well)
static Complex[] getResponse(float x, float y, int[] dim)
          Create an idealised response image
static boolean hasNextQuotedString(java.util.Scanner sc)
          Returns true if the next token is the beginning of a quoted string value.
static void main(java.lang.String[] args)
          Main method used for testing
static java.lang.String nextQuotedString(java.util.Scanner sc)
          Scans a quoted string value from the scanner input.
static void preprocess(FloatImage fimg)
          Preprocess the image using a log transform (y=log(1+x)), normalis mean and sd and sine window
 void read(java.lang.String dir)
          Read an OESF filter from file
static void testFilter(java.lang.String file, java.util.ArrayList<FloatImage> filters, FloatImage prior, HaarReader haar)
          Test the filter
static void testFilterComplex(java.lang.String file, java.util.ArrayList<FloatImage[]> filters, FloatImage prior, HaarReader haar)
          Test the complex filter
 void write(java.lang.String dir)
          Writes the filters and prior data to file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OESF

public OESF()
Method Detail

convert

public static Complex[] convert(FloatImage fimg)
Scan converts a FloatImage to an array of Complex

Parameters:
fimg - the FloatImage to convert
Returns:
returns an array of Complex

convert

public static Complex[] convert(FloatImage[] fimg)
Converts a pair of FloatImages {real, imaginary} into a Complex array

Parameters:
fimg - the pair of images to convert
Returns:
returns an array of Complex

convert

public static FloatImage convert(Complex[] a,
                                 int w,
                                 int h)
Converts an array of Complex back into a FloatImage, discarding imaginary components

Parameters:
a - the complex array of data
w - the output width
h - the output height
Returns:
returns the real part as a FloatImage

convertComplex

public static FloatImage[] convertComplex(Complex[] a,
                                          int w,
                                          int h)
Convert a Complex array into a pair of FloatImages {real, imaginary}

Parameters:
a - the Complex array
w - the output width
h - the output height
Returns:
returns 2 FloatImages, one for the real parts and one for the complex

preprocess

public static void preprocess(FloatImage fimg)
Preprocess the image using a log transform (y=log(1+x)), normalis mean and sd and sine window

Parameters:
fimg - the image to preprocess

getResponse

public static Complex[] getResponse(float x,
                                    float y,
                                    int[] dim)
Create an idealised response image

Parameters:
x - the x-coord of the feature
y - the y-coord of the feature
dim - the dimensions of the Complex array, should be {128, 128}
Returns:
returns the complex array

getMultiResponse

public static Complex[] getMultiResponse(Template tem,
                                         int[] plist,
                                         int[] dim)
Get an idealised response image for all listed features in the Template

Parameters:
tem - the Template
plist - the list of points from the Template to use
dim - the dimension (should be {128, 128}
Returns:
return the response image for all the features

getResponse

public static Complex[] getResponse(float x,
                                    float y,
                                    double angle,
                                    int[] dim)
Get the response image with orientation information (trying to detect orientation doesn't seem to work all that well)

Parameters:
x - the x-coord
y - the y-coord
angle - the angle of the feature rotation
dim - the dimensionality should be {128, 128}
Returns:
returns the response image

buildFilter

public FloatImage buildFilter(java.lang.String file,
                              HaarReader haar,
                              int[] plist)
                       throws java.io.FileNotFoundException,
                              java.io.IOException
Build an OESF filter

Parameters:
file - list of images in a file
haar - face detector
plist - list of points to use from each template (only the first point is returned)
Returns:
returns the optimal filter
Throws:
java.io.FileNotFoundException
java.io.IOException

buildFilter

public FloatImage[] buildFilter(java.lang.String file,
                                HaarReader haar,
                                boolean orientation,
                                int[] plist)
                         throws java.io.FileNotFoundException,
                                java.io.IOException
Build a set of OESF filters

Parameters:
file - the name of the file containing the list of images and template
haar - the face detector
orientation - idicates that we want to try and learn detectors that give us the orientation
plist - the list of points to use from the templates
Returns:
return the set of filters, one for each point
Throws:
java.io.FileNotFoundException
java.io.IOException

write

public void write(java.lang.String dir)
           throws java.io.IOException
Writes the filters and prior data to file

Parameters:
dir - the folder to write to (filter.fimg, prior.fimg and data.txt are written to this file)
Throws:
java.io.IOException

read

public void read(java.lang.String dir)
          throws java.io.IOException
Read an OESF filter from file

Parameters:
dir - the directory to read from (reads filter.fimg, prior.fimg and data.txt)
Throws:
java.io.IOException

centre

public static FloatImage centre(FloatImage fimg)
Shift the origin to centre for easier human veiwing / interpretation

Parameters:
fimg - the filter image to centre
Returns:
returns the fiter image centred on its midpoint

filter

public static FloatImage filter(FloatImage fimg,
                                Complex[] filt,
                                int[] dim)
Apply a filter to an image

Parameters:
fimg - the image to apply the filter to
filt - the FFT of the filter
dim - the dimensionality data {128, 128}
Returns:
return the filtered image (spatial domain)

filterComplex

public static FloatImage[] filterComplex(FloatImage fimg,
                                         Complex[] filt,
                                         int[] dim)
Filters a real image with a complex filter

Parameters:
fimg - the image to filter
filt - the FFT of the complex filter
dim - the dimensionality
Returns:
returns the real and imaginary components of the filtered image

detectFace

public static java.awt.Rectangle detectFace(java.awt.image.BufferedImage bimg,
                                            HaarReader haar)
Detect a face

Parameters:
bimg - the image to look for faces in
haar -
Returns:
return the biggest face detected or null

detectFace

public static java.awt.Rectangle detectFace(java.awt.image.BufferedImage bimg,
                                            HaarReader haar,
                                            java.awt.Rectangle prevRect)
Detect a face

Parameters:
bimg - the image to look for faces in
haar - the face detector
prevRect - the previous rectangle, if not null it is added to list of candidate rectangles
Returns:
return the biggest face detected or null

testFilter

public static void testFilter(java.lang.String file,
                              java.util.ArrayList<FloatImage> filters,
                              FloatImage prior,
                              HaarReader haar)
                       throws java.io.FileNotFoundException,
                              java.io.IOException
Test the filter

Parameters:
file - the file to read image and template names from
filters - the filters to use
prior - the prior data
haar - the face detector
Throws:
java.io.FileNotFoundException
java.io.IOException

testFilterComplex

public static void testFilterComplex(java.lang.String file,
                                     java.util.ArrayList<FloatImage[]> filters,
                                     FloatImage prior,
                                     HaarReader haar)
                              throws java.io.FileNotFoundException,
                                     java.io.IOException
Test the complex filter

Parameters:
file - the file to read image and template names from
filters - the filters to use
prior - the prior data
haar - the face detector
Throws:
java.io.FileNotFoundException
java.io.IOException

main

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

Parameters:
args - the program args, args[0] = list of images and template to build from, args[1] = test list
Throws:
java.io.FileNotFoundException
java.io.IOException

hasNextQuotedString

public static boolean hasNextQuotedString(java.util.Scanner sc)
Returns true if the next token is the beginning of a quoted string value.

Parameters:
sc - the Scanner to read from
Returns:
returns true if the Scanner has a next quoted string

nextQuotedString

public static java.lang.String nextQuotedString(java.util.Scanner sc)
Scans a quoted string value from the scanner input.

Parameters:
sc - the Scanner to read from
Returns:
returns the next quoted string