no.hiof.imagepr
Class BinaryImage

java.lang.Object
  extended byno.hiof.imagepr.BinaryImage
All Implemented Interfaces:
Image, java.io.Serializable

public class BinaryImage
extends java.lang.Object
implements Image, java.io.Serializable

BinaryImage is a class for Binary images (black and white images). The BinaryImage class contains a Bitset containing the pixel values. There is one bit, which is 0 or 1 (or equally false or true) for each pixel.

Author:
Per-Olav Rusås
See Also:
IntensityImage, RGBImage, HSIImage, Serialized Form

Field Summary
protected  java.util.BitSet data
           
protected  int height
           
protected  java.awt.Color oneColor
           
protected  int width
           
protected  java.awt.Color zeroColor
           
 
Fields inherited from interface no.hiof.imagepr.Image
BLUE, GREEN, RED
 
Constructor Summary
BinaryImage()
          Constructor for an empty BinaryImage.
BinaryImage(BinaryImage otherImage)
          Construcs a BinaryImage by copying another BinaryImage.
BinaryImage(IntensityImage original, int threshold)
          Construcs a BinaryImage with an IntensityImage as a basis.
BinaryImage(int height, int width)
          Constructs a BinaryImage with a given height and width.
 
Method Summary
 Image createScaledImage(double scale, int interpolType)
          Creates a scaled image.
 void draw(java.awt.Graphics g, int x, int y)
          Draw the image to a Graphics object at a given position.
 void draw(java.awt.Graphics g, int x, int y, double scaleX, double scaleY, double rotateAngle)
          Draw the image to a Graphics object at a given position with a given scale and rotation.
 java.util.BitSet getData()
          Gets the BitSet width the image data.
 int getHeight()
          Get the height of the BinaryImage.
 boolean getValueAt(int row, int col)
          Gets the value at a given pixel.
 int getWidth()
          Get the width of the BinaryImage.
 void load(java.lang.String filename)
          Loads the image from a file.
 java.awt.image.BufferedImage makeBufferedImage()
           
 IntensityImage makeIntensityImage()
          Make a IntensityImage of the BinaryImage
 IntensityImage makeIntensityImage(short zeroValue, short oneValue)
          Make a IntensityImage of the BinaryImage
 RGBImage makeRGBImage()
          Make a RGBImage of the BinaryImage
 void save(java.lang.String filename)
          Saves the image to a binary file.
 void setData(java.util.BitSet data)
          Sets the BitSet of the BinaryImage
 void setOneColor(java.awt.Color c)
          Sets the color of the pixels whith value one.
 void setValueAt(int row, int col, boolean value)
          Sets the value at a given pixel as true or false (representing 1 or 0).
 void setZeroColor(java.awt.Color c)
          Sets the color of the pixels whith value zero.
 void show()
          Shows the BinaryImage in a modal window.
 void show(java.lang.String title)
          Shows the BinaryImage in a modal window.
 void show(java.lang.String title, double scale)
           
 java.lang.String toString()
          Returns a description of the image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

width

protected int width

height

protected int height

data

protected java.util.BitSet data

zeroColor

protected java.awt.Color zeroColor

oneColor

protected java.awt.Color oneColor
Constructor Detail

BinaryImage

public BinaryImage()
Constructor for an empty BinaryImage.


BinaryImage

public BinaryImage(int height,
                   int width)
Constructs a BinaryImage with a given height and width.

Parameters:
height - The height.
width - The width.

BinaryImage

public BinaryImage(BinaryImage otherImage)
Construcs a BinaryImage by copying another BinaryImage.

Parameters:
otherImage - Another BinaryImage.

BinaryImage

public BinaryImage(IntensityImage original,
                   int threshold)
Construcs a BinaryImage with an IntensityImage as a basis. The pixel value of the BinaryImage is set to true if the intensity of the IntensityImage is greater or equal to a given threshold. Otherwise the pixel value are set to false.

Parameters:
original - The original IntensityImage
threshold - The threshold
Method Detail

getValueAt

