Facemorph
Class Warp

java.lang.Object
  extended by Facemorph.Warp
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
LinearWarp, MultiscaleWarp, MultiscaleWarpRB, TPSWarp

public abstract class Warp
extends java.lang.Object
implements java.io.Serializable

Base warping class

See Also:
Serialized Form

Field Summary
 int height
          The height of the warping function
static int LINEAR
          Linear warp constant
static int MULTISCALE
          Multiscale (affine) warp constant
static int MULTISCALERB
          Multiscale (rigid body)warp constant
static int TPS
          Thin plate spline warp constant
 int width
          The width of the warping function
 float[] xshift
          The array of xshifts
 float[] yshift
          The array of y-shifts
 
Constructor Summary
Warp()
          Construct an empty warp
 
Method Summary
 void concatenate(Warp warp)
          Concatenates warp with this
 void concatenate(Warp warp1, Warp warp2)
          Concatenates the two warps and puts the result in this
 void convert(FloatImage Wx, FloatImage Wy)
          Converts this warp into the two FloatImages
static Warp createWarp(int type, int w, int h, int ow, int oh, boolean r)
          Factory method for creating a warp of the specified type
 float[] get(int x, int y)
          Gets the value of this warp at (x,y)
 int getHeight()
          Gets the height of this warp
 int getWidth()
          Gets the width of this warp
abstract  boolean interpolate(int n, java.awt.geom.Point2D.Float[] source, java.awt.geom.Point2D.Float[] dest, boolean borders)
          Method to interpolate the warping function
 boolean interpolate(int n, java.awt.geom.Point2D.Float[] source, java.awt.geom.Point2D.Float[] dest, boolean borders, boolean overlap)
          Interpolates the given 2D values across the 2D space, by performing setup then calling interpolate()
 boolean interpolate(Template tmp1, Template tmp2, boolean sample, boolean borders)
          Interpolate this warping function from tmp1 to tmp2
 boolean interpolate(Template tmp1, Template tmp2, boolean sample, boolean borders, boolean overlap)
          Interpolate this warping function from tmp1 to tmp2
 int iterate(int n, java.awt.geom.Point2D.Float[] source, java.awt.geom.Point2D.Float[] dest, Warp tmp, float minJ, boolean borders)
          Implements an overlap control algorithm
 float overlap(float minJ)
          Calculates the scaling parameter to ensure the Jacobean >= minJ and applies (if less than 1) it to this warp
 void reconvert(FloatImage Wx, FloatImage Wy)
          Converts the warp sepcified as two float images into this
 float[] sample(float x, float y)
          Samples this warp at non-intege pixels using bi-linear interpolation
static java.awt.Color sample(int[] pix, int width, int height, float x, float y)
          Sample from a non-integer point in an image (as an int array) using linear interpolated sampling
 void scaleWarp(float scaleFactor)
          Scales a warp by the amount specified
 void set(int x, int y, float X, float Y)
          Sets the value of this warp at the specified point
 int stripPoints(java.awt.geom.Point2D.Float[] source, java.awt.geom.Point2D.Float[] dest, java.awt.geom.Point2D.Float[] newSource, java.awt.geom.Point2D.Float[] newDest, int n, int w1, int h1, int w2, int h2)
          Removes points from both lists that are outside the image borders of their respective images
 FloatImage warpFloatImage(FloatImage fimg)
          Warp a FloatImage using this warping function
 java.awt.image.BufferedImage warpImage(java.awt.image.BufferedImage img)
          Warp an image using this warping function
 java.awt.Image warpImage(java.awt.Image img, java.awt.image.ImageObserver ob)
          Warp an image using this warping function
 int[] warpImage(java.awt.Image img, int twidth, int theight)
          Warp an image using this warping function
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xshift

public float[] xshift
The array of xshifts


yshift

public float[] yshift
The array of y-shifts


width

public int width
The width of the warping function


height

public int height
The height of the warping function


MULTISCALE

public static final int MULTISCALE
Multiscale (affine) warp constant

See Also:
Constant Field Values

LINEAR

public static final int LINEAR
Linear warp constant

See Also:
Constant Field Values

TPS

public static final int TPS
Thin plate spline warp constant

See Also:
Constant Field Values

MULTISCALERB

public static final int MULTISCALERB
Multiscale (rigid body)warp constant

See Also:
Constant Field Values
Constructor Detail

Warp

public Warp()
Construct an empty warp

Method Detail

createWarp

public static Warp createWarp(int type,
                              int w,
                              int h,
                              int ow,
                              int oh,
                              boolean r)
Factory method for creating a warp of the specified type

Parameters:
type - the type of warp to make, one of MULTISCALE, LINEAR, TPS or MULTISCALERB
w - the output width
h - the output height
ow - the input width
oh - the input height
r - indicates reverse of the triangulation (i.e. triangulate the output not the input)
Returns:
returns the warp of the requested type

interpolate

public boolean interpolate(int n,
                           java.awt.geom.Point2D.Float[] source,
                           java.awt.geom.Point2D.Float[] dest,
                           boolean borders,
                           boolean overlap)
Interpolates the given 2D values across the 2D space, by performing setup then calling interpolate()

Parameters:
n - The number of constraints to interpolate
source - The array of start points
dest - The array of end points
borders - Specifies whether to fix the points on the borders
overlap - indicates that overlap control should be used
Returns:
true of the interpolation was successful, false otherwise

