no.hiof.imagepr.tools
Class Arithmetic

java.lang.Object
  extended byno.hiof.imagepr.tools.Arithmetic

public class Arithmetic
extends java.lang.Object

Arithmetic is a class for enhancement of images using arithmetic and logic operations.

The Arithemtic class contains methods for performing the logic operations (AND and OR) and arithmetic operations (substraction, addition and multiplication) between two images, and methods for performing the logical operation NOT on separate images.

Author:
Mari-Ann Akerjord

Field Summary
static int ABS
          Option for changing negative pixel values to their absolute value.
static int CUT_LOWER
          Option for changing negative pixel values to zero
static int CUT_UPPER
          Option for changing pixel values above 255 to 255
static int DONT_SCALE
          Option for no scaling
static int SCALE_MAX
          Option for multiplying each pixel in the image by the quantity 255/Max, where Max is the maximum pixel value in the image.
static int SUB_MIN
          Option for substracting the minimum pixel value in the image from all pixels in the image.
static int WRAP_UPPER
          Option for changing pixel values (p) above 255 to 2*255 -p
 
Constructor Summary
Arithmetic()
          Constructs an Arithmetic-object.
Arithmetic(int option)
          Constructs an Arithmetic-object with a spesific scaling-option.
 
Method Summary
 IntensityImage add(IntensityImage im1, IntensityImage im2)
          Computes the sum of two IntensityImages on a pixel-by-pixel basis.
 IntensityImage add(IntensityImage image, short c)
          Adds a value to each pixel of an IntensityImage.
 short[][] add(short[][] matrix1, short c)
          Adds a value to each element of a short matrix.
 short[][] add(short[][] matrix1, short[][] matrix2)
          Computes the sum of two IntensityImages on a pixel-by-pixel basis.
 BinaryImage and(BinaryImage im1, BinaryImage im2)
          Performs the logical operator AND between two BinaryImages.
 IntensityImage and(IntensityImage im1, BinaryImage im2)
          Performs the logical operator AND between an IntensityImage and a BinaryImage.
 IntensityImage and(IntensityImage im1, IntensityImage im2)
          Performs the logical operator AND between an two IntensityImages The two images must be of equal size.
 short[][] and(short[][] matrix1, short[][] matrix2)
          Performs the logical operator AND between two short matrices.
 BinaryImage andNot(BinaryImage im1, BinaryImage im2)
          Takes the and operation between a binary image and of the inversion of another binary image.
 short findMaximum(short[][] matrix)
          Find the maximum of the elements in a short matrix.
 short findMinimum(short[][] matrix)
          Find the minimum of the elements in a short matrix.
 IntensityImage multiply(IntensityImage im, int c)
          Multiplies each pixel value in an IntensityImage with a constant value.
 IntensityImage multiply(IntensityImage im1, IntensityImage im2)
          Multiplies two IntensityImages on a pixel-by-pixel basis.
 short[][] multiply(short[][] matrix, int c)
          Multiplies each element of a short matrix with a constant value.
 short[][] multiply(short[][] matrix1, short[][] matrix2)
          Multiplies two short matrices on a pixel-by-pixel basis.
 BinaryImage not(BinaryImage im)
          Performs the logical operator NOT on a BinaryImage.
 IntensityImage not(IntensityImage im)
          Performs the logical operator NOT on an IntensityImage.
 short[][] not(short[][] matrix)
          Performs the logical operator NOT on a short matrix.
 BinaryImage or(BinaryImage im1, BinaryImage im2)
          Performs the logical operator OR between two BinaryImages.
 IntensityImage or(IntensityImage im1, BinaryImage im2)
          Performs the logical operator OR between an IntensityImage and a BinaryImage.
 IntensityImage or(IntensityImage im1, IntensityImage im2)
          Performs the logical operator OR between two IntensityImages.
 short[][] or(short[][] matrix1, short[][] matrix2)
          Performs the logical operator OR between an IntensityImage and a BinaryImage.
 void scale(short[][] matrix)
          Scales a matrix of image data.
 IntensityImage subtract(IntensityImage im1, IntensityImage im2)
          Computes the difference of two IntensityImages on a pixel-by-pixel basis.
 short[][] subtract(short[][] matrix1, short[][] matrix2)
          Computes the difference of two short matrices on a element by element basis.
 BinaryImage xor(BinaryImage im1, BinaryImage im2)
          Takes the xor operation between to binary images.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DONT_SCALE

public static final int DONT_SCALE
Option for no scaling

