Facemorph
Class BSplineQuadTree

java.lang.Object
  extended by Facemorph.BSplineQuadTree

public class BSplineQuadTree
extends java.lang.Object

BSplineQuadTree performs 2D interpolation


Constructor Summary
BSplineQuadTree(double width, double height)
          Constructor for BSplineQuadTree of given width and height
 
Method Summary
 boolean addConstraint(int level, int kx, int ky, double xval, double yval)
          Add a constraint to level level of this interpolation tree
 void addToEstimate(int level, double x, double y, double u, double v, boolean warping)
          Adds the values u and v to the estimate at point x, y, i.e.
 void addToLinearEstimate(double x, double y, double u, double v)
          Adds to the linear (affine) constraints
 double[] bsplineinterp(double x, double y)
          Performs interpolation rather than warping, so the shift between levels is added not concatenated
 double[] bsplinewarp(double x, double y)
          Find the warp shift at point (x, y), values between levels are concatenated not added
 boolean bsplinewarp(double x, double y, double[] res, int lev)
          Find the warp shift at point (x,y)
 void calculateInterpConstraints(int maxLev, double[] xcoords, double[] ycoords, double[] ucoords, double[] vcoords)
          Calculate the interpolation function from the given constraints
 void calculateInterpConstraints(int maxLev, FloatImage mask, FloatImage xshift, FloatImage yshift)
          Calculate the interpolation with the constraints given as a set of FloatImages
 void calculateWarp(int levs, java.util.ArrayList<java.awt.geom.Point2D.Float> t1pts, java.util.ArrayList<java.awt.geom.Point2D.Float> t2pts)
          Calculates a warp from the constraints given
 void calculateWarp(int levs, Template t1, Template t2)
          Calculate a warp from the constraints given as two Templates
 void calculateWarpConstraints(int maxLev, double[] xcoords, double[] ycoords, double[] ucoords, double[] vcoords)
          Calculate the constraints for warp
 void calculateWarpConstraints(int maxLev, FloatImage mask, FloatImage xshift, FloatImage yshift)
          Calculate the warp with constraints specified in FloatImages
static void main(java.lang.String[] args)
          Main method is used for testing
 void paint(java.awt.Graphics g)
          Draws the interpolated function, mostly used for debugging
 double spline(double x)
          Calculates the cubic B-spline on interval x=[0.0,4.0]
 void updateConstraints(int level)
          Final step in setting the constraints
 void updateLinearConstraints()
          Final step in constructing the linear (affine) part of the warp/interpolation
 java.awt.image.BufferedImage warpImage(java.awt.image.BufferedImage bimg)
          Warps the image using this BSplineQuadTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BSplineQuadTree

public BSplineQuadTree(double width,
                       double height)
Constructor for BSplineQuadTree of given width and height

Parameters:
width - the width of the area to interpolate
height - the height of the area to interpolate
Method Detail

addConstraint

public boolean addConstraint(int level,
                             int kx,
                             int ky,
                             double xval,
                             double yval)
Add a constraint to level level of this interpolation tree

Parameters:
level - the max levels to go to in interpolating
kx - x coordinate of constraint
ky - y coordinate of constraint
xval - value of x shift
yval - value of y shift
Returns:
return true if the constraint is on a grid node at that level, or false otherwise

bsplinewarp

public double[] bsplinewarp(double x,
                            double y)
Find the warp shift at point (x, y), values between levels are concatenated not added

Parameters:
x - the x-coord to interpolate at
y - the y coord to interpolate at
Returns:
the x-y shift as a 2D array of double

bsplinewarp

public boolean bsplinewarp(double x,
                           double y,
                           double[] res,
                           int lev)
Find the warp shift at point (x,y)

Parameters:
x - the x-coord to interpolate at
y - the y coord to interpolate at
res - the result, should be a 2D array of double
lev - the level to interpolate at
Returns:
returns true if there are nodes down to lev, false otherwise

bsplineinterp

public double[] bsplineinterp(double x,
                              double y)