interpolate

public boolean interpolate(Template tmp1,
                           Template tmp2,
                           boolean sample,
                           boolean borders,
                           boolean overlap)
Interpolate this warping function from tmp1 to tmp2

Parameters:
tmp1 - Source template
tmp2 - target template
sample - should the contour samples be used, or just the control points
borders - Should we pin the border down
overlap - indicates that overlap control should be used
Returns:
true if interpolation successful

getWidth

public int getWidth()
Gets the width of this warp

Returns:
The width

getHeight

public int getHeight()
Gets the height of this warp

Returns:
The height

get

public float[] get(int x,
                   int y)
Gets the value of this warp at (x,y)

Parameters:
x - The x-coord
y - The y-coord
Returns:
The value at (x,y)

set

public void set(int x,
                int y,
                float X,
                float Y)
Sets the value of this warp at the specified point

Parameters:
x - The x-coord
y - The y-coord
X - The X value
Y - The Y value

interpolate

public abstract boolean interpolate(int n,
                                    java.awt.geom.Point2D.Float[] source,
                                    java.awt.geom.Point2D.Float[] dest,
                                    boolean borders)
Method to interpolate the warping function

Parameters:
n - The number of constraints
source - The start points
dest - The target points
borders - if true fix the borders
Returns:
true if the interpolation was successful

interpolate

public boolean interpolate(Template tmp1,
                           Template tmp2,
                           boolean sample,
                           boolean borders)
Interpolate this warping function from tmp1 to tmp2

Parameters:
tmp1 - Source template
tmp2 - target template
sample - should the contour samples be used, or just the control points
borders - Should we pin the border down
Returns:
true if interpolation successful

stripPoints

public int stripPoints(java.awt.geom.Point2D.Float[] source,
                       java.awt.geom.Point2D.Float[] dest,
                       java.awt.geom.Point2D.Float[] newSource,
                       java.awt.geom.Point2D.Float[] newDest,
                       int n,
                       int w1,
                       int h1,
                       int w2,
                       int h2)
Removes points from both lists that are outside the image borders of their respective images

Parameters:
source - List of source points
dest - List of destination points
newSource - output source point list
newDest - output de3stination point list
n - the number of input points
w1 - he width of image 1
h1 - The height of image 1
w2 - The width of image 2
h2 - The height of image 2
Returns:
The number of points in the stripped set

sample

public static java.awt.Color sample(int[] pix,
                                    int width,
                                    int height,
                                    float x,
                                    float y)
Sample from a non-integer point in an image (as an int array) using linear interpolated sampling

Parameters:
pix - An array of the images pixels as RGB ints
width - The width of the image
height - The height of theimage
x - The x-coord of the sample point
y - Te y-coord of the sample point
Returns:
The sampled colour

sample

public float[] sample(float x,
                      float y)
Samples this warp at non-intege pixels using bi-linear interpolation

Parameters:
x - the x-coord to sample
y - the y-coord to sample
Returns:
the target of the warping function as an (x,y) pair

warpImage

public int[] warpImage(java.awt.Image img,
                       int twidth,
                       int theight)
Warp an image using this warping function

Parameters:
img - The image to warp
twidth - The width of the input image
theight - The height of the input image
Returns:
The warped image as an array of RGB int values

warpImage

public java.awt.Image warpImage(java.awt.Image img,
                                java.awt.image.ImageObserver ob)
Warp an image using this warping function

Parameters:
img - The image to warp
ob - An image observer object
Returns:
The warped image

warpImage

public java.awt.image.BufferedImage warpImage(java.awt.image.BufferedImage img)
Warp an image using this warping function

Parameters:
img - The image to warp
Returns:
The warped image

warpFloatImage

public FloatImage warpFloatImage(FloatImage fimg)
Warp a FloatImage using this warping function

Parameters:
fimg - The image to warp
Returns:
The warped image

concatenate

public void concatenate(Warp warp)
Concatenates warp with this

Parameters:
warp - the warp to concatenate

concatenate

public void concatenate(Warp warp1,
                        Warp warp2)
Concatenates the two warps and puts the result in this

Parameters:
warp1 - the first warp
warp2 - the second warp

convert

public void convert(FloatImage Wx,
                    FloatImage Wy)
Converts this warp into the two FloatImages

Parameters:
Wx - the output x shifts
Wy - the output y shifts

reconvert

public void reconvert(FloatImage Wx,
                      FloatImage Wy)
Converts the warp sepcified as two float images into this

Parameters:
Wx - warp x-component
Wy - warp y component

iterate

public int iterate(int n,
                   java.awt.geom.Point2D.Float[] source,
                   java.awt.geom.Point2D.Float[] dest,
                   Warp tmp,
                   float minJ,
                   boolean borders)
Implements an overlap control algorithm

Parameters:
n - number of points
source - source points
dest - target points
tmp - tempory warp workspace
minJ - minimum allowed value of the Jacobean in any partial warp
borders - indicates if borders should be pinned down
Returns:
returns 1

overlap

public float overlap(float minJ)
Calculates the scaling parameter to ensure the Jacobean >= minJ and applies (if less than 1) it to this warp

Parameters:
minJ - the minimum allowed value of the Jacobean
Returns:
returns the scaling value

scaleWarp

public void scaleWarp(float scaleFactor)
Scales a warp by the amount specified

Parameters:
scaleFactor - the scale factor to apply to this warp