Facemorph
Class Pyramid

java.lang.Object
  extended by Facemorph.Pyramid

public class Pyramid
extends java.lang.Object

A wavelet pyramid class for texture analysis / synthesis


Field Summary
 FloatImage[] horizontal
          The set of horizontally filtered images at different resolutions
 int levels
          The number of levels in this pyramid
 FloatImage smooth
          The low pass residual
 FloatImage[] vertical
          The set of vertically filtered images at different resolutions
 
Constructor Summary
Pyramid()
          Construct an empty Pyramid
Pyramid(int width, int height, int levels)
           
 
Method Summary
 boolean adaptAverage(Pyramid magPyr, boolean smooth)
          Multiplies this by the ratio of magPyr / variance(this)
 boolean adaptComplexAverage(Pyramid imag, Pyramid magPyr)
          Treats this as the real part and imag as the imaginary part and converts the values by multiplying by the ratio of complex magnitudes
 boolean adaptVariance(Pyramid varPyr, boolean smooth)
          Modifies this by multiplying by the ratio of varPyr over variance of this
 boolean add_to_average(Pyramid pyr, int n)
          Add pyr to this as part of constructing an average
 boolean add_to_variance(Pyramid pyr, int n)
          Adds pyr to this as part of estimating the average absolute value
 boolean add_to_varianceSquared(Pyramid pyr, int n)
          Adds pyr to this as part of estimating the variance squared
 void add(FloatImage image, int level)
           
 void add(Pyramid pyr, boolean applyToSmooth)
          Adds to the value of each subband of this Pyramid with the corresponding subband in the other Pyramid
 boolean addToComplexMagnitudeAverage(Pyramid real, Pyramid imag, int n)
          Adds real and image to this as part of making an average magnitude
 boolean addWeighted(Pyramid pyr, float w)
          Adds a weighted amount of pyr to this
 void build_pyramid(Filter H, Filter G, int levs)
          Build a Pyramid
 int calculateVariance(java.util.ArrayList<Pyramid> pyr, int count)
          Calculates the pixelwise variance of a set of Pyramids
 void collapse_pyramid(Filter H, Filter L1, Filter K1, Filter L2, Filter K2, int bm)
          Collapse the Pyramid
 void convolve(Filter H)
          Filter all subbands
 Pyramid copy(boolean copySmooth)
          Create a copy of this pyramid.
 void copy(Pyramid pyr)
          Copy the given pyramid into this, including the low pass residual
 void copy(Pyramid pyr, boolean copySmooth)
          Copy the given Pyramis into this
 boolean copySubband(Pyramid pyr, int lev)
          Copy a subband of the given pyramid
 double dotProduct(Pyramid pyr)
          Dot product, each level's contribution scaled up to match largest
 double dotProduct(Pyramid pyr, FloatImage mask)
          Dot product, each level's contribution scaled up to match largest
 void magnitude()
          Convert each subband into a rectified (magnitude) image
 void magnitudeSquared()
          Convert each subband into a rectified (magnitude squared) image
static void main(java.lang.String[] args)
          Main method used for testing
 int MRFTransform(Pyramid original, java.util.ArrayList<Pyramid> source, java.util.ArrayList<Pyramid> target, float min, float max, int bins, double[] coefs, boolean weighted)
          Pyramid based MRF transformation
 boolean read(java.lang.String fname)
          Read a binary format FloatImage from a file
static java.awt.Image readPPM(java.lang.String filename)
          Read a PPM image from the named file
 void scale(float dp)
          Multiplies the values in each subband by the value specified
 void setImage(FloatImage img)
          Set the low pass residual (at level 0) and delete the bandpass images
 void subtract(FloatImage image, int level)
           
 void subtract(Pyramid pyr, boolean applyToSmooth)
          Adds to the value of each subband of this Pyramid with the corresponding subband in the other Pyramid
 boolean transformTexture(Pyramid oldPyr, Pyramid source, Pyramid destination, float shift)
          Transform using the magnitude
 boolean transformTextureSquared(Pyramid oldPyr, Pyramid source, Pyramid destination, float shift)
          Performs a texture transform using the squared magnitude values.
 boolean write(java.io.File f)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