See Also:
Constant Field Values

CUT_LOWER

public static final int CUT_LOWER
Option for changing negative pixel values to zero

See Also:
Constant Field Values

CUT_UPPER

public static final int CUT_UPPER
Option for changing pixel values above 255 to 255

See Also:
Constant Field Values

ABS

public static final int ABS
Option for changing negative pixel values to their absolute value.

See Also:
Constant Field Values

WRAP_UPPER

public static final int WRAP_UPPER
Option for changing pixel values (p) above 255 to 2*255 -p

See Also:
Constant Field Values

SUB_MIN

public static final int SUB_MIN
Option for substracting the minimum pixel value in the image from all pixels in the image.

See Also:
Constant Field Values

SCALE_MAX

public static final int SCALE_MAX
Option for multiplying each pixel in the image by the quantity 255/Max, where Max is the maximum pixel value in the image.

See Also:
Constant Field Values
Constructor Detail

Arithmetic

public Arithmetic()
Constructs an Arithmetic-object. No scaling will be performed on images created by the methods for performing arithmetic or logical operations on spesific images.


Arithmetic

public Arithmetic(int option)
Constructs an Arithmetic-object with a spesific scaling-option. Images created by the methods for performing arithmetic or logical operations on spesific images will be scaled. Scaling method to be used is determined by the value of the parameter option.

Parameters:
option - Option for scaling. Possible values: DONT_SCALE, CUT_LOWER, CUT_UPPER, ABS, WRAP_UPPER, SUB_MIN AND SCALE_MAX. If more than one scaling method is wanted, the sum of two or more of these values should be used.
Method Detail

not

public BinaryImage not(BinaryImage im)
Performs the logical operator NOT on a BinaryImage.

Parameters:
im - The BinaryImage.
Returns:
The resulting BinaryImage.

not

public IntensityImage not(IntensityImage im)
Performs the logical operator NOT on an IntensityImage.

Parameters:
im - The IntensityImage.
Returns:
The resulting IntensityImage.

not

public short[][] not(short[][] matrix)
Performs the logical operator NOT on a short matrix. The operation is performed only on the eight lowest bits. The eight upper bits are set to zero.

Parameters:
matrix - The short matrix.
Returns:
The resulting matrix.

and

public BinaryImage and(BinaryImage im1,
                       BinaryImage im2)
Performs the logical operator AND between two BinaryImages. The two images must be of equal size.

Parameters:
im1 - A BinaryImage.
im2 - Another BinaryImage.
Returns:
The resulting BinaryImage.

and

public IntensityImage and(IntensityImage im1,
                          BinaryImage im2)
Performs the logical operator AND between an IntensityImage and a BinaryImage. The two images must be of equal size.

Parameters:
im1 - The intensityImage
im2 - The BinaryImage
Returns:
The resulting IntensityImage.

and

public IntensityImage and(IntensityImage im1,
                          IntensityImage im2)
Performs the logical operator AND between an two IntensityImages The two images must be of equal size.

Parameters:
im1 - An IntensityImage.
im2 - Another IntensityImage.
Returns:
The resulting IntensityImage.

and

public short[][] and(short[][] matrix1,
                     short[][] matrix2)
Performs the logical operator AND between two short matrices. The operation is performed only on the eight lowest bits. The eight upper bits are set to zero.

Parameters:
matrix1 - A short matrix.
matrix2 - Another short matrix.

or

public BinaryImage or(BinaryImage im1,
                      BinaryImage im2)
Performs the logical operator OR between two BinaryImages. The two images must be of equal size.

Parameters:
im1 - A BinaryImage.
im2 - Another BinaryImage.
Returns:
The resulting BinaryImage.

or

public IntensityImage or(IntensityImage im1,
                         BinaryImage im2)
Performs the logical operator OR between an IntensityImage and a BinaryImage. The two images must be of equal size.

Parameters:
im1 - The intensityImage
im2 - The BinaryImage
Returns:
The resulting IntensityImage.

or

public IntensityImage or(IntensityImage im1,
                         IntensityImage im2)
Performs the logical operator OR between two IntensityImages. The two images must be of equal size.

Parameters:
im1 - An IntensityImage.
im2 - Another IntensityImage.
Returns:
The resulting IntensityImage.

or

public short[][] or(short[][] matrix1,
                    short[][] matrix2)
Performs the logical operator OR between an IntensityImage and a BinaryImage. The two images must be of equal size.

