Class ImageAccess

java.lang.Object
  |
  +--ImageAccess

public class ImageAccess
extends java.lang.Object

ImageAccess is an interface layer to facilitate the access to the pixels of ImageJ images. Methods of ImageAccess provides an easy and robust way to access to the pixels of images. The data are stored in an double array. Many methods get/put allows to access to the data. If the user try to access outside of the image, the mirror boundary conditions are applied.
Field Summary
static int PATTERN_CROSS_3x3
           
static int PATTERN_SQUARE_3x3
           
 
Constructor Summary
ImageAccess(ij.process.ColorProcessor cp, int colorPlane)
          Creates a new object of the class ImageAccess from an ColorProcessor object.
ImageAccess(double[][] array)
          Creates a new ImageAccess object from a 2D double array of pixels.
ImageAccess(ij.process.ImageProcessor ip)
          Creates a new object of the class ImageAccess from an ImageProcessor object.
ImageAccess(int nx, int ny)
          Creates a new object of the class ImageAccess.
 
Method Summary
 void abs()
          Compute the absolute value.
 void add(double constant)
          An ImageAccess object calls this method for adding a constant to each pixel.
 void add(ImageAccess im1, ImageAccess im2)
          An ImageAccess object calls this method for adding two ImageAccess objects.
 ij.process.ByteProcessor createByteProcessor()
          Create a ByteProcessor from the pixel data.
 ij.process.FloatProcessor createFloatProcessor()
          Create a FloatProcessor from the pixel data.
 void divide(double constant)
          An ImageAccess object calls this method for dividing a constant to each pixel.
 void divide(ImageAccess im1, ImageAccess im2)
          An ImageAccess object calls this method for dividing two ImageAccess objects.
 ImageAccess duplicate()
          Create a new ImageAccess object by duplication of the current the ImageAccess object.
 double[][] getArrayPixels()
          Returns a copy of the pixel data organize in a 2D array.
 void getColumn(int x, double[] column)
          An ImageAccess object calls this method for getting a whole column of the image.
 void getColumn(int x, int y, double[] column)
          An ImageAccess object calls this method for getting a part of column.
 int getHeight()
          Return the height of the image.
 double getInterpolatedPixel(double x, double y)
          An ImageAccess object calls this method for getting the gray level of a selected pixel using a bilinear interpolation.
 double getMaximum()
          Return the maximum value of ImageAccess.
 double getMean()
          Return the mean value of ImageAccess.
 double getMinimum()
          Return the minimum value of ImageAccess.
 void getNeighborhood(int x, int y, double[][] neigh)
          An ImageAccess object calls this method for getting a neighborhood arround a pixel position.
 void getPattern(int x, int y, double[] neigh, int pattern)
          An ImageAccess object calls this method for getting a neighborhood of a predefined pattern around a selected pixel (x,y).
 double getPixel(int x, int y)
          An ImageAccess object calls this method for getting the gray level of a selected pixel.
 double[] getPixels()
          Returns a reference to the pixel data in double (1D).
 void getRow(int y, double[] row)
          An ImageAccess object calls this method for getting a whole row of the image.
 void getRow(int x, int y, double[] row)
          An ImageAccess object calls this method for getting a part of row.
 void getSubImage(int x, int y, ImageAccess output)
          An ImageAccess object calls this method to get a sub-image with the upper left corner in the coordinate (x,y).
 int getWidth()
          Return the width of the image.
 void multiply(double constant)
          An ImageAccess object calls this method for multiplying a constant to each pixel.
 void multiply(ImageAccess im1, ImageAccess im2)
          An ImageAccess object calls this method for multiplying two ImageAccess objects.
 void normalizeContrast()
          Stretches the contrast inside an image so that the gray levels are in the range 0 to 255.
 void pow(double a)
          Raised an ImageAccess object to the power a.
 void putArrayPixels(double[][] array)
          An ImageAccess object calls this method in order to put an 2D array of double in an ImageAccess.
 void putColumn(int x, double[] column)
          An ImageAccess object calls this method to put a whole column in a specified position into the image.
 void putColumn(int x, int y, double[] column)
          An ImageAccess object calls this method to put a part of column into the image.
 void putPixel(int x, int y, double value)
          An ImageAccess object calls this method in order a value of the gray level to be put to a position inside it given by the coordinates.
 void putRow(int y, double[] row)
          An ImageAccess object calls this method to put a whole row in a specified position into the image.
 void putRow(int x, int y, double[] row)
          An ImageAccess object calls this method to put a part of row into the image.
 void putSubImage(int x, int y, ImageAccess input)
          An ImageAccess object calls this method to put a sub-image with the upper left corner in the coordinate (x,y).
 void setConstant(double constant)
          An ImageAccess object calls this method to set a constant value to all pixels of the image.
 void show(java.lang.String title)
          Display an image.
 void show(java.lang.String title, java.awt.Point loc)
          Display an image at a specific position (x, y).
 void sqrt()
          Compute the square root of an ImageAccess.
 void subtract(double constant)
          An ImageAccess object calls this method for adding a constant to each pixel.
 void subtract(ImageAccess im1, ImageAccess im2)
          An ImageAccess object calls this method for subtracting two ImageAccess objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATTERN_SQUARE_3x3

