no.hiof.imagepr
Class IntensityImage

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

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

IntensityImage is a class for intensity images (gray scale images) which is supposed to be easier to use than the classes for image processing in the Java SDK API. The IntensityImage class contains one two-dimensional short array for the intensity values.

In order to be viewed properly, the intensity values must be set in the interval from 0 to 255. As default an IntensityImage is shown with a gray scale colormap, which means that an intensity of 0 is shown as black and an intensity of 255 is shown as white. It is possible to change which colormap to use. Several predifined colormaps are defined as static matrices.

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

Field Summary
static short[][] BLUE
          Colormap which shows the image in shades of blue.
protected  short[][] colormap
          The current mapping between intensity values and RGB colors
static short[][] COOL
          Colormap which shows an intensity of 0 as blue and an intensity of 255 as white.
protected  short[][] data
          The matrix with pixel values
static short[][] GRAY
          Colormap which shows the image as gray.
static short[][] GREEN
          Colormap which shows the image in shades of green.
static short[][] HSI
          Colormap which uses the HSI color model.
static short[][] INVGRAY
          Colormap which shows the image as an inverted gray image.
static short[][] RED
          Colormap which shows the image in shades of red.
static short[][] TEMP
          Colormap which shows an intensity of 0 as blue and an intensity of 255 as red.
 
Constructor Summary
IntensityImage()
          Constructor that creates an empty IntensityImage.
IntensityImage(IntensityImage otherImage)
          Constructor that copies another IntensityImage.
IntensityImage(int height, int width)
          Constructor that creates an IntensityImage with all pixel values set to zero.
IntensityImage(RGBImage rgbImage)
          A constructor that creates an IntensityImage from a RGBImage by letting the gray scale intensity be the average of the red, green and blue intensities.
IntensityImage(short[][] data)
          Constructor that creates an IntensityImage with given intensity data.
IntensityImage(java.lang.String filename)
          Constructor that creates an IntensityImage by reading data from a file.
 
Method Summary
 Image createScaledImage(double scale, int interpolType)
          Creates a scaled image.
 void draw(java.awt.Graphics g, int x, int y)
          Draws 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)
          Draws the image to a Graphics object at a given position with a given scale and rotation.
 short[][] getData()
          Returns the matrix of intensity data.
 int getHeight()
          The height of the image.
 int getWidth()
          The width of the image.
 void load(java.lang.String filename)
          Loads the image from a file.
 java.awt.image.BufferedImage makeBufferedImage()
          Creates a bufferedImage of the intensityImage using the current colormap.
static short[][] makeColormap(java.awt.Color minColor, java.awt.Color maxColor)
          Calculates a linear colormap.
 RGBImage makeRGBImage()
          Makes a RGBImage of the IntensityImage using the current colormap.
 void save(java.lang.String filename)
          Saves the image to a binary file.
 void setColormap(java.awt.Color minColor, java.awt.Color maxColor)
          Calculates and sets the colormap of the IntensityImage.
 void setColormap(short[][] colormap)
          Sets the current colormap of the IntensityImage.
 void setData(short[][] data)
          Sets the matrix of intensity data.
 void show()
          Shows the HSIImage in a modal window.
 void show(java.lang.String title)
          Shows the IntensityImage in a modal window.
 void show(java.lang.String title, double scale)
          Shows the IntensityImage scaled with use of nearest neighbor interpolation.
 void showBL(double scale, java.lang.String title)
          Shows the IntensityImage scaled with use of bilinear interpolation.
 java.lang.String toString()
          Returns a description of the image.
 boolean withColors()
          Returns true if the image uses a colormap which uses other colors than gray.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

data

protected short[][] data
The matrix with pixel values


colormap

protected short[][] colormap
The current mapping between intensity values and RGB colors


GRAY

public static short[][] GRAY
Colormap which shows the image as gray.


INVGRAY

public static short[][] INVGRAY
Colormap which shows the image as an inverted gray image.


RED

public static short[][] RED
Colormap which shows the image in shades of red.


GREEN

public static short[][] GREEN
Colormap which shows the image in shades of green.


BLUE

public static short[][] BLUE
Colormap which shows the image in shades of blue.


HSI

public static short[][] HSI
Colormap which uses the HSI color model.


TEMP

public static short[][] TEMP
Colormap which shows an intensity of 0 as blue and an intensity of 255 as red.


COOL

public static short[][] COOL
Colormap which shows an intensity of 0 as blue and an intensity of 255 as white.

Constructor Detail

IntensityImage

public IntensityImage()
Constructor that creates an empty IntensityImage.


IntensityImage

public IntensityImage(short[][] data)
Constructor that creates an IntensityImage with given intensity data.

Parameters:
data - Matrix of intensity data.

IntensityImage

public IntensityImage(int height,
                      int width)
Constructor that creates an IntensityImage with all pixel values set to zero.

Parameters:
height - The height of the image
width - The width of the image

IntensityImage

public IntensityImage(java.lang.String filename)
               throws java.io.IOException
Constructor that creates an IntensityImage by reading data from a file. The format of the file must be as produced by the save-method of this class.

Parameters:
filename - The name of the file.

IntensityImage

public IntensityImage(IntensityImage otherImage)
Constructor that copies another IntensityImage.

Parameters:
otherImage - Original image.

IntensityImage

public IntensityImage(RGBImage rgbImage)
A constructor that creates an IntensityImage from a RGBImage by letting the gray scale intensity be the average of the red, green and blue intensities.

Parameters:
rgbImage - Original image.
Method Detail

makeBufferedImage

public java.awt.image.BufferedImage makeBufferedImage()
Creates a bufferedImage of the intensityImage using the current colormap.

Specified by:
makeBufferedImage in interface Image
Returns:
a BufferedImage version of the Image

show

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

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

show

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


show

public void show(java.lang.String title,
                 double scale)
Shows the IntensityImage scaled with use of nearest neighbor interpolation. This method utilizes an ImageScaler to perform the scaling.

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

showBL

public void showBL(double scale,
                   java.lang.String title)
Shows the IntensityImage scaled with use of bilinear interpolation. This method utilizes an ImageScaler to perform the scaling.

Parameters:
scale - The scale.
title - The title on top of the window.

draw

public void draw(java.awt.Graphics g,
                 int x,
                 int y)
Draws 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)
Draws 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()
Makes a RGBImage of the IntensityImage using the current colormap.

Returns:
A RGBImage representation of the IntensityImage.

setColormap

public void setColormap(short[][] colormap)
Sets the current colormap of the IntensityImage.

Parameters:
colormap - The colormap.

setColormap

public void setColormap(java.awt.Color minColor,
                        java.awt.Color maxColor)
Calculates and sets the colormap of the IntensityImage.

Parameters:
minColor - Color which represent 0.
maxColor - Color which represent 255.

makeColormap

public static short[][] makeColormap(java.awt.Color minColor,
                                     java.awt.Color maxColor)
Calculates a linear colormap.

Parameters:
minColor - Color which represent 0.
maxColor - Color which represent 255.
Returns:
The colormap.

getData

public short[][] getData()
Returns the matrix of intensity data.

Returns:
The intensity matrix.

setData

public void setData(short[][] data)
Sets the matrix of intensity data. Does not copy the data.

Parameters:
data - The matrix of intensity data.

getWidth

public int getWidth()
The width of the image.

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

getHeight

public int getHeight()
The height of the image.

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

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

withColors

public boolean withColors()
Returns true if the image uses a colormap which uses other colors than gray.

Returns:
Shown with colors.

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 may be one of the constants Image.NEAREST for nearest neighbour interpolation or Image.BILINEAR for bilinear interpolation.

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