Class HTPprocessor

java.lang.Object
  extended by HTPprocessor

public class HTPprocessor
extends java.lang.Object

HTPprocessor
Contains all methods which are used for the image classification process.


Constructor Summary
HTPprocessor()
           
 
Method Summary
 boolean allPixelsOnTheCircleAroundXYAreInTheSameClass(int[][] CLASSES, int radius, int x, int y)
          Tests whether all pixel on a circle around point (x,y) with given radius are of the same class.
 void classifyByColorRange(ij.ImagePlus img, int[][] CLASSES, java.util.ArrayList<int[]> colorRanges, int classNumber)
          Wrapper for the method classifyByColorRange.
 void classifyByColorRange(ij.ImagePlus img, int[][] CLASSES, java.util.Hashtable<java.lang.String,java.util.ArrayList<int[]>> color2class, java.util.Hashtable<java.lang.String,java.lang.Integer> class2number, java.lang.String[] allowedClasses, java.util.Hashtable<java.lang.String,java.lang.String> currentRegion)
          Classifies the image according to given colour regions.
 void classifyByColorRange(ij.ImagePlus img, int[][] CLASSES, int[] colorRange, int classNumber)
          Classifies all pixel of the image according to the given colour range, marked as classified in the CLASSES classification array for a specified class.
 double EuclideanDistance_PixelToClass_HSV(ij.ImagePlus imgRGB, int x1, int y1, int[] colorRange)
          Calculates the Euclidean distance of a pixel to the specified HSV colour range.
 double EuclideanDistance_PixelToClass_RGBHSV(ij.ImagePlus imgRGB, int x, int y, int[] colorRange)
          Calculates the Euclidean distance of a pixel to the specified RGB and HSV colour range.
 double EuclideanDistance_PixelToPixel_RGBHSV(ij.ImagePlus imgRGB, int x1, int y1, int x2, int y2)
          Calculates the Euclidean distance between two pixels.
 void fillSingleHoles(int[][] CLASSES)
          Wrapper for the method fillSingleHoles.
 void fillSingleHoles(int[][] CLASSES, int radius)
          Classifies a pixel (x,y) if all neighbours on a circle around (x,y) are in the same class.
 ij.ImagePlus getEmptyImageCopy(ij.ImagePlus img)
          Returns a new, empty image of identical dimensions.
 ij.ImagePlus getImageCopy(ij.ImagePlus img)
          Returns a copy of the image.
 ij.ImagePlus getImageCopyHSV(ij.ImagePlus img)
          Creates the HSV copy of an RGB image.
 boolean pixelIsInHSVRange(ij.ImagePlus img, int col, int row, int[] range)
          Checks whether the HSV colour values of a pixel are within a certain colour range.
 boolean pixelIsInRange(ij.ImagePlus img, int col, int row, int[] range)
          Checks whether the colour values of a pixel are within a certain colour range.
 boolean pixelIsInRGBHSVRange(ij.ImagePlus img, int col, int row, int[] range)
          Checks whether the RGB and HSV coulor values of a pixel are within a certain colour range.
 boolean pixelIsInRGBRange(ij.ImagePlus img, int col, int row, int[] range)
          Checks whether the RGB colour values of a pixel are within a certain colour range.
 void removeNonConnectedClassClusters(int[][] CLASSES, int classNumber, int radiusOne, int radiusTwo)
          Removes non-connected cluster of a specified class depending on two specified circumcircle.
 void removeSinglePixels(int[][] CLASSES, int threshold)
          Removes pixel which neighbourhood of 8 pixel does not contain at least the given number of pixel in the same class.
 void RGBSimilarity(ij.ImagePlus img, int[][] CLASSES)
          Classifies the remaining pixel according to their local neighbourhood and the Euclidean distance to those neighbours.
 int RGBtoHSV(int RGB)
          Provides RGB to HSV conversion for a single RGB value.
 int[] RGBtoHSV(int[] RGB)
          Provides RGB to HSV conversion for a RGB array.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTPprocessor

public HTPprocessor()
Method Detail

RGBtoHSV

public int[] RGBtoHSV(int[] RGB)
Provides RGB to HSV conversion for a RGB array.

Parameters:
RGB - An Array of RGB colour values.
Returns:
An Array of HSV colour values.

RGBtoHSV

public int RGBtoHSV(int RGB)
Provides RGB to HSV conversion for a single RGB value.

Parameters:
RGB - A single RGB colour values.
Returns:
A single HSV colour values.

pixelIsInRange

public boolean pixelIsInRange(ij.ImagePlus img,
                              int col,
                              int row,
                              int[] range)
Checks whether the colour values of a pixel are within a certain colour range.