public static final int PATTERN_SQUARE_3x3

PATTERN_CROSS_3x3

public static final int PATTERN_CROSS_3x3
Constructor Detail

ImageAccess

public ImageAccess(double[][] array)
Creates a new ImageAccess object from a 2D double array of pixels. The size of the array determines the size of the image.
Parameters:
array - an array of pixel (2D)

ImageAccess

public ImageAccess(ij.process.ImageProcessor ip)
Creates a new object of the class ImageAccess from an ImageProcessor object. ImageProcessor object contains the image data, the size and the type of the image. The ImageProcessor is provided by ImageJ, it should by a 8-bit, 16-bit.
Parameters:
ip - an ImageProcessor object provided by ImageJ

ImageAccess

public ImageAccess(ij.process.ColorProcessor cp,
                   int colorPlane)
Creates a new object of the class ImageAccess from an ColorProcessor object. ImageProcessor object contains the image data, the size and the type of the image. The ColorProcessor is provided by ImageJ, The ImageAccess contains one plane (red, green or blue) selected with the colorPlane parameter.
Parameters:
cp - an ColorProcessor object
colorPlane - index of the color plane 0, 1 or 2

ImageAccess

public ImageAccess(int nx,
                   int ny)
Creates a new object of the class ImageAccess. The size of the image are given as parameter. The data pixels are empty and are not initialized.
Parameters:
nx - the size of the image along the X-axis
ny - the size of the image along the Y-axis
Method Detail

getWidth

public int getWidth()
Return the width of the image.
Returns:
the image width

getHeight

public int getHeight()
Return the height of the image.
Returns:
the image height

getMaximum

public double getMaximum()
Return the maximum value of ImageAccess.
Returns:
the maximum value

getMinimum

public double getMinimum()
Return the minimum value of ImageAccess.
Returns:
the minimum value

getMean

public double getMean()
Return the mean value of ImageAccess.
Returns:
the mean value

getArrayPixels

public double[][] getArrayPixels()
Returns a copy of the pixel data organize in a 2D array.
Returns:
the 2D double array

getPixels

public double[] getPixels()
Returns a reference to the pixel data in double (1D).
Returns:
the 1D double array

createFloatProcessor

public ij.process.FloatProcessor createFloatProcessor()
Create a FloatProcessor from the pixel data.
Returns:
the FloatProcessor

createByteProcessor

public ij.process.ByteProcessor createByteProcessor()
Create a ByteProcessor from the pixel data.
Returns:
the ByteProcessor

duplicate

public ImageAccess duplicate()
Create a new ImageAccess object by duplication of the current the ImageAccess object.
Returns:
a new ImageAccess object

getPixel

public double getPixel(int x,
                       int y)
An ImageAccess object calls this method for getting the gray level of a selected pixel. Mirror border conditions are applied.
Parameters:
x - input, the integer x-coordinate of a pixel
y - input, the integer y-coordinate of a pixel
Returns:
the gray level of the pixel (double)

getInterpolatedPixel

public double getInterpolatedPixel(double x,
                                   double y)
An ImageAccess object calls this method for getting the gray level of a selected pixel using a bilinear interpolation. The coordinates can be given in double and the bilinear interpolation is applied the find the gray level. Mirror border conditions are applied.
Parameters:
x - input, the double x-coordinate of a pixel
y - input, the double y-coordinate of a pixel
Returns:
the gray level of the pixel (double)

getColumn

public void getColumn(int x,
                      double[] column)
An ImageAccess object calls this method for getting a whole column of the image. The column should already created with the correct size [ny].
Parameters:
x - input, the integer x-coordinate of a column
column - output, an array of the type double

