com.pearsoneduc.ip.op
Class BinaryStructElement

java.lang.Object
  |
  +--com.pearsoneduc.ip.op.StructElement
        |
        +--com.pearsoneduc.ip.op.BinaryStructElement

public class BinaryStructElement
extends StructElement
implements java.lang.Cloneable, StructElementTypes

A structuring element for the morphological processing of binary images.

Version:
1.1 [1999/08/30]
Author:
Nick Efford

Fields inherited from class com.pearsoneduc.ip.op.StructElement
height, origin, pixel, width
 
Constructor Summary
BinaryStructElement()
          Creates a 3x3 square SE.
BinaryStructElement(int type)
          Creates an instance of a standard BinaryStructElement, one of the types defined in the MorphologicalConstants interface.
BinaryStructElement(int w, int h)
          Creates an instance of a BinaryStructElement with the specified dimensions.
BinaryStructElement(int w, int h, java.awt.Point p)
          Creates an instance of a BinaryStructElement with the specified dimensions and origin.
BinaryStructElement(java.io.Reader source)
          Creates an instance of a BinaryStructElement by reading data.
 
Method Summary
 void clearPixel(int x, int y)
          Clears a pixel in the structuring element (i.e., gives it a value of 0).
 java.lang.Object clone()
           
 boolean equals(java.lang.Object obj)
          Tests for equality with another BinaryStructElement.
 boolean fits(java.awt.image.Raster raster, int x, int y)
          Tests whether the SE fits within an image at the specified coordinates.
 boolean fitsComplement(java.awt.image.Raster raster, int x, int y)
          Tests whether the SE fits within the complement of an image at the specified coordinates.
 BinaryStructElement getRotatedVersion()
           
 boolean hits(java.awt.image.Raster raster, int x, int y)
          Tests whether the SE hits an image when it is placed at the specified coordinates.
 void setPixel(int x, int y)
          Sets a pixel in the structuring element to 1.
 void setPixels()
          Sets all pixels of the SE to 1.
 void setPixels(int[] value)
          Copies values from a one-dimensional array into the SE.
 void setPixels(int[][] value)
          Copies values from a two-dimensional array into the SE.
 void setPixels(java.lang.String valueString)
          Copies values from a String into the SE.
 void write(java.io.Writer destination)
          Writes SE data, including a header, to the specified destination.
 void writePixels(java.io.Writer destination)
          Writes SE pixel values to the specified destination.
 
Methods inherited from class com.pearsoneduc.ip.op.StructElement
getHeight, getOrigin, getPixel, getWidth, readInt, setOrigin, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BinaryStructElement

public BinaryStructElement()
                    throws StructElementException
Creates a 3x3 square SE.

BinaryStructElement

public BinaryStructElement(int w,
                           int h)
                    throws StructElementException
Creates an instance of a BinaryStructElement with the specified dimensions. All its pixels will be set to 1.
Parameters:
w - desired SE width (greater than 0)
h - desired SE height (greater than 0)
Throws:
StructElementException - if dimensions are invalid.

BinaryStructElement

public BinaryStructElement(int w,
                           int h,
                           java.awt.Point p)
                    throws StructElementException
Creates an instance of a BinaryStructElement with the specified dimensions and origin. All its pixels will be set to 1.
Parameters:
w - desired SE width (greater than 0)
h - desired SE height (greater than 0)
p - java.awt.Point object representing origin of SE
Throws:
StructElementException - if dimensions are invalid.

BinaryStructElement

public BinaryStructElement(int type)
                    throws StructElementException
Creates an instance of a standard BinaryStructElement, one of the types defined in the MorphologicalConstants interface.
Parameters:
type - integer specifying SE type
Throws:
StructElementException - if an invalid type parameter has been specified.
See Also:
StructElementTypes

BinaryStructElement

public BinaryStructElement(java.io.Reader source)
                    throws java.io.IOException,
                           StructElementException
Creates an instance of a BinaryStructElement by reading data.
Parameters:
source - Reader representing source of SE data
Throws:
java.io.IOException - if there was an I/O error.
StructElementException - if the data do not conform to the required format or the dimensions, origin or SE values are not valid.
Method Detail