Parameters:
img - An ImagePlus object containing the original image.
col - The column which defines the position of an pixel in the image.
row - The row which defines the position of an pixel in the image.
range - An Array containing the minimal and maximal colour values for RGB and HSV.
Returns:
false

pixelIsInRGBRange

public boolean pixelIsInRGBRange(ij.ImagePlus img,
                                 int col,
                                 int row,
                                 int[] range)
Checks whether the RGB colour values of a pixel are within a certain colour range.

Parameters:
img - An ImagePlus object containing the original image.
col - The column which defines the position of an pixel in the image.
row - The row which defines the position of an pixel in the image.
range - An Array containing the minimal and maximal colour values for RGB.
Returns:
false

pixelIsInRGBHSVRange

public boolean pixelIsInRGBHSVRange(ij.ImagePlus img,
                                    int col,
                                    int row,
                                    int[] range)
Checks whether the RGB and HSV coulor values of a pixel are within a certain colour range.

Parameters:
img - An ImagePlus object containing the original image.
col - The column which defines the position of an pixel in the image.
row - The row which defines the position of an pixel in the image.
range - An Array containing the minimal and maximal colour values for RGB and HSV.
Returns:
false

pixelIsInHSVRange

public boolean pixelIsInHSVRange(ij.ImagePlus img,
                                 int col,
                                 int row,
                                 int[] range)
Checks whether the HSV colour values of a pixel are within a certain colour range.

Parameters:
img - An ImagePlus object containing the original image.
col - The column which defines the position of an pixel in the image.
row - The row which defines the position of an pixel in the image.
range - An Array containing the minimal and maximal colour values for HSV.
Returns:
false

getImageCopy

public ij.ImagePlus getImageCopy(ij.ImagePlus img)
Returns a copy of the image.

Parameters:
img - An ImagePlus object.
Returns:
An copy of the ImagePlus object.

getEmptyImageCopy

public ij.ImagePlus getEmptyImageCopy(ij.ImagePlus img)
Returns a new, empty image of identical dimensions.

Parameters:
img - An ImagePlus object.
Returns:
An empty ImagePlus object.

getImageCopyHSV

public ij.ImagePlus getImageCopyHSV(ij.ImagePlus img)
Creates the HSV copy of an RGB image.

Parameters:
img - An ImagePlus object.
Returns:
An copy of the ImagePlus object in HSV.

EuclideanDistance_PixelToClass_RGBHSV

public double EuclideanDistance_PixelToClass_RGBHSV(ij.ImagePlus imgRGB,
                                                    int x,
                                                    int y,
                                                    int[] colorRange)
Calculates the Euclidean distance of a pixel to the specified RGB and HSV colour range.

Parameters:
imgRGB - An ImagePlus object of RGB colour values.
x - The column which defines the position of an pixel in the image.
y - The row which defines the position of an pixel in the image.
colorRange - An Array containing the minimal and maximal colour values for RGB and HSV.
Returns:
The Euclidean distance of a pixel to the specified RGB and HSV colour range.

EuclideanDistance_PixelToClass_HSV

public double EuclideanDistance_PixelToClass_HSV(ij.ImagePlus imgRGB,
                                                 int x1,
                                                 int y1,
                                                 int[] colorRange)
Calculates the Euclidean distance of a pixel to the specified HSV colour range.

Parameters:
imgRGB - An ImagePlus object of RGB colour values.
x - The column which defines the position of an pixel in the image.
y - The row which defines the position of an pixel in the image.
colorRange - An Array containing the minimal and maximal colour values for HSV.
Returns:
The Euclidean distance of a pixel to the specified HSV colour range.

EuclideanDistance_PixelToPixel_RGBHSV

public double EuclideanDistance_PixelToPixel_RGBHSV(ij.ImagePlus imgRGB,
                                                    int x1,
                                                    int y1,
                                                    int x2,
                                                    int y2)
Calculates the Euclidean distance between two pixels.

Parameters:
imgRGB - An ImagePlus object of RGB colour values.
x1 - The column which defines the position of an pixel in the image.
y1 - The row which defines the position of an pixel in the image.
x2 - The column which defines the position of another pixel in the image.
y2 - The row which defines the position of another pixel in the image.
Returns:
The Euclidean distance of a pixel to the specified RGB and HSV colour range.

RGBSimilarity

public void RGBSimilarity(ij.ImagePlus img,
                          int[][] CLASSES)
Classifies the remaining pixel according to their local neighbourhood and the Euclidean distance to those neighbours.

Parameters:
img - An ImagePlus object.
CLASSES - A 2-dimensional Array containing the colour classification information for each pixel in the image.