getColumn

public void getColumn(int x,
                      int y,
                      double[] column)
An ImageAccess object calls this method for getting a part of column. The starting point is given by the y parameter and the ending determine by the size of the column parameter. The column parameter should already created.
Parameters:
x - input, the integer x-coordinate of a column
y - input, starting point
column - output, an array of the type double

getRow

public void getRow(int y,
                   double[] row)
An ImageAccess object calls this method for getting a whole row of the image. The row should already created with the correct size [nx].
Parameters:
y - input, the integer y-coordinate of a row
row - output, an array of the type double

getRow

public void getRow(int x,
                   int y,
                   double[] row)
An ImageAccess object calls this method for getting a part of row. The starting point is given by the y parameter and the ending determine by the size of the row parameter. The row parameter should already created.
Parameters:
x - input, starting point
y - input, the integer y-coordinate of a row
row - output, an array of the type double

getNeighborhood

public void getNeighborhood(int x,
                            int y,
                            double[][] neigh)
An ImageAccess object calls this method for getting a neighborhood arround a pixel position. The neigh parameter should already created. The size of the array determines the neighborhood block.
Mirror border conditions are applied.

The pixel value of (x-n/2, y-n/2) is put into neigh[0][0]
...
The pixel value of (x+n/2, y+n/2) is put into neigh[n-1][n-1]

For example if neigh is a double[4][4]:
The pixel value of (x-1, y-1) is put into neigh[0][0]
The pixel value of (x , y ) is put into neigh[1][1]
The pixel value of (x+1, y+1) is put into neigh[2][2]
The pixel value of (x+2, y+2) is put into neigh[3][3]
...
For example if neigh is a double[5][5]:
The pixel value of (x-2, y-2) is put into neigh[0][0]
The pixel value of (x-1, y-1) is put into neigh[1][1]
The pixel value of (x , y ) is put into neigh[2][2]
The pixel value of (x+1, y+1) is put into neigh[3][3]
The pixel value of (x+2, y+2) is put into neigh[4][4]
Parameters:
x - the integer x-coordinate of a selected central pixel
y - the integer y-coordinate of a selected central pixel
neigh - output, a 2D array s

getPattern

public void getPattern(int x,
                       int y,
                       double[] neigh,
                       int pattern)
An ImageAccess object calls this method for getting a neighborhood of a predefined pattern around a selected pixel (x,y).
The available patterns are:
- a 3*3 block: PATTERN_SQUARE_3x3 (8-connect)
- a 3*3 cross: PATTERN_CROSS_3x3 (4-connect)

Mirror border conditions are applied.
The pixel is arranged in a 1D array according the following rules:

If the pattern is PATTERN_SQUARE_3x3 (8-connect)
The pixel value of (x-1, y-1) are put into neigh[0]
The pixel value of (x , y-1) are put into neigh[1]
The pixel value of (x+1, y-1) are put into neigh[2]
The pixel value of (x-1, y ) are put into neigh[3]
The pixel value of (x , y ) are put into neigh[4]
The pixel value of (x+1, y ) are put into neigh[5]
The pixel value of (x-1, y+1) are put into neigh[6]
The pixel value of (x , y+1) are put into neigh[7]
The pixel value of (x+1, y+1) are put into neigh[8]

If the pattern is PATTERN_CROSS_3x3 (4-connect)
The pixel value of (x , y-1) are put into neigh[0]
The pixel value of (x-1, y ) are put into neigh[1]
The pixel value of (x , y ) are put into neigh[2]
The pixel value of (x+1, y ) are put into neigh[3]
The pixel value of (x , y+1) are put into neigh[4]

The neigh should already created as a double array of 9 elements for the PATTERN_SQUARE_3x3 or 5 elements for the PATTERN_CROSS_3x3.
Parameters:
x - x-coordinate of a selected central pixel
y - y-coordinate of a selected central pixel
neigh - output, an array consisting of 9 or 5 elements
pattern - PATTERN_SQUARE_3x3 or PATTERN_CROSS_3x3.

getSubImage

public void getSubImage(int x,
                        int y,
                        ImageAccess output)
An ImageAccess object calls this method to get a sub-image with the upper left corner in the coordinate (x,y). The sub-image ouptut should be already created.
Parameters:
x - x-coordinate in the source image
y - y-coordinate in the source image
output - an ImageAccess object with the sub-image;

putPixel

public void putPixel(int x,
                     int y,
                     double value)
