diva.sketch.features
Class CornerFE

java.lang.Object
  extended by diva.sketch.features.CornerFE
All Implemented Interfaces:
FeatureExtractor

public class CornerFE
extends Object
implements FeatureExtractor

CornerFE computes the number of corners in a stroke by enumerating over the data points in the stroke. For every three points, it computes the angle formed by two vectors. If the dot product of the two neighboring vectors is less than 0.6 (empirical value), a cusp is detected. Then the magnitudes of the two vectors are calculated. If both of the vector magnitudes divided by the total path length are less than a threshold value (20%), then this is not really a corner. Otherwise it is likely to be a corner.

Version:
$Revision: 1.13 $
Author:
Heloise Hse (hwawen@eecs.berkeley.edu)

Field Summary
static double DEFAULT_THRESH_DOT
          The default dot product value for determining whether two vectors form a corner.
static double DEFAULT_THRESH_MAG_RATIO
          The default threshold ratio of a segment length to the entire path length of the stroke.
static double DEFAULT_THRESH_RELAXED_DOT
          If the dot product of two vectors is greater than DEFAULT_THRESH_DOT but less than this parameter (DEFAULT_THRESH_RELAXED_DOT), we identify this to be a likely corner, and more checkings are performed on the two vectors to verify.
static String PROPERTY_KEY
          The key to access the cached corner property.
 
Constructor Summary
CornerFE()
          Create a CornerFE with default parameters.
CornerFE(double magThresh, double dotThresh, double dotRelaxThresh)
          Create a CornerFE with the specified parameters.
 
Method Summary
 double apply(TimedStroke s)
          Return the number of corners in the specified stroke.
static int[] cornerIndices(TimedStroke s)
          Return the indices where the corners occur in the given stroke.
static int[] cornerIndices(TimedStroke s, double threshMagRatio, double threshDot, double threshRelaxedDot)
          Return the indices where the corners occur in the given stroke.
 String getName()
          Return the name of this feature extractor.
static int numCorners(TimedStroke s)
          Return the number of corners in the given stroke.
static int numCorners(TimedStroke s, double threshMagRatio, double threshDot, double threshRelaxedDot)
          Return the number of corners in the given stroke.
 void setDotThreshold(double val)
          Set the dot product threshold for determining whether two vectors form a corner.
 void setMagRatioThreshold(double val)
          Set the magnitude ratio threshold.
 void setRelaxedDotThreshold(double val)
          If the dot product of two vectors is greater than _threshDot but less than this parameter (_threshRelaxedDot), we identify this to be a likely corner, and more checkings are performed on the two vectors to verify.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_KEY

public static final String PROPERTY_KEY
The key to access the cached corner property.

See Also:
Constant Field Values

DEFAULT_THRESH_MAG_RATIO

public static final double DEFAULT_THRESH_MAG_RATIO
The default threshold ratio of a segment length to the entire path length of the stroke.

See Also:
Constant Field Values

DEFAULT_THRESH_DOT

public static final double DEFAULT_THRESH_DOT
The default dot product value for determining whether two vectors form a corner. If the dot product of two vectors is less than this value, there is definitely a corner.

See Also:
Constant Field Values

DEFAULT_THRESH_RELAXED_DOT

public static final double DEFAULT_THRESH_RELAXED_DOT
If the dot product of two vectors is greater than DEFAULT_THRESH_DOT but less than this parameter (DEFAULT_THRESH_RELAXED_DOT), we identify this to be a likely corner, and more checkings are performed on the two vectors to verify. See numCorners for more details.

See Also:
Constant Field Values
Constructor Detail

CornerFE

public CornerFE()
Create a CornerFE with default parameters. The default value for vector dot product is 0.3, the relaxed dot product is 0.6, and the ratio of magnitude is 0.2 (20%). See numCorners for more detail on how these parameters are being used.


CornerFE

public CornerFE(double magThresh,
                double dotThresh,
                double dotRelaxThresh)
Create a CornerFE with the specified parameters.

Method Detail

apply

public double apply(TimedStroke s)
Return the number of corners in the specified stroke. This calls numCorners with threshold values either initialized in the constructor or specified by the user.

First check to see if this feature already exists in the stroke's property table (access using PROPERTY_KEY). If so, return that value (cast to double). Otherwise call numCorners to compute and cache the result in the table.

Specified by:
apply in interface FeatureExtractor

cornerIndices

public static final int[] cornerIndices(TimedStroke s)
Return the indices where the corners occur in the given stroke. Return null if no corners exist in the stroke. This methods makes a call to cornerIndices with default threshold values.


cornerIndices

public static final int[] cornerIndices(TimedStroke s,
                                        double threshMagRatio,
                                        double threshDot,
                                        double threshRelaxedDot)
Return the indices where the corners occur in the given stroke. Return null if no corners exist in the stroke. Iterate over the points in the stroke, for every three points (p1, p2, p3) we form two vectors, (p1,p2) and (p2, p3). If the dot product of these two vectors is less than threshDot, then there is definitely an angle at p2. If the dot product is greater than threshDot but less than threshRelaxedDot, it is likely that there is an angle at p2, but we're not sure. In this case, the magnitudes of both vectors are calculated, m1 and m2. Let 'plen' be the stroke path length, we calculate r1 = m1/plen and r2 = m2/plen. If either r1 or r2 is greater than threshMagRatio, then we say that there is a corner. If both vectors are really short (r1

getName

public String getName()
Return the name of this feature extractor.

Specified by:
getName in interface FeatureExtractor

numCorners

public static final int numCorners(TimedStroke s)
Return the number of corners in the given stroke. This method calls numCorners with default threshold values.


numCorners

public static final int numCorners(TimedStroke s,
                                   double threshMagRatio,
                                   double threshDot,
                                   double threshRelaxedDot)
Return the number of corners in the given stroke. This method calls cornerIndices.


setDotThreshold

public void setDotThreshold(double val)
Set the dot product threshold for determining whether two vectors form a corner. If the dot product of two vectors is less than this value, there is definitely a corner.


setMagRatioThreshold

public void setMagRatioThreshold(double val)
Set the magnitude ratio threshold. The default threshold ratio of a segment length to the entire path length of the stroke.


setRelaxedDotThreshold

public void setRelaxedDotThreshold(double val)
If the dot product of two vectors is greater than _threshDot but less than this parameter (_threshRelaxedDot), we identify this to be a likely corner, and more checkings are performed on the two vectors to verify. See numCorners for more details.



Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.