clone

public java.lang.Object clone()
Returns:
a copy of this BinaryStructElement.
Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Tests for equality with another BinaryStructElement.
Parameters:
obj - a BinaryStructElement object
Returns:
true if the SEs are equal, false otherwise.
Overrides:
equals in class StructElement

setPixel

public void setPixel(int x,
                     int y)
Sets a pixel in the structuring element to 1.
Parameters:
x - x coordinate of SE pixel
y - y coordinate of SE pixel

clearPixel

public void clearPixel(int x,
                       int y)
Clears a pixel in the structuring element (i.e., gives it a value of 0).
Parameters:
x - x coordinate of SE pixel
y - y coordinate of SE pixel

setPixels

public void setPixels()
Sets all pixels of the SE to 1.

setPixels

public void setPixels(int[] value)
               throws StructElementException
Copies values from a one-dimensional array into the SE.
Parameters:
value - array of values to be copied into SE
Throws:
StructElementException - if array is too small or if any of the values is neither 1 nor 0.
Overrides:
setPixels in class StructElement

setPixels

public void setPixels(int[][] value)
               throws StructElementException
Copies values from a two-dimensional array into the SE.
Parameters:
value - array of values (1 or 0) to be copied into SE
Throws:
StructElementException - if array dimensions are too small or if any of the values is neither 1 nor 0.
Overrides:
setPixels in class StructElement

setPixels

public void setPixels(java.lang.String valueString)
               throws StructElementException
Copies values from a String into the SE.
Parameters:
valueString - String of ones and zeroes to be copied into SE
Throws:
StructElementException - if any of the values is neither 1 nor 0.
Overrides:
setPixels in class StructElement

writePixels

public void writePixels(java.io.Writer destination)
Writes SE pixel values to the specified destination.
Parameters:
destination - Writer acting as destination for the SE data
Overrides:
writePixels in class StructElement

write

public void write(java.io.Writer destination)
           throws java.io.IOException
Writes SE data, including a header, to the specified destination.
Parameters:
destination - Writer acting as a destination for the SE
Throws:
java.io.IOException - if there was some kind of error when writing the header.
Overrides:
write in class StructElement

fits

public boolean fits(java.awt.image.Raster raster,
                    int x,
                    int y)
Tests whether the SE fits within an image at the specified coordinates. The SE is positioned so that its origin lies at these coordinates. If, for each SE pixel set to 1, the corresponding image pixel is non-zero, the SE is said to fit at that point.

Note: this method does not check whether SE pixels lie beyond the bounds of the image!

Parameters:
raster - Raster of the image into which the SE will be fitted
x - x coordinate of pixel where SE will be placed
y - y coordinate of pixel where SE will be placed
Returns:
true if the SE fits, false otherwise.

fitsComplement

public boolean fitsComplement(java.awt.image.Raster raster,
                              int x,
                              int y)
Tests whether the SE fits within the complement of an image at the specified coordinates. The SE is positioned so that its origin lies at these coordinates. If, for all SE pixels set to 1, the corresponding image pixel is zero, the SE is said to fit the complement of the image at that point.

Note: this method does not check whether SE pixels lie beyond the bounds of the image!

Parameters:
raster - Raster of the image into which the SE will be fitted
x - x coordinate of pixel where SE will be placed
y - y coordinate of pixel where SE will be placed
Returns:
true if the SE fits the complement of the image, false otherwise.

hits

public boolean hits(java.awt.image.Raster raster,
                    int x,
                    int y)
Tests whether the SE hits an image when it is placed at the specified coordinates. The SE is positioned so that its origin lies at these coordinates. If, for any of the SE pixels set to 1, the corresponding image pixel is non-zero, the SE is said to hit the image at that point.

Note: this method does not check whether SE pixels lie beyond the bounds of the image!

Parameters:
raster - Raster of the image with which the SE will be intersected
x - x coordinate of pixel where SE will be placed
y - y coordinate of pixel where SE will be placed
Returns:
true if the SE hits, false otherwise.

getRotatedVersion

public BinaryStructElement getRotatedVersion()
Returns:
a version of this BinaryStructElement that has been rotated through 180 degrees.