Performs interpolation rather than warping, so the shift between levels is added not concatenated

Parameters:
x - the x-coord to interpolated at
y - the y-coord to interpolate at
Returns:
returns the result as an array of double length 2

addToEstimate

public void addToEstimate(int level,
                          double x,
                          double y,
                          double u,
                          double v,
                          boolean warping)
Adds the values u and v to the estimate at point x, y, i.e. these are the original constraints

Parameters:
level - the level to add the estimate at
x - the x-coord to add it at
y - the y coord to add it at
u - the x value of the estimate
v - the y value of the estimate
warping - if true the position is shifted between levels to use concatentation, otherwise subtraction is used

addToLinearEstimate

public void addToLinearEstimate(double x,
                                double y,
                                double u,
                                double v)
Adds to the linear (affine) constraints

Parameters:
x - the x-coord of the constraint
y - the y-coord of the constraint
u - the x-value of the shift
v - the y-value of the shift

updateLinearConstraints

public void updateLinearConstraints()
Final step in constructing the linear (affine) part of the warp/interpolation


updateConstraints

public void updateConstraints(int level)
Final step in setting the constraints

Parameters:
level - the level to update

spline

public double spline(double x)
Calculates the cubic B-spline on interval x=[0.0,4.0]

Parameters:
x - the position to calculate the B-spline value at
Returns:
the value of the cubic B-spline

calculateInterpConstraints

public void calculateInterpConstraints(int maxLev,
                                       double[] xcoords,
                                       double[] ycoords,
                                       double[] ucoords,
                                       double[] vcoords)
Calculate the interpolation function from the given constraints

Parameters:
maxLev - the maximum number of levels to use in this B-spline approximation
xcoords - the x positions
ycoords - the y positions
ucoords - the x shifts
vcoords - the y shifts

calculateInterpConstraints

public void calculateInterpConstraints(int maxLev,
                                       FloatImage mask,
                                       FloatImage xshift,
                                       FloatImage yshift)
Calculate the interpolation with the constraints given as a set of FloatImages

Parameters:
maxLev - the maximum levels
mask - selection function to indicate which points to use
xshift - the shifts in the x -direction
yshift - the shifts in the y direction

calculateWarpConstraints

public void calculateWarpConstraints(int maxLev,
                                     double[] xcoords,
                                     double[] ycoords,
                                     double[] ucoords,
                                     double[] vcoords)
Calculate the constraints for warp

Parameters:
maxLev - maximum levels to use
xcoords - the x positions of the constraints
ycoords - the y positions of the constraints
ucoords - the xshifts
vcoords - the yshifts

calculateWarpConstraints

public void calculateWarpConstraints(int maxLev,
                                     FloatImage mask,
                                     FloatImage xshift,
                                     FloatImage yshift)
Calculate the warp with constraints specified in FloatImages

Parameters:
maxLev - the maximum number of levels to use
mask - the selection function for points to use
xshift - the shifts in the x direction
yshift - the shifts in the y direction

paint

public void paint(java.awt.Graphics g)
Draws the interpolated function, mostly used for debugging

Parameters:
g - the graphics to draw to

warpImage

public java.awt.image.BufferedImage warpImage(java.awt.image.BufferedImage bimg)
Warps the image using this BSplineQuadTree

Parameters:
bimg - The BufferedImage to warp
Returns:
returns the warped image

calculateWarp

public void calculateWarp(int levs,
                          java.util.ArrayList<java.awt.geom.Point2D.Float> t1pts,
                          java.util.ArrayList<java.awt.geom.Point2D.Float> t2pts)
Calculates a warp from the constraints given

Parameters:
levs - the number of levels to interpolate to
t1pts - the starting points
t2pts - the target points

calculateWarp

public void calculateWarp(int levs,
                          Template t1,
                          Template t2)
Calculate a warp from the constraints given as two Templates

Parameters:
levs - the number of levels to build the warp to
t1 - the start Template
t2 - the target Template

main

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

Parameters:
args - not used
Throws:
java.io.IOException