An ImageAccess object calls this method in order a value of the gray level to be put to a position inside it given by the coordinates.
Parameters:
x - input, the integer x-coordinate of a pixel
y - input, the integer y-coordinate of a pixel
value - input, a value of the gray level of the type double

putColumn

public void putColumn(int x,
                      double[] column)
An ImageAccess object calls this method to put a whole column in a specified position into the image.
Parameters:
x - input, the integer x-coordinate of a column
column - input, an array of the type double

putColumn

public void putColumn(int x,
                      int y,
                      double[] column)
An ImageAccess object calls this method to put a part of column into the image. The starting poisition in given by y and the ending position is determined by the size of the column array.
Parameters:
x - input, the integer x-coordinate of a column
y - input, the integer y-coordinate of a column
column - input, an array of the type double

putRow

public void putRow(int y,
                   double[] row)
An ImageAccess object calls this method to put a whole row in a specified position into the image.
Parameters:
y - input, the integer x-coordinate of a column
row - input, an array of the type double

putRow

public void putRow(int x,
                   int y,
                   double[] row)
An ImageAccess object calls this method to put a part of row into the image. The starting poisition in given by x and the ending position is determined by the size of the row array.
Parameters:
x - input, the integer x-coordinate of a column
y - input, the integer y-coordinate of a column
row - input, an array of the type double

putArrayPixels

public void putArrayPixels(double[][] array)
An ImageAccess object calls this method in order to put an 2D array of double in an ImageAccess.
Parameters:
array - input, the double array

putSubImage

public void putSubImage(int x,
                        int y,
                        ImageAccess input)
An ImageAccess object calls this method to put a sub-image with the upper left corner in the coordinate (x,y). The sub-image input should be already created.
Parameters:
x - x-coordinate in the source image
y - y-coordinate in the source image
input - an ImageAccess object that we want to put;

setConstant

public void setConstant(double constant)
An ImageAccess object calls this method to set a constant value to all pixels of the image.
Parameters:
constant - a constant value

normalizeContrast

public void normalizeContrast()
Stretches the contrast inside an image so that the gray levels are in the range 0 to 255.

show

public void show(java.lang.String title,
                 java.awt.Point loc)
Display an image at a specific position (x, y).
Parameters:
title - a string for the title
loc - Point for the location

show

public void show(java.lang.String title)
Display an image.
Parameters:
title - a string for the title of the window

abs

public void abs()
Compute the absolute value.

sqrt

public void sqrt()
Compute the square root of an ImageAccess.

pow

public void pow(double a)
Raised an ImageAccess object to the power a.
Parameters:
a - input

add

public void add(double constant)
An ImageAccess object calls this method for adding a constant to each pixel.
Parameters:
constant - a constant to be added

multiply

public void multiply(double constant)
An ImageAccess object calls this method for multiplying a constant to each pixel.
Parameters:
constant - a constant to be multiplied

subtract

public void subtract(double constant)
An ImageAccess object calls this method for adding a constant to each pixel.
Parameters:
constant - a constant to be added

divide

public void divide(double constant)
An ImageAccess object calls this method for dividing a constant to each pixel.
Parameters:
constant - a constant to be multiplied

add

public void add(ImageAccess im1,
                ImageAccess im2)
An ImageAccess object calls this method for adding two ImageAccess objects. [this = im1 + im2] The resulting ImageAccess and the two operands should have the same size.
Parameters:
im1 - an ImageAccess object to be added
im2 - an ImageAccess object to be added

multiply

public void multiply(ImageAccess im1,
                     ImageAccess im2)
An ImageAccess object calls this method for multiplying two ImageAccess objects. The resulting ImageAccess and the two operands should have the same size. [this = im1 * im2]
Parameters:
im1 - an ImageAccess object to be multiplied
im2 - an ImageAccess object to be multiplied

subtract

public void subtract(ImageAccess im1,
                     ImageAccess im2)
An ImageAccess object calls this method for subtracting two ImageAccess objects. The resulting ImageAccess and the two operands should have the same size. [this = im1 - im2]
Parameters:
im1 - an ImageAccess object to be subtracted
im2 - an ImageAccess object to be subtracted

divide

public void divide(ImageAccess im1,
                   ImageAccess im2)
An ImageAccess object calls this method for dividing two ImageAccess objects. [this = im1 / im2] The resulting ImageAccess and the two operands should have the same size.
Parameters:
im1 - numerator
im2 - denominator