org.yccheok.numrecognition
Class NumberImageProcessor

java.lang.Object
  extended by org.yccheok.numrecognition.NumberImageProcessor

public class NumberImageProcessor
extends java.lang.Object

The NumberImageProcessor class is image of a number character. This class provides all the functionality of image processing on a number image.


Field Summary
private static int COLOR_BACKGROUND
          Color of foreground.
private static int COLOR_FOREGROUND
          Color of foreground.
private  ij.ImagePlus imagePlus
          ImageJ ImagePlus.
 
Constructor Summary
NumberImageProcessor(ij.ImagePlus imagePlus)
          Constructs a number image object based on ImageJ image data type.
NumberImageProcessor(java.lang.String fileName)
          Constructs a number image object by opening image file.
 
Method Summary
 void clear(ROI roi)
          Clears the region within ROI.
 void close()
          Performs morphological close.
 void dilate()
          Performs morphological dilate.
 float[] getAreas()
          Get the area of all the objects.
 ROI[] getBlobROIs()
          Get the ROI of all the objects.
 NumberImageProcessorList getBlobs()
          Get blobs in NumberImageProcessorList.
 int[] getBottomProfiles()
          Get the bottom profiles
private  ChainCode getChainCode(int x, int y, int code, Mark[] mark, ChainCode cc)
          The chain code is using the following conventional:
4 5 6
3 x 7
2 1 8
This is a recursive called helper method.
 java.util.List getChainCodes()
          Gets the chain code of this number image.
 int getHeight()
          Returns height of the image.
 int[] getHeightProfiles()
          Get height profiles
 int[][] getHistogram()
          Get the histogram of an image.
 int[] getHorizontalProjectionHistogram()
          Get the horizontal projection histogram.
 int[][] getHSBHistogram()
          Get the histogram of a color image in HSB color model.
 int[] getLeftProfiles()
          Get the left profiles.
 int getNumberOfBlob()
          Get the number of objects within the whole image.
 int getNumOfStartingPoint()
          How many starting points within the whole image.
 int[] getPixels()
          Returns pixels of the image.
 int[] getRightProfiles()
          Get the right profiles.
 java.util.List getSortedBlobs(int maxXDistanceOfNextDigit)
          Get blobs in list of NumberImageProcessorList.
 int[] getTopProfiles()
          Get the top profiles
 int[] getVerticalProjectionHistogram()
          Get the vertical projection histogram.
 int getWidth()
          Returns width of the image.
 int[] getWidthProfiles()
          Get width profiles.
 boolean isStartingPoint(int x, int y)
          This method is used to determine whether a given point is a starting point.
 void save(java.lang.String fileName)
          Save the image.
 boolean savePBM(java.lang.String fileName)
          Save image in PBM format.
 void scale(double scale)
          Performs image scaling.
 void scale(double scaleX, double scaleY)
          Performs image scaling.
 void setROI(ROI roi)
          Set the ROI of an image.
 void skeletonize()
          Performs thinning (skeletonize).
 void threshold()
          Performs image auto thresholding.
 void threshold(int lowThreshold, int highThreshold)
          Performs image thresholding.
 void to8Bit()
          Performs 8 bit conversion.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

imagePlus

private ij.ImagePlus imagePlus
ImageJ ImagePlus.


COLOR_FOREGROUND

private static final int COLOR_FOREGROUND
Color of foreground. We assume it is black.

See Also:
Constant Field Values

COLOR_BACKGROUND

private static final int COLOR_BACKGROUND
Color of foreground. We assume it is white.

See Also:
Constant Field Values
Constructor Detail

NumberImageProcessor

public NumberImageProcessor(ij.ImagePlus imagePlus)
Constructs a number image object based on ImageJ image data type.

Parameters:
imagePlus - ImageJ image data type.

NumberImageProcessor

public NumberImageProcessor(java.lang.String fileName)
Constructs a number image object by opening image file.

Parameters:
fileName - File name of the image.
Method Detail

threshold

public void threshold(int lowThreshold,
                      int highThreshold)
Performs image thresholding.

Parameters:
lowThreshold - Low thresholding value.
highThreshold - High thresholding value.

threshold

public void threshold()
Performs image auto thresholding.


save

public void save(java.lang.String fileName)
Save the image. Please note that if this number image has been saved before and no modification had been done on this number image, calling this method will have no effect.

Parameters:
fileName - Name of the file to be saved.

scale

public void scale(double scale)
Performs image scaling.

Parameters:
scale - x and y scaling.

scale

public void scale(double scaleX,
                  double scaleY)
Performs image scaling.

Parameters:
scaleX - x scaling.
scaleY - y scaling.

skeletonize

public void skeletonize()
Performs thinning (skeletonize).


dilate

public void dilate()
Performs morphological dilate.


