org.jscience.computing.ai.vision
Class ThresholdFilter

java.lang.Object
  extended by org.jscience.computing.ai.vision.Filter
      extended by org.jscience.computing.ai.vision.ThresholdFilter

public class ThresholdFilter
extends Filter

This class encapsulates a variety of thresholding algorithms. The current available thresholding algorithms are:


Field Summary
static int ERROR_DIFFUSION
          Error-diffusion thresholding.
static int ONE_POINT
          One-point thresholding.
static int PATTERN_DIFFUSION
          Pattern-diffusion thresholding.
protected  int thresholdLimit
          The threshold limit using by one-point thresholding.
protected  int thresholdMode
          The thresholding mode
static int TWO_POINT
          Two-point thresholding.
protected  int upperLimit
          The upper limit used in two-point thresholding.
 
Constructor Summary
ThresholdFilter()
          Creates a new instance of Threshold
ThresholdFilter(int threshold)
          Creates a new instances of Threshold, and sets the threshold limit
 
Method Summary
protected  java.awt.image.BufferedImage errorDiffusion(java.awt.image.BufferedImage image, java.awt.image.BufferedImage output)
          Performs error diffusion.
 java.awt.image.BufferedImage filter(java.awt.image.BufferedImage image, java.awt.image.BufferedImage output)
          Threshold the image according to the mode selected.
 int getThresholdLimit()
          Retrieve the thresholding limit for one- or two-point thresholding.
 int getThresholdMode()
          Return the threshold mode.
 int getUpperLimit()
          Retrieve the upper threshold limit for two-point thresholding.
protected  java.awt.image.BufferedImage onePoint(java.awt.image.BufferedImage image, java.awt.image.BufferedImage output, int thresholdLimit)
          Performs one-point thresholding.
protected  java.awt.image.BufferedImage patternDiffusion(java.awt.image.BufferedImage image, java.awt.image.BufferedImage output)
          Performs pattern diffusion on the input image.
 void setThresholdLimit(int limit)
          Sets the threshold limit used by one- or two-point thresholding.
 void setThresholdLimits(int threshold, int upper)
          Set the upper and lower threshold limits used in two-point thresholding.
 void setThresholdMode(int mode)
          Set the threshold mode.
 void setUpperLimit(int upper)
          Set the upper threshold limit for two-point thresholding.
 java.lang.String toString()
          DOCUMENT ME!
protected  java.awt.image.BufferedImage twoPoint(java.awt.image.BufferedImage image, java.awt.image.BufferedImage output, int lowerLimit, int upperLimit)
          Perform two-point thresholding on the input image.
 
Methods inherited from class org.jscience.computing.ai.vision.Filter
filter, verifyOutput, verifyOutput, verifyOutput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ONE_POINT

public static final int ONE_POINT
One-point thresholding. Any value below the limit is thresholded to black, anything above is thresholded to white.

See Also:
Constant Field Values

PATTERN_DIFFUSION

public static final int PATTERN_DIFFUSION
Pattern-diffusion thresholding. This uses a 4x4 dithering matrix to create a grouping of pixels that approximates the pixel group brightness.

See Also:
Constant Field Values

ERROR_DIFFUSION

public static final int ERROR_DIFFUSION
Error-diffusion thresholding. This uses Floyd-Steinberg's algorithm to keep a track of the error in brightness caused by the thresholding, and diffusing it across an area. This is the best thresholding algorithms for photographs and other complicated images.

See Also:
Constant Field Values

TWO_POINT

public static final int TWO_POINT
Two-point thresholding. Any image between the two threshold points is painted white, otherwise the pixel is painted black.

See Also:
Constant Field Values

thresholdMode

protected int thresholdMode
The thresholding mode


thresholdLimit

protected int thresholdLimit
The threshold limit using by one-point thresholding.

See Also:
ONE_POINT

upperLimit

protected int upperLimit
The upper limit used in two-point thresholding.

Constructor Detail

ThresholdFilter

public ThresholdFilter()
Creates a new instance of Threshold


ThresholdFilter

public ThresholdFilter(int threshold)
Creates a new instances of Threshold, and sets the threshold limit

Parameters:
threshold - the threshold limit
See Also:
setThresholdLimit(int)
Method Detail

setThresholdLimit

public void setThresholdLimit(int limit)
Sets the threshold limit used by one- or two-point thresholding. For one- point thresholding it is the primary threshold point. For two-point thresholding, it specifies the lower threshold limit.

Parameters:
limit - the threshold limit

getThresholdLimit

public int getThresholdLimit()
Retrieve the thresholding limit for one- or two-point thresholding. For one- point thresholding it is the primary threshold point. For two-point thresholding, it specifies the lower threshold limit.

Returns:
the current thresholding limit

setUpperLimit

public void setUpperLimit(int upper)
Set the upper threshold limit for two-point thresholding.

Parameters:
upper - the upper threshold limit.

getUpperLimit

public int getUpperLimit()
Retrieve the upper threshold limit for two-point thresholding.

Returns:
the upper limit used in two-point thresholding.

setThresholdLimits

public void setThresholdLimits(int threshold,
                               int upper)
Set the upper and lower threshold limits used in two-point thresholding.

Parameters:
threshold - the lower threshold limit.
upper - the upper threshold limit.

setThresholdMode

public void setThresholdMode(int mode)
Set the threshold mode.

Parameters:
mode - the threshold mode.

getThresholdMode

public int getThresholdMode()
Return the threshold mode.

Returns:
the threshold mode.

filter

public java.awt.image.BufferedImage filter(java.awt.image.BufferedImage image,
                                           java.awt.image.BufferedImage output)
Threshold the image according to the mode selected.

Specified by:
filter in class Filter
Parameters:
image - the input image.
output - the output image (optional).
Returns:
the output image.
See Also:
Filter.verifyOutput(BufferedImage,BufferedImage)

patternDiffusion

protected java.awt.image.BufferedImage patternDiffusion(java.awt.image.BufferedImage image,
                                                        java.awt.image.BufferedImage output)
Performs pattern diffusion on the input image.

Parameters:
image - the input image.
output - the output image.
Returns:
the output image.

onePoint

protected java.awt.image.BufferedImage onePoint(java.awt.image.BufferedImage image,
                                                java.awt.image.BufferedImage output,
                                                int thresholdLimit)
Performs one-point thresholding.

Parameters:
image - the input image.
output - the output image.
thresholdLimit - the threshold limit.
Returns:
the output image.

twoPoint

protected java.awt.image.BufferedImage twoPoint(java.awt.image.BufferedImage image,
                                                java.awt.image.BufferedImage output,
                                                int lowerLimit,
                                                int upperLimit)
Perform two-point thresholding on the input image. This method is called within filter, which passes the lower and upper limits specified in setThresholdLimits.

Parameters:
image - the input image.
output - the output image.
lowerLimit - the lower limit.
upperLimit - the upper limit.
Returns:
the thresholded image.
See Also:
setThresholdLimits(int,int)

errorDiffusion

protected java.awt.image.BufferedImage errorDiffusion(java.awt.image.BufferedImage image,
                                                      java.awt.image.BufferedImage output)
Performs error diffusion.

Parameters:
image - the input image.
output - the output image.
Returns:
the output image.

toString

public java.lang.String toString()
DOCUMENT ME!

Overrides:
toString in class java.lang.Object
Returns:
DOCUMENT ME!