smooth

public FloatImage smooth
The low pass residual


horizontal

public FloatImage[] horizontal
The set of horizontally filtered images at different resolutions


vertical

public FloatImage[] vertical
The set of vertically filtered images at different resolutions


levels

public int levels
The number of levels in this pyramid

Constructor Detail

Pyramid

public Pyramid()
Construct an empty Pyramid


Pyramid

public Pyramid(int width,
               int height,
               int levels)
Method Detail

setImage

public void setImage(FloatImage img)
Set the low pass residual (at level 0) and delete the bandpass images

Parameters:
img - the image to set

copy

public void copy(Pyramid pyr,
                 boolean copySmooth)
Copy the given Pyramis into this

Parameters:
pyr - the Pyramid to copy
copySmooth - boolean indicating if the low pass residual should also be copied

copy

public void copy(Pyramid pyr)
Copy the given pyramid into this, including the low pass residual

Parameters:
pyr - the Pyramid to copy

copy

public Pyramid copy(boolean copySmooth)
Create a copy of this pyramid.

Parameters:
copySmooth - boolean indicating if the low pass residual should also be copied

copySubband

public boolean copySubband(Pyramid pyr,
                           int lev)
Copy a subband of the given pyramid

Parameters:
pyr - the pyramid to copy
lev - the subband to copy
Returns:
returns true if copied OK

build_pyramid

public void build_pyramid(Filter H,
                          Filter G,
                          int levs)
Build a Pyramid

Parameters:
H - the low-pass filter
G - the high pass filter
levs - the number of levels to build

collapse_pyramid

public void collapse_pyramid(Filter H,
                             Filter L1,
                             Filter K1,
                             Filter L2,
                             Filter K2,
                             int bm)
Collapse the Pyramid

Parameters:
H - the low-pass filter
L1 - the parallel even pixel filter
K1 - the orthogonal even pixel filter
L2 - the parallel odd pixel filter
K2 - the orthogonal odd pixel filter
bm - the border model to use in the parallel direction

magnitude

public void magnitude()
Convert each subband into a rectified (magnitude) image


magnitudeSquared

public void magnitudeSquared()
Convert each subband into a rectified (magnitude squared) image


add_to_variance

public boolean add_to_variance(Pyramid pyr,
                               int n)
Adds pyr to this as part of estimating the average absolute value

Parameters:
pyr - the pyramid to add
n - the number of pyramids that have been added previously
Returns:
returns true if all is OK

add_to_varianceSquared

public boolean add_to_varianceSquared(Pyramid pyr,
                                      int n)
Adds pyr to this as part of estimating the variance squared

Parameters:
pyr - the pyramid to add
n - the number of pyramids that have been added previously
Returns:
returns true if all OK

addToComplexMagnitudeAverage

public boolean addToComplexMagnitudeAverage(Pyramid real,
                                            Pyramid imag,
                                            int n)
Adds real and image to this as part of making an average magnitude

Parameters:
real - the real pyramid to add
imag - the imaginary pyramid to add
n - the number of pyramids that have been added previously
Returns:
returns true if all OK

add_to_average

public boolean add_to_average(Pyramid pyr,
                              int n)
Add pyr to this as part of constructing an average

Parameters:
pyr - the pyramid to add
n - the number of pyramids that have been added previously
Returns:
returns tru if all OK

addWeighted

public boolean addWeighted(Pyramid pyr,
                           float w)
Adds a weighted amount of pyr to this

Parameters:
pyr - the pyramid to add
w - the weight to use
Returns:
returns true is added successfully

convolve

public void convolve(Filter H)
Filter all subbands

Parameters:
H - the filter to use

adaptAverage

public boolean adaptAverage(Pyramid magPyr,
                            boolean smooth)
Multiplies this by the ratio of magPyr / variance(this)

Parameters:
magPyr - the desired variance
smooth - flag indicating if magPyr should be smoothed
Returns:
returns true if all OK