Pseudo-code:
        forall pixels p
         if (p is already classified) continue;
         forall neighbours n of p, that are at worst "searchRadius" away
         keep track of the number of occurences of each class;
         remember the neighbour with the lowest RGBHSV distance to p,
              but never choose plant over anything else;
         endfor;
         if ( most frequent neighbour class       == plant &&
                 class with smallest RGB distance == plant &&
                 smallest RGB distance                    <= 150 )   classify p as "plant";
         else if ( class with smallest RGB distance != plant )
              classify p as smallest-RGB-distance-class;
     endfor;
 
Future improvement is to fine tune the decision process (e.g. consider the most frequent neighbour).

fillSingleHoles

public void fillSingleHoles(int[][] CLASSES)
Wrapper for the method fillSingleHoles.

Parameters:
CLASSES - A 2-dimensional Array containing the colour classification information for each pixel in the image.

fillSingleHoles

public void fillSingleHoles(int[][] CLASSES,
                            int radius)
Classifies a pixel (x,y) if all neighbours on a circle around (x,y) are in the same class.

Parameters:
CLASSES - A 2-dimensional Array containing the colour classification information for each pixel in the image.
radius - An Integer which defines a radius of a circle.

Pseudo-code:
  forall pixels p
      if (p is already classified) continue;
      if (all pixel on the circle around p are of the same class)
          classify p accordingly;
  endfor;
 

allPixelsOnTheCircleAroundXYAreInTheSameClass

public boolean allPixelsOnTheCircleAroundXYAreInTheSameClass(int[][] CLASSES,
                                                             int radius,
                                                             int x,
                                                             int y)
Tests whether all pixel on a circle around point (x,y) with given radius are of the same class.

Parameters:
CLASSES - A 2-dimensional Array containing the colour classification information for each pixel in the image.
radius - An Integer which defines a radius of a circle.
x - The column which defines the position of an pixel in the image.
y - The row which defines the position of an pixel in the image.
Returns:
true

removeSinglePixels

public void removeSinglePixels(int[][] CLASSES,
                               int threshold)
Removes pixel which neighbourhood of 8 pixel does not contain at least the given number of pixel in the same class.

Parameters:
CLASSES - A 2-dimensional Array containing the colour classification information for each pixel in the image.
threshold - Defines the allowed number of neighbours to keep this pixel classified.

removeNonConnectedClassClusters

public void removeNonConnectedClassClusters(int[][] CLASSES,
                                            int classNumber,
                                            int radiusOne,
                                            int radiusTwo)
Removes non-connected cluster of a specified class depending on two specified circumcircle.

Parameters:
CLASSES - A 2-dimensional Array containing the colour classification information for each pixel in the image.
classNumber - An Integer containing the number of the class.
radiusOne - An Integer which defines a radius of a circle.
radiusTwo - An Integer which defines a radius of another circle.

classifyByColorRange

public void classifyByColorRange(ij.ImagePlus img,
                                 int[][] CLASSES,
                                 int[] colorRange,
                                 int classNumber)
Classifies all pixel of the image according to the given colour range, marked as classified in the CLASSES classification array for a specified class.

Parameters:
img - An ImagePlus object.
CLASSES - A 2-dimensional Array containing the colour classification information for each pixel in the image.
colorRange - An Array containing the minimal and maximal colour values for RGB and HSV.
classNumber - An Integer containing the number of the class.

classifyByColorRange

public void classifyByColorRange(ij.ImagePlus img,
                                 int[][] CLASSES,
                                 java.util.ArrayList<int[]> colorRanges,
                                 int classNumber)
Wrapper for the method classifyByColorRange.

Parameters:
img - An ImagePlus object.
CLASSES - A 2-dimensional Array containing the colour classification information for each pixel in the image.
colorRange - An ArrayList containing the minimal and maximal colour values for RGB and HSV of all color range arrays.
classNumber - An Integer containing the number of the class.

classifyByColorRange

public void classifyByColorRange(ij.ImagePlus img,
                                 int[][] CLASSES,
                                 java.util.Hashtable<java.lang.String,java.util.ArrayList<int[]>> color2class,
                                 java.util.Hashtable<java.lang.String,java.lang.Integer> class2number,
                                 java.lang.String[] allowedClasses,
                                 java.util.Hashtable<java.lang.String,java.lang.String> currentRegion)
Classifies the image according to given colour regions.

Parameters:
img - An ImagePlus object.
CLASSES - A 2-dimensional Array containing the colour classification information for each pixel in the image.
color2class - A Hashtable of colour values for each class.
class2number - A Hashtable of numbers for each class.
allowedClasses - A Array of classes to be classified (if null all classes are classified).
currentRegion - A Hashtable to limit the classification process to the given region (if null whole image is classified).