close

public void close()
Performs morphological close.


clear

public void clear(ROI roi)
Clears the region within ROI.

Parameters:
roi - ROI to be cleared.

getChainCodes

public java.util.List getChainCodes()
Gets the chain code of this number image.

Returns:
Chain code of this number image.

getChainCode

private ChainCode getChainCode(int x,
                               int y,
                               int code,
                               Mark[] mark,
                               ChainCode cc)
The chain code is using the following conventional:
4 5 6
3 x 7
2 1 8
This is a recursive called helper method. It should be exported (public).

Parameters:
x - Current x coordinate.
y - Current y coordinate.
code - Code represents current coordinate. 0 if this is a starting point.
mark - Whether this position has been visited before.
cc - The chain code.
Returns:
The chain code. If there are no blob, null will be returned. If there is only single pixel, chain code with 0 size will be returned. Else, a chain code with size >0 will be returned.

isStartingPoint

public boolean isStartingPoint(int x,
                               int y)
This method is used to determine whether a given point is a starting point. Starting point means a pixel with only one or no neighbour (8-connectivity-pixel).

Parameters:
x - x coordinate of the test pixel.
y - y coordinate of the test pixel.
Returns:
Whether a given point is a starting point.

getNumOfStartingPoint

public int getNumOfStartingPoint()
How many starting points within the whole image.

Returns:
Number of starting points within the whole image.

to8Bit

public void to8Bit()
Performs 8 bit conversion.


getNumberOfBlob

public int getNumberOfBlob()
Get the number of objects within the whole image.

Returns:
Number of objects (blobs).

getAreas

public float[] getAreas()
Get the area of all the objects.

Returns:
Area of all the objects.

getBlobROIs

public ROI[] getBlobROIs()
Get the ROI of all the objects.

Returns:
ROI of all the objects.

setROI

public void setROI(ROI roi)
Set the ROI of an image. Once the ROI had been set, a new image will be created. It cannot be undo.

Parameters:
roi - ROI to be set.

getWidth

public int getWidth()
Returns width of the image.

Returns:
Width of the image.

getHeight

public int getHeight()
Returns height of the image.

Returns:
The height of the image.

getPixels

public int[] getPixels()
Returns pixels of the image.

Returns:
Array of pixel in int.

savePBM

public boolean savePBM(java.lang.String fileName)
Save image in PBM format.

Parameters:
fileName - Name of the file to be saved.
Returns:
Whether the operation is successful.

getRightProfiles

public int[] getRightProfiles()
Get the right profiles.

Returns:
Right profiles.

getLeftProfiles

public int[] getLeftProfiles()
Get the left profiles.

Returns:
Left profiles.

getTopProfiles

public int[] getTopProfiles()
Get the top profiles

Returns:
Top profiles

getBottomProfiles

public int[] getBottomProfiles()
Get the bottom profiles

Returns:
Bottom profiles.

getHorizontalProjectionHistogram

public int[] getHorizontalProjectionHistogram()
Get the horizontal projection histogram.

Returns:
Horizontal projection histogram.

getVerticalProjectionHistogram

public int[] getVerticalProjectionHistogram()
Get the vertical projection histogram.

Returns:
Vertical projection histogram.

getWidthProfiles

public int[] getWidthProfiles()
Get width profiles.

Returns:
Width profiles.

getHeightProfiles

public int[] getHeightProfiles()
Get height profiles

Returns:
Height profiles.

getBlobs

public NumberImageProcessorList getBlobs()
Get blobs in NumberImageProcessorList.

Returns:
NumberImageProcessorList.

getSortedBlobs

public java.util.List getSortedBlobs(int maxXDistanceOfNextDigit)
Get blobs in list of NumberImageProcessorList. The each element in NumberImageProcessorList will be sorted from left to right, from top to bottom. If a blob's x distance with its previous neighbour > maxXDistanceOfNextDigit, it will begin allocated in a new NumberImageProcessorList.

Parameters:
maxXDistanceOfNextDigit - Maximum distance among the digits within a single number.
Returns:
List of NumberImageProcessorList in left to right, top to bottom sorted order. User may view the elements of NumberImageProcessorList as a number consists of multiple digits.

getHSBHistogram

public int[][] getHSBHistogram()
Get the histogram of a color image in HSB color model. If the image is a non-color color image, 0 size array will be returned. If the image is color image, an array int[3][255] will be returned.

Returns:
The histogram of a color image in HSB color model.

getHistogram

public int[][] getHistogram()
Get the histogram of an image. This implementation is slightly different from the default implementation of ImageJ, where it will take the average value of RGB. In our case, we do a special threatment on color image. We will get the histogram for each channel and return array int[3][255]. If the image is non-color image, array int[1][255] will be returned.

Returns:
The histogram of an image.