adaptVariance

public boolean adaptVariance(Pyramid varPyr,
                             boolean smooth)
Modifies this by multiplying by the ratio of varPyr over variance of this

Parameters:
varPyr - the desired variance
smooth - flag indicating if varPyr should be smoothed
Returns:
returns true if all OK

adaptComplexAverage

public boolean adaptComplexAverage(Pyramid imag,
                                   Pyramid magPyr)
Treats this as the real part and imag as the imaginary part and converts the values by multiplying by the ratio of complex magnitudes

Parameters:
imag - the imaginary components
magPyr - the target magnitude pyramid
Returns:
returns true if OK or flase on an error (e.g. different sized images)

transformTexture

public boolean transformTexture(Pyramid oldPyr,
                                Pyramid source,
                                Pyramid destination,
                                float shift)
Transform using the magnitude

Parameters:
oldPyr - the pyramid of the original (not-texture transformed) image
source - the pyramid of the source average
destination - the pyramid of the destination pyramid
shift - the amount to transform by
Returns:
returns true if transformed OK, or false on an error (e.g. different size images)

transformTextureSquared

public boolean transformTextureSquared(Pyramid oldPyr,
                                       Pyramid source,
                                       Pyramid destination,
                                       float shift)
Performs a texture transform using the squared magnitude values. The squared magnitude of oldPyr, source and destination are calculated within the method.

Parameters:
oldPyr - the Pyramid decomposition before the colour transform was applied
source - the source average pyramid
destination - the detination average pyramid
shift - the amount to transform by
Returns:
returns true if all is OK, or false otherwise (e.g. different size images)

calculateVariance

public int calculateVariance(java.util.ArrayList<Pyramid> pyr,
                             int count)
Calculates the pixelwise variance of a set of Pyramids

Parameters:
pyr - the set of pyramids
count - the number of pyramids
Returns:
returns 1

MRFTransform

public int MRFTransform(Pyramid original,
                        java.util.ArrayList<Pyramid> source,
                        java.util.ArrayList<Pyramid> target,
                        float min,
                        float max,
                        int bins,
                        double[] coefs,
                        boolean weighted)
Pyramid based MRF transformation

Parameters:
original - the original image pyramid
source - the (warped) source image pyramids
target - the (warped) target image pyramids
min - the minimum value to put in the histograms
max - the maximum value to hold in the histograms
bins - the number of bins
Returns:
returns 1

read

public boolean read(java.lang.String fname)
Read a binary format FloatImage from a file

Parameters:
fname - The name of the file to read
Returns:
True if the file was read successfully

write

public boolean write(java.io.File f)

dotProduct

public double dotProduct(Pyramid pyr)
Dot product, each level's contribution scaled up to match largest

Parameters:
pyr - the Pyramid to dot product with
Returns:
returns the dot product

dotProduct

public double dotProduct(Pyramid pyr,
                         FloatImage mask)
Dot product, each level's contribution scaled up to match largest

Parameters:
pyr - the Pyramid to dot product with
mask - the mask to use
Returns:
returns the dot product

scale

public void scale(float dp)
Multiplies the values in each subband by the value specified

Parameters:
dp - the scale factor

add

public void add(Pyramid pyr,
                boolean applyToSmooth)
Adds to the value of each subband of this Pyramid with the corresponding subband in the other Pyramid

Parameters:
pyr - The pyramid to add to this one.
applyToSmooth - IF true the apply the addition to the smoothed image as well

add

public void add(FloatImage image,
                int level)

subtract

public void subtract(Pyramid pyr,
                     boolean applyToSmooth)
Adds to the value of each subband of this Pyramid with the corresponding subband in the other Pyramid

Parameters:
pyr - The pyramid to add to this one.
applyToSmooth - IF true the apply the addition to the smoothed image as well

subtract

public void subtract(FloatImage image,
                     int level)

readPPM

public static java.awt.Image readPPM(java.lang.String filename)
Read a PPM image from the named file

Parameters:
filename - the name of the file to read from
Returns:
returns the specified image if available

main

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

Parameters:
args -