Facemorph
Class Mask

java.lang.Object
  extended by Facemorph.Mask
All Implemented Interfaces:
MaskInterface, java.lang.Cloneable

public class Mask
extends java.lang.Object
implements MaskInterface

Defines a mask file (a list of which contours to follow in a Template and in which directions).


Field Summary
static int CONTOUR_FORWARD
          Indicates a line goes in the direction of points
static int CONTOUR_REVERSE
          Indicates a line goes in the opposite direction to the points
static java.awt.Color maskColour
           
static int POINT
          indicates a point, not a line
 
Constructor Summary
Mask()
          Creates a new instance of Mask
 
Method Summary
 void add(int index, int dir)
          Adds a contour or point to this mask
 Mask clone()
          Creates and returns a copy of this object.
 void delete(int index)
          Delete a contour from this mask
 FloatImage getAsFloatImage(Template tem, int w, int h, float min, float max)
          Constructs a FloatImage with values of 0 (masked) and max (not masked)
static FloatImage getAsFloatImage(Template tem, java.util.Vector<java.lang.Integer> maskDirections, java.util.Vector<java.lang.Integer> maskConts, int w, int h, float min, float max)
           
 double getBlur()
          Gets the size of the Gaussian (or implementation specific) blur to apply to the mask
 java.util.Vector<java.lang.Integer> getContours()
          Get the list of contours for this mask
 java.util.Vector<java.lang.Integer> getDirections()
          Get the list of directions for this mask
 javax.swing.filechooser.FileNameExtensionFilter getExt()
           
 java.awt.Polygon getMask(Template tem, int xoff, int yoff, float zoom)
          Constructs a masking polygon from this Template and MaskInterface
 FloatImage maskImage(FloatImage img, Template tem, java.awt.Color col, boolean reverse)
          Masks an image using the mask object specified/
 java.awt.Image maskImage(java.awt.Image img, Template tem, java.awt.Color col, boolean reverse)
          Masks an image using the mask object specified/
 void paint(Template tem, java.awt.Graphics g, java.awt.Color col, int xoff, int yoff, int width, int height, float zoom)
          Paint the mask using the supplied Graphics component
 void paint(Template tem, java.awt.Graphics g, java.awt.Color col, int xoff, int yoff, int width, int height, float zoom, boolean invert)
          Paint the mask using the supplied Graphics component, with option to invert the mask
 void read(java.io.File file)
          Reads a mask from a file
 void read(java.io.Reader r)
          Reads a mask from a Reader (e.g.
 void read(java.lang.String file)
          Reads a mask from a file
 void setBlur(double blurLevel)
          Sets the size of the Gaussian (or implementation specific) blur to apply to the mask The size specified as multiple applications of a Gaussian blur function
 void write(java.io.File f)
          Writes the mask to a file
 void write(java.io.PrintWriter pw)
          Writes the mask to a PrintWriter
 void write(java.lang.String fname)
          Writes the mask to a file
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maskColour

public static final java.awt.Color maskColour

CONTOUR_FORWARD

public static final int CONTOUR_FORWARD
Indicates a line goes in the direction of points

See Also:
Constant Field Values

CONTOUR_REVERSE

public static final int CONTOUR_REVERSE
Indicates a line goes in the opposite direction to the points

See Also:
Constant Field Values

POINT

public static final int POINT
indicates a point, not a line

See Also:
Constant Field Values
Constructor Detail

Mask

public Mask()
Creates a new instance of Mask

Method Detail

clone

public Mask clone()
Description copied from interface: MaskInterface
Creates and returns a copy of this object.

Specified by:
clone in interface MaskInterface
Overrides:
clone in class java.lang.Object

read

public void read(java.lang.String file)
          throws java.io.FileNotFoundException,
                 java.io.IOException
Reads a mask from a file

Parameters:
file - The name of the mask file
Throws:
java.io.FileNotFoundException - thrown if file not found
java.io.IOException - thrown if some other I/O error

read

public void read(java.io.File file)
          throws java.io.FileNotFoundException,
                 java.io.IOException
Reads a mask from a file

Specified by:
read in interface MaskInterface
Parameters:
file - The name of the mask file
Throws:
java.io.FileNotFoundException - thrown if file not found
java.io.IOException - thrown if some other I/O error

read

public void read(java.io.Reader r)
          throws java.io.IOException
Reads a mask from a Reader (e.g. InputStreamReader or FileReader)

Parameters:
r - The Reader to read from
Throws:
java.io.IOException - if an IOException occurs

write

public void write(java.lang.String fname)
           throws java.io.IOException
Writes the mask to a file

Parameters:
fname - the name of the file to write to
Throws:
java.io.IOException

write

public void write(java.io.File f)
           throws java.io.IOException
Writes the mask to a file

Specified by:
write in interface MaskInterface
Parameters:
f - the file to write to
Throws:
java.io.IOException

write

public void write(java.io.PrintWriter pw)
Writes the mask to a PrintWriter

Parameters:
pw - the PrintWriter to write to

getContours

public java.util.Vector<java.lang.Integer> getContours()
Get the list of contours for this mask

Returns:
The list of contours

getDirections

public java.util.Vector<java.lang.Integer> getDirections()
Get the list of directions for this mask

Returns:
The list of contour directions

add

public void add(int index,
                int dir)
Adds a contour or point to this mask

Parameters:
index - the index of the contour or point to add
dir - the direction the contour should be followed or point CONTOUR_FORWARD, CONTOUR_REVERSE or POINT

delete

public void delete(int index)
Delete a contour from this mask

Parameters:
index - the index of the contour to remove

getAsFloatImage

public FloatImage getAsFloatImage(Template tem,
                                  int w,
                                  int h,
                                  float min,
                                  float max)
Description copied from interface: MaskInterface
Constructs a FloatImage with values of 0 (masked) and max (not masked)

Specified by:
getAsFloatImage in interface MaskInterface
Parameters:
tem - the template to apply the mask to
w - The width of the output mask image
h - The height of the output mask image
min - The values to draw outside the masked regions
max - The values to draw in the masked regions
Returns:
The mask as a FloatImage, this allows it to be smoothed for softer edges

getAsFloatImage

public static FloatImage getAsFloatImage(Template tem,
                                         java.util.Vector<java.lang.Integer> maskDirections,
                                         java.util.Vector<java.lang.Integer> maskConts,
                                         int w,
                                         int h,
                                         float min,
                                         float max)

getMask

public java.awt.Polygon getMask(Template tem,
                                int xoff,
                                int yoff,
                                float zoom)
Constructs a masking polygon from this Template and MaskInterface

Parameters:
tem - The template defining the lines to use in this mask
xoff - the x-offset
yoff - the y-offset
zoom - the zoom
Returns:
Return the masking polygon

maskImage

public java.awt.Image maskImage(java.awt.Image img,
                                Template tem,
                                java.awt.Color col,
                                boolean reverse)
Masks an image using the mask object specified/

Specified by:
maskImage in interface MaskInterface
Parameters:
img - The image to mask
tem - The template to use
col - The colour to draw in the masked regions
reverse - If true draw outside the polygon defined by the mask, otherwise draw inside
Returns:
return the masked image, the original is unmodified

maskImage

public FloatImage maskImage(FloatImage img,
                            Template tem,
                            java.awt.Color col,
                            boolean reverse)
Masks an image using the mask object specified/

Specified by:
maskImage in interface MaskInterface
Parameters:
img - The image to mask
tem - The template to use
col - The colour to draw in the masked regions
reverse - If true draw outside the polygon defined by the mask, otherwise draw inside
Returns:
return the masked image, the original is unmodified

paint

public void paint(Template tem,
                  java.awt.Graphics g,
                  java.awt.Color col,
                  int xoff,
                  int yoff,
                  int width,
                  int height,
                  float zoom)
Paint the mask using the supplied Graphics component

Specified by:
paint in interface MaskInterface
Parameters:
tem - Template to form mask around
g - Graphics object to paint onto
col - Colour to paint the mask
xoff - the x-offset
yoff - the y-offset
zoom - the zoom

paint

public void paint(Template tem,
                  java.awt.Graphics g,
                  java.awt.Color col,
                  int xoff,
                  int yoff,
                  int width,
                  int height,
                  float zoom,
                  boolean invert)
Description copied from interface: MaskInterface
Paint the mask using the supplied Graphics component, with option to invert the mask

Specified by:
paint in interface MaskInterface
Parameters:
tem - Template to form mask around
g - Graphics object to paint onto
col - Colour to paint the mask
xoff - the x-offset
yoff - the y-offset
zoom - the zoom
invert - will invert the mask if true.

getExt

public javax.swing.filechooser.FileNameExtensionFilter getExt()
Specified by:
getExt in interface MaskInterface
Returns:
the file extensions appropriate for this type of mask

setBlur

public void setBlur(double blurLevel)
Description copied from interface: MaskInterface
Sets the size of the Gaussian (or implementation specific) blur to apply to the mask The size specified as multiple applications of a Gaussian blur function

Specified by:
setBlur in interface MaskInterface

getBlur

public double getBlur()
Description copied from interface: MaskInterface
Gets the size of the Gaussian (or implementation specific) blur to apply to the mask

Specified by:
getBlur in interface MaskInterface
Returns: