JIGL
v1.6

jigl.image
Class GrayImage

java.lang.Object
  |
  +--jigl.image.GrayImage
All Implemented Interfaces:
Image
Direct Known Subclasses:
InterpolatedGrayImage

public class GrayImage
extends Object
implements Image

GrayImage is implemented by a 2 dimension array of shorts.


Field Summary
protected  short[][] data
          Two dimensional integer array to store image content.
protected  int X
          Cartesian width
protected  int Y
          Cartesian height
 
Constructor Summary
GrayImage()
          Creates an empty GrayImage with a height and width of zero
GrayImage(GrayImage img)
          Creates a two dimensional GrayImage from GrayImage img
GrayImage(Image img)
          Creates an two dimensional GrayImage from the standard java.awt.Image
GrayImage(int x, int y)
          Creates a two dimensional GrayImage with a width and height of x and y repectively
GrayImage(int x, int y, short[] data)
          Creates a two dimensional GrayImage with a height and width of x and y repectively
GrayImage(short[][] data)
          Creates a two dimensional GrayImage from a two dimensional array
 
Method Summary
 int absSum()
          Adds absolute value of all the values together
 GrayImage add(GrayImage im)
          Adds another GrayImage to this image
 GrayImage add(GrayImage im, ROI sourceROI, ROI destROI)
          Adds a Region of Interest (sourceROI) in another GrayImage to a Region of Interest (destROI) of this image
 GrayImage add(int v)
          Adds a value to all the pixels in this image
 void add(int x, int y, int value)
          Adds a value to a single pixel
 void add(int x, int y, int value, ROI roi)
          Adds a value to a single pixel in a Region of Interest
 GrayImage add(int v, ROI roi)
          Adds a value to all the pixels in a Region of Interest
 GrayImage addbuffer(int w, int h, int color)
          Makes a copy of this image with a buffer so the resulting image has a width w and height h
 GrayImage addbuffer(int w, int h, int xoff, int yoff, int color)
          Makes a copy of this image with a buffer so the resulting image has a width w and height h
 int addSum()
          Adds all the values together
 void byteSize()
          Scales the range of this image to byte (0..255)
 void byteSize(ROI roi)
          Scales the range of a region of interest of this image to byte (0..255)
 GrayImage clear()
          Clears the image to zero
 GrayImage clear(int val)
          Clears to constant value
 void clip(int min, int max)
          Clips the range of this image to an arbitrary min/max
 void clip(int min, int max, ROI roi)
          Clips the range of this image to an arbitrary min/max in a Region of Interest
 Image copy()
          Makes a deep copy of this image
 Image copy(ROI roi)
          Makes a deep copy of a Region of Interest
 GrayImage diff(GrayImage im)
          Subtracts the second image from the first and returns the absolute value.
 GrayImage divide(GrayImage im)
          Divides this image by a GrayImage
 GrayImage divide(GrayImage im, ROI sourceROI, ROI destROI)
          Divides by a Region of Interest (sourceROI) in this image by a Region of Interest (destROI) of another GrayImage
 GrayImage divide(int v)
          Divides all the pixels in this image by a value
 void divide(int x, int y, int value)
          Divides a single pixel by a value
 void divide(int x, int y, int value, ROI roi)
          Divides a single pixel by a value in a Region of Interest
 GrayImage divide(int v, ROI roi)
          Divides all the pixels by a value in a Region of Interest
 int get(int x, int y)
          Returns the pixel value at the given x, y value
 short[][] getData()
          Return a deep copy of data.
 ImageProducer getJavaImage()
          Turns this image into a Java Image (java.awt.Image).
private  void InitFromImage(Image img, int x, int y, int w, int h)
           
static void main(String[] args)
           
 int max()
          Finds the maximum value of this image
 int max(ROI roi)
          Finds the maximum value in a Region of Interest
 void median(int size)
          Performs median filter on this image
 void median(int size, ROI roi)
          Performs median filter in a Region of Interest
 int min()
          Finds the minimum value of this image
 int min(ROI roi)
          Finds the minimum value in a Region of Interest
 GrayImage multiply(GrayImage im)
          Multiplies a GrayImage by this image
 GrayImage multiply(GrayImage im, ROI sourceROI, ROI destROI)
          Multiplies a Region of Interest (sourceROI) of another GrayImage by a Region of Interest (destROI) of this image
 GrayImage multiply(int v)
          Multiplies all the pixels in this image by a value
 void multiply(int x, int y, int value)
          Mutiplies a single pixel by a value
 void multiply(int x, int y, int value, ROI roi)
          Mutiplies a single pixel by a value in a Region of Interest
 GrayImage multiply(int v, ROI roi)
          Multiplies all the pixels in a Region of Interest by a value
 void set(int x, int y, int value)
          Sets the pixel value at x, y to a given value
 void set(int x, int y, int value, ROI roi)
          Sets the pixel value at x, y to a given value in a Region of Interest
private  double[] sort(double[] vals, int size)
           
 long sqrSum()
          Adds the square of all the values together
 GrayImage subtract(GrayImage im)
          Subtracts a GrayImage from this image
 GrayImage subtract(GrayImage im, ROI sourceROI, ROI destROI)
          Subtracts a Region of Interest (sourceROI) in another GrayImage from a Region of Interest (destROI) of this image
 GrayImage subtract(int v)
          Subtracts a value from all the pixels in this image
 void subtract(int x, int y, int value)
          Subtracts a value from a single pixel
 void subtract(int x, int y, int value, ROI roi)
          Subtracts a value from a single pixel in a Region of Interest
 GrayImage subtract(int v, ROI roi)
          Subtracts a value from all the pixels in a Region of Interest
 String toString()
          Prints this image in integer format.
 String toString(ROI roi)
          Prints a Region of Interest in integer format.
 int X()
          Returns the width (maximum X value)
 int Y()
          Returns the height (maximum Y value)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

data

protected short[][] data
Two dimensional integer array to store image content.


X

protected int X
Cartesian width


Y

protected int Y
Cartesian height

Constructor Detail

GrayImage

public GrayImage()
Creates an empty GrayImage with a height and width of zero


GrayImage

public GrayImage(int x,
                 int y)
Creates a two dimensional GrayImage with a width and height of x and y repectively


GrayImage

public GrayImage(int x,
                 int y,
                 short[] data)
Creates a two dimensional GrayImage with a height and width of x and y repectively

Parameters:
x - width of image
y - height of image

GrayImage

public GrayImage(short[][] data)
Creates a two dimensional GrayImage from a two dimensional array


GrayImage

public GrayImage(GrayImage img)
Creates a two dimensional GrayImage from GrayImage img


GrayImage

public GrayImage(Image img)
Creates an two dimensional GrayImage from the standard java.awt.Image

Method Detail

copy

public Image copy()
Makes a deep copy of this image

Specified by:
copy in interface Image
Returns:
a deep copy of GrayImage

getData

public short[][] getData()
Return a deep copy of data.


addbuffer

public GrayImage addbuffer(int w,
                           int h,
                           int color)
Makes a copy of this image with a buffer so the resulting image has a width w and height h

Parameters:
w - width of buffered image
h - height of buffered image
color - default color to buffer with
Returns:
a deep copy of GrayImage

addbuffer

public GrayImage addbuffer(int w,
                           int h,
                           int xoff,
                           int yoff,
                           int color)
Makes a copy of this image with a buffer so the resulting image has a width w and height h

Parameters:
w - width of buffered image
h - height of buffered image
xoff - x offset of this image in the buffered image
yoff - y offset of this image in the buffered image
color - default color to buffer with
Returns:
a deep copy of GrayImage

InitFromImage

private void InitFromImage(Image img,
                           int x,
                           int y,
                           int w,
                           int h)

X

public final int X()
Returns the width (maximum X value)

Specified by:
X in interface Image

Y

public final int Y()
Returns the height (maximum Y value)

Specified by:
Y in interface Image

get

public final int get(int x,
                     int y)
Returns the pixel value at the given x, y value

Parameters:
x - the X coordinate
y - the Y coordinate

set

public final void set(int x,
                      int y,
                      int value)
Sets the pixel value at x, y to a given value

Parameters:
x - the X coordinate
y - the Y coordinate
value - the value to set the pixel to

clear

public final GrayImage clear()
Clears the image to zero


clear

public final GrayImage clear(int val)
Clears to constant value

Parameters:
val - the value to "clear" the image to

add

public final void add(int x,
                      int y,
                      int value)
Adds a value to a single pixel

Parameters:
x - X-coordinate
y - Y-coordinate
value - the value to add to the pixel

subtract

public final void subtract(int x,
                           int y,
                           int value)
Subtracts a value from a single pixel

Parameters:
x - X-coordinate
y - Y-coordinate
value - the value to subtract from the pixel

multiply

public final void multiply(int x,
                           int y,
                           int value)
Mutiplies a single pixel by a value

Parameters:
x - X-coordinate
y - Y-coordinate
value - - the value to mutiply to the pixel

divide

public final void divide(int x,
                         int y,
                         int value)
Divides a single pixel by a value

Parameters:
x - X-coordinate
y - Y-coordinate
value - - the value to mutiply to the pixel

min

public final int min()
Finds the minimum value of this image

Returns:
an integer containing the minimum value

max

public final int max()
Finds the maximum value of this image

Returns:
an integer containing the maximum value

add

public final GrayImage add(int v)
Adds a value to all the pixels in this image

Parameters:
v - value to be added to the pixels
Returns:
this

subtract

public final GrayImage subtract(int v)
Subtracts a value from all the pixels in this image

Parameters:
v - value to be added to the pixels
Returns:
this

multiply

public final GrayImage multiply(int v)
Multiplies all the pixels in this image by a value

Parameters:
v - value to be added to the pixels
Returns:
this

divide

public final GrayImage divide(int v)
Divides all the pixels in this image by a value

Parameters:
v - value to be added to the pixels
Returns:
this

addSum

public final int addSum()
Adds all the values together


absSum

public final int absSum()
Adds absolute value of all the values together


sqrSum

public final long sqrSum()
Adds the square of all the values together


add

public final GrayImage add(GrayImage im)
Adds another GrayImage to this image

Parameters:
im - the GrayImage to add
Returns:
this

subtract

public final GrayImage subtract(GrayImage im)
Subtracts a GrayImage from this image

Parameters:
im - the GrayImage to subtract
Returns:
this

diff

public final GrayImage diff(GrayImage im)
Subtracts the second image from the first and returns the absolute value. Assumes the two images having the same size.


multiply

public final GrayImage multiply(GrayImage im)
Multiplies a GrayImage by this image

Parameters:
im - the GrayImage to multiply
Returns:
this

divide

public final GrayImage divide(GrayImage im)
Divides this image by a GrayImage

Parameters:
im - the GrayImage to divide
Returns:
this

toString

public String toString()
Prints this image in integer format.
-Example of output on an image with width 100 and height 120:
100 : 120
10 20 32 12 32 56 40 59 42 39 43 ...

Specified by:
toString in interface Image
Overrides:
toString in class Object

getJavaImage

public ImageProducer getJavaImage()
Turns this image into a Java Image (java.awt.Image). Note: This method also scales the image so all the values are between 0 and 255.

Specified by:
getJavaImage in interface Image
See Also:
ImageProducer

byteSize

public void byteSize()
Scales the range of this image to byte (0..255)


clip

public void clip(int min,
                 int max)
Clips the range of this image to an arbitrary min/max

Parameters:
min - minimum value
max - maximum value

sort

private double[] sort(double[] vals,
                      int size)

median

public void median(int size)
Performs median filter on this image

Parameters:
size - the size of the median filter

copy

public Image copy(ROI roi)
Makes a deep copy of a Region of Interest

Specified by:
copy in interface Image
Parameters:
roi - Region of Interest
Returns:
a deep copy of GrayImage

set

public final void set(int x,
                      int y,
                      int value,
                      ROI roi)
Sets the pixel value at x, y to a given value in a Region of Interest

Parameters:
x - the X coordinate
y - the Y coordinate
value - the value to set the pixel to
roi - Region of Interest

add

public final void add(int x,
                      int y,
                      int value,
                      ROI roi)
Adds a value to a single pixel in a Region of Interest

Parameters:
x - X-coordinate
y - Y-coordinate
value - the value to add to the pixel
roi - Region of Interest

subtract

public final void subtract(int x,
                           int y,
                           int value,
                           ROI roi)
Subtracts a value from a single pixel in a Region of Interest

Parameters:
x - X-coordinate
y - Y-coordinate
value - the value to subtract from the pixel
roi - Region of Interest

multiply

public final void multiply(int x,
                           int y,
                           int value,
                           ROI roi)
Mutiplies a single pixel by a value in a Region of Interest

Parameters:
x - X-coordinate
y - Y-coordinate
value - - the value to mutiply to the pixel
roi - Region of Interest

divide

public final void divide(int x,
                         int y,
                         int value,
                         ROI roi)
Divides a single pixel by a value in a Region of Interest

Parameters:
x - X-coordinate
y - Y-coordinate
value - - the value to mutiply to the pixel
roi - Region of Interest

min

public final int min(ROI roi)
Finds the minimum value in a Region of Interest

Parameters:
roi - Region of Interest
Returns:
an integer containing the minimum value.

max

public final int max(ROI roi)
Finds the maximum value in a Region of Interest

Parameters:
roi - Region of Interest
Returns:
an integer containing the maximum value

add

public final GrayImage add(int v,
                           ROI roi)
Adds a value to all the pixels in a Region of Interest

Parameters:
v - value to be added to the pixels
roi - Region of Interest
Returns:
this

subtract

public final GrayImage subtract(int v,
                                ROI roi)
Subtracts a value from all the pixels in a Region of Interest

Parameters:
v - value to be added to the pixels
roi - Region of Interest
Returns:
this

multiply

public final GrayImage multiply(int v,
                                ROI roi)
Multiplies all the pixels in a Region of Interest by a value

Parameters:
v - value to be added to the pixels
roi - Region of Interest
Returns:
this

divide

public final GrayImage divide(int v,
                              ROI roi)
Divides all the pixels by a value in a Region of Interest

Parameters:
v - value to be added to the pixels
roi - Region of Interest
Returns:
this

add

public final GrayImage add(GrayImage im,
                           ROI sourceROI,
                           ROI destROI)
Adds a Region of Interest (sourceROI) in another GrayImage to a Region of Interest (destROI) of this image

Parameters:
im - the GrayImage to add
sourceROI - Region of Interest for the Source Image
destROI - Region of Interest for the Destination Image
Returns:
this

subtract

public final GrayImage subtract(GrayImage im,
                                ROI sourceROI,
                                ROI destROI)
Subtracts a Region of Interest (sourceROI) in another GrayImage from a Region of Interest (destROI) of this image

Parameters:
im - the GrayImage to subtract
sourceROI - Region of Interest for the Source Image
destROI - Region of Interest for the Destination Image
Returns:
this

multiply

public final GrayImage multiply(GrayImage im,
                                ROI sourceROI,
                                ROI destROI)
Multiplies a Region of Interest (sourceROI) of another GrayImage by a Region of Interest (destROI) of this image

Parameters:
im - the GrayImage to multiply
sourceROI - Region of Interest for the Source Image
destROI - Region of Interest for the Destination Image
Returns:
this

divide

public final GrayImage divide(GrayImage im,
                              ROI sourceROI,
                              ROI destROI)
Divides by a Region of Interest (sourceROI) in this image by a Region of Interest (destROI) of another GrayImage

Parameters:
im - the GrayImage to divide
sourceROI - Region of Interest for the Source Image
destROI - Region of Interest for the Destination Image
Returns:
this

toString

public String toString(ROI roi)
Prints a Region of Interest in integer format.

Parameters:
roi - Region of Interest
-Example of output on an image with width 100 and height 120:
100 : 120
10 20 32 12 32 56 40 59 42 39 43 ...

clip

public void clip(int min,
                 int max,
                 ROI roi)
Clips the range of this image to an arbitrary min/max in a Region of Interest

Parameters:
min - minimum value
max - maximum value
roi - Region of Interest

byteSize

public void byteSize(ROI roi)
Scales the range of a region of interest of this image to byte (0..255)


median

public void median(int size,
                   ROI roi)
Performs median filter in a Region of Interest

Parameters:
size - the size of the median filter
roi - Region of Interest

main

public static void main(String[] args)

JIGL
v1.6

Submit a bug or feature
Revised in May 2002 by Weiming Liu