Parameters:
matrix1 - The intensityImage
matrix2 - The BinaryImage
Returns:
The resulting IntensityImage.

add

public IntensityImage add(IntensityImage im1,
                          IntensityImage im2)
Computes the sum of two IntensityImages on a pixel-by-pixel basis. Each pixel in the resulting image is the sum of the pixels in the same location in the two images beeing added. The resulting image is scaled.

Parameters:
im1 - An IntensityImage
im2 - Another IntensityImage
Returns:
The resulting IntensityImage.

add

public short[][] add(short[][] matrix1,
                     short[][] matrix2)
Computes the sum of two IntensityImages on a pixel-by-pixel basis. Each pixel in the resulting image is the sum of the pixels in the same location in the two images beeing added. The resulting image is scaled.

Parameters:
matrix1 - A matrix
matrix2 - Another matrix
Returns:
The resulting IntensityImage.

add

public IntensityImage add(IntensityImage image,
                          short c)
Adds a value to each pixel of an IntensityImage. The resulting image is scaled.

Parameters:
image - An IntensityImage.
c - The value that is added to the image.
Returns:
The resulting IntensityImage.

add

public short[][] add(short[][] matrix1,
                     short c)
Adds a value to each element of a short matrix. The resulting matrix is scaled.

Parameters:
matrix1 - A matrix
c - The value that is added to the image.
Returns:
The resulting IntensityImage.

multiply

public IntensityImage multiply(IntensityImage im,
                               int c)
Multiplies each pixel value in an IntensityImage with a constant value.

Parameters:
im - The IntensityImage
c - The constant.
Returns:
The resulting IntensityImage.

multiply

public short[][] multiply(short[][] matrix,
                          int c)
Multiplies each element of a short matrix with a constant value.

Parameters:
matrix - The matrix.
c - The constant.
Returns:
The resulting matrix.

multiply

public IntensityImage multiply(IntensityImage im1,
                               IntensityImage im2)
Multiplies two IntensityImages on a pixel-by-pixel basis. Each pixel in the resulting image is the product of the pixels in the same location in the two images beeing multiplied. The resulting image is scaled.

Parameters:
im1 - An IntensityImage
im2 - Another IntensityImage
Returns:
The resulting IntensityImage.

multiply

public short[][] multiply(short[][] matrix1,
                          short[][] matrix2)
Multiplies two short matrices on a pixel-by-pixel basis. Each pixel in the resulting matrix is the product of the pixels in the same location in the two matrices beeing multiplied. The resulting matrix is scaled.

Parameters:
matrix1 - A short matrix
matrix2 - Another short matrix
Returns:
The resulting matrix.

andNot

public BinaryImage andNot(BinaryImage im1,
                          BinaryImage im2)
Takes the and operation between a binary image and of the inversion of another binary image. This means that the resulting image is the result of setting the pixels of the first image to zero where the pixel of the second image is one.

Parameters:
im1 - A binary image.
im2 - A binary image specifying which pixels should be set to zero.
Returns:
The resulting image.

xor

public BinaryImage xor(BinaryImage im1,
                       BinaryImage im2)
Takes the xor operation between to binary images.

Parameters:
im1 - A binary image.
im2 - Another binary image.
Returns:
The resulting image.

subtract

public IntensityImage subtract(IntensityImage im1,
                               IntensityImage im2)
Computes the difference of two IntensityImages on a pixel-by-pixel basis. Each pixel in the resulting image is the difference of the pixels in the same location in the two images beeing subtracted. The resulting image is scaled.

Parameters:
im1 - An IntensityImage
im2 - Another IntensityImage
Returns:
The resulting IntensityImage.

subtract

public short[][] subtract(short[][] matrix1,
                          short[][] matrix2)
Computes the difference of two short matrices on a element by element basis. Each element in the resulting matrix is the difference of the elements in the same location in the two matrices beeing subtracted. The resulting matrix is scaled.

Parameters:
matrix1 - A short matrix.
matrix2 - Another short matrix.
Returns:
The resulting matrix.

scale

public void scale(short[][] matrix)
Scales a matrix of image data.

Parameters:
matrix - The matrix containing the image data.

findMinimum

public short findMinimum(short[][] matrix)
Find the minimum of the elements in a short matrix.

Parameters:
matrix - A matrix.
Returns:
The minimum.

findMaximum

public short findMaximum(short[][] matrix)
Find the maximum of the elements in a short matrix.

Parameters:
matrix - A matrix.
Returns:
The maximum.