public boolean getValueAt(int row,
                          int col)
Gets the value at a given pixel. The row and column numbering starts at zero.

Parameters:
row - The row-number of the pixel.
col - The column-number of the pixel.
Returns:
true if the pixel's bit is 1 otherwhise false.

setValueAt

public void setValueAt(int row,
                       int col,
                       boolean value)
Sets the value at a given pixel as true or false (representing 1 or 0).

Parameters:
row - The row-number of the pixel.
col - The column-number of the pixel.

show

public void show()
Shows the BinaryImage in a modal window.


show

public void show(java.lang.String title)
Shows the BinaryImage in a modal window.

Specified by:
show in interface Image
Parameters:
title - The title on top of the window.

show

public void show(java.lang.String title,
                 double scale)
Specified by:
show in interface Image

draw

public void draw(java.awt.Graphics g,
                 int x,
                 int y)
Draw the image to a Graphics object at a given position.

Specified by:
draw in interface Image
Parameters:
g - The Graphics object to draw on.
x - The horizontal position of the image.
y - The vertical position of the image.

draw

public void draw(java.awt.Graphics g,
                 int x,
                 int y,
                 double scaleX,
                 double scaleY,
                 double rotateAngle)
Draw the image to a Graphics object at a given position with a given scale and rotation.

Specified by:
draw in interface Image
Parameters:
g - The Graphics object to draw on.
x - The horizontal position of the image.
y - The vertical position of the image.
scaleX - The scale in x-direction. 1.0 means unscaled.
scaleY - The scale in y-direction. 1.0 means unscaled.
rotateAngle - Rotation of the image in degrees (0-360).

makeRGBImage

public RGBImage makeRGBImage()
Make a RGBImage of the BinaryImage

Returns:
a RGBImage representation of the BinaryImage

makeIntensityImage

public IntensityImage makeIntensityImage()
Make a IntensityImage of the BinaryImage

Returns:
An IntensityImage representation of the BinaryImage

makeIntensityImage

public IntensityImage makeIntensityImage(short zeroValue,
                                         short oneValue)
Make a IntensityImage of the BinaryImage

Parameters:
zeroValue - Value in IntensityImage corresponding to binary 0.
oneValue - Value in IntensityImage corresponding to binary 1.
Returns:
An IntensityImage representation of the BinaryImage

setZeroColor

public void setZeroColor(java.awt.Color c)
Sets the color of the pixels whith value zero.

Parameters:
c - The color.

setOneColor

public void setOneColor(java.awt.Color c)
Sets the color of the pixels whith value one.

Parameters:
c - The color.

setData

public void setData(java.util.BitSet data)
Sets the BitSet of the BinaryImage

Parameters:
data - The BitSet.

getWidth

public int getWidth()
Get the width of the BinaryImage.

Specified by:
getWidth in interface Image
Returns:
The width.

getHeight

public int getHeight()
Get the height of the BinaryImage.

Specified by:
getHeight in interface Image
Returns:
height.

save

public void save(java.lang.String filename)
          throws java.io.IOException
Saves the image to a binary file.

Parameters:
filename - The filename.
Throws:
java.io.IOException

load

public void load(java.lang.String filename)
          throws java.io.IOException
Loads the image from a file. The format of the file must be as produced by the save-method of this class.

Parameters:
filename - The filename.
Throws:
java.io.IOException

getData

public java.util.BitSet getData()
Gets the BitSet width the image data.

Returns:
The image data.

makeBufferedImage

public java.awt.image.BufferedImage makeBufferedImage()
Specified by:
makeBufferedImage in interface Image

toString

public java.lang.String toString()
Returns a description of the image.

Returns:
A description.

createScaledImage

public Image createScaledImage(double scale,
                               int interpolType)
Creates a scaled image. This method utilizes an ImageScaler to perform the scaling. The parameter interpolType is unused for this type of image. Nearest neighbour interpolation is the only possibility.

Specified by:
createScaledImage in interface Image
Parameters:
scale - The scale
interpolType - The type of interpolation (unused)