Class AlgorithmHaralickTexture

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.WindowListener, java.lang.Runnable, java.util.EventListener

    public class AlgorithmHaralickTexture
    extends AlgorithmBase
    DOCUMENT ME!
    Version:
    0.5 September 10, 2009
    Author:
    William Gandler This code is based on the material in the GLCM Texture Tutorial by Myrka Hall-Beyer at http://www.fp.ucalgary.ca/mhallbey/tutorial.htm.

    This code can be used for 2D or 2.5D processing. If optional concatenation is used, then only 1 result image is formed by concatenating the calculated features after the original source. For 3D images the features are selected with the t dimension slider.

    The Haralick features are based on the frequency of occurrence of the pixel intensity values of 2 pixels an offset distance apart. The offset distance will almost always be 1. The frequency of occurrence is counted over a square window which is placed over each pixel interior to a band of width (window size - 1)/2 at the edge of the image, since results are only calculated for pixels over which the entire square window can be placed. The values in this outer band have been left at zero.

    The user selects 1 or more of the 5 direction possibilities and 1 or more of the 14 operator possibilities. The number of floating point Haralick texture images created equals the number of directions selected times the number of operators selected. The result image dimensions are the same as the source window dimensions.

    The five direction possibilities are north-south, northeast-southwest, east-west, southeast-northwest, and spatially invariant. Spatially invariant is created by counting in the four directions and summing the counts.

    The calculations start with the creation of a gray level co-occurrence matrix for each pixel position interior to the outer band for each direction. This matrix gives the probability for each pair of 2 pixels within the square window.

    Data should be rescaled so that the Grey-Level Co-occurrence Matrix is of the appropriate size. Eight bit data has 256 possible values, so the GLCM would be a 256 x 256 matrix, with 65,536 cells. 16 bit data would give a matrix of size 65536 x 65536 = 4,294,967,296 cells, so 16 bit data is too much to handle. There is another reason for compressing the data. If all 256 x 256 (or more) cells were used, there would be many cells filled with zeros (because that combination of grey levels simply does not occur). The GLCM approximates the joint probability distribution of the two pixels. Having many zeros in cells makes this a very bad approximation. If the number of grey levels is reduced, the number of zeros is reduced, and the statistical validity is greatly improved. In "An analysis of co-occurrence texture statistics as a function of grey level quantization" David A. Clausi concludes: "... any value of G greater than 24 is advocated. However, large values of G (greater than 64) are deemed unnecessary since they do not improve the classification accuracy and are computationally costly. Setting G to a value under twenty-four can produce unreliable results." Cluster shade is defined in "Urban and Non Urban Area Classification by Texture Characteristics and Data Fusion" by D. I. Morales, M. Moctezuma, and F. Parmiggiani. Shade and promenance are defined in "Improving Co-occurrence Matrix Feature Discrimination" by Ross F. Walker, Paul Jackway, and I. D. Longstaff.
    • Field Detail

      • asm

        private boolean asm
        If true calculate angular second moment Sum over i,j of Probability(i,j) * Probability(i,j).
      • contrast

        private boolean contrast
        If true calculate contrast, also known as sum of squares variance Sum over i,j of Probability(i,j) * (i-j) * (i-j).
      • correlation

        private boolean correlation
        If true calculate glcm correlation Sum over i,j of Probability(i,j) * (i - glcm mean) * (j - glcm mean)/ glcm variance.
      • destImage

        private ModelImage[] destImage
        DOCUMENT ME!
      • dissimilarity

        private boolean dissimilarity
        If true calculate dissimilarity Sum over i,j of Probability(i,j) * Absolute value(i-j).
      • energy

        private boolean energy
        If true calculate energy Energy = square root(asm).
      • entropy

        private boolean entropy
        If true calcuate entropy Sum over i,j of -Probability(i,j) * ln(Probability(i,j)).
      • ew

        private boolean ew
        If true east-west direction calculated.
      • homogeneity

        private boolean homogeneity
        If true calculate homogeneity, also called the Inverse Difference Moment of Order 2 Sum over i,j of Probability(i,j)/(1 + (i-j)*(i-j)).
      • invariantDir

        private boolean invariantDir
        If true spatially invariant direction calculated. This is created by counting in the 4 directions and summing the counts.
      • inverseOrder1

        private boolean inverseOrder1
        If true calculate inverse difference moment of order 1 Sum over i,j of Probability(i,j)/(1 + abs(i-j)).
      • maxProbability

        private boolean maxProbability
        If true calculate maximum probability maximum probability is the largest probability value within the window.
      • mean

        private boolean mean
        If true calculate gray level co-occurrence matrix mean Sum over i,j of i * Probability(i,j) = Sum over i,j of j * Probability(i,j).
      • nesw

        private boolean nesw
        If true northeast-southwest direction calculated.
      • ns

        private boolean ns
        If true north-south direction calculated.
      • offsetDistance

        private int offsetDistance
        Distance between the 2 pixels in the pair - almost always 1.
      • senw

        private boolean senw
        If true southeast-northwest direction calculated.
      • standardDeviation

        private boolean standardDeviation
        If true calculate glcm standard deviation glcm standard deviation = square root(glcm variance).
      • variance

        private boolean variance
        If true calculate glcm variance Sum over i,j of Probability(i,j) * (i - glcm mean) * (i - glcm mean) = Sum over i,j of Probability(i,j) * (j - glcm mean) * (j - glcm mean).
      • shade

        private boolean shade
        If true calculate the cluster shade Sum over i,j of ((i + j - x mean - y mean)**3) * Probability(i,j) For the symmetrical glcm x mean = y mean = glcm mean Sum over i,j over ((i + j - 2 * glcm mean)**3) * Probability(i,j) It is a measure of the degree to which the outliers in the histogram favor one side or another of the statistical mean.
      • promenance

        private boolean promenance
        If true calculate the cluster promenance Sum over i,j of ((i + j - x mean - y mean)**4) * Probability(i,j) For the symmetrical glcm x mean = y mean = glcm mean Sum over i,j of ((i + j - 2 * glcm mean)**4) * Probability(i,j)
      • concatenate

        private boolean concatenate
        If true, form only 1 result image by concatenating the original source to each of the calculated features.
      • zscore

        private boolean zscore
        If true, produce zscore output. zscore = (value - mean)/(standard deviation)
      • windowSize

        private int windowSize
        Size of square window used in calculating each glcm matrix - must be an odd number.
      • greyLevels

        private int greyLevels
        Number of grey levels used if rescaling performed.
      • RGBOffset

        private int RGBOffset
    • Constructor Detail

      • AlgorithmHaralickTexture

        public AlgorithmHaralickTexture​(ModelImage[] destImg,
                                        ModelImage srcImg,
                                        int windowSize,
                                        int offsetDistance,
                                        int greyLevels,
                                        boolean ns,
                                        boolean nesw,
                                        boolean ew,
                                        boolean senw,
                                        boolean invariantDir,
                                        boolean contrast,
                                        boolean dissimilarity,
                                        boolean homogeneity,
                                        boolean inverseOrder1,
                                        boolean asm,
                                        boolean energy,
                                        boolean maxProbability,
                                        boolean entropy,
                                        boolean mean,
                                        boolean variance,
                                        boolean standardDeviation,
                                        boolean correlation,
                                        boolean shade,
                                        boolean promenance,
                                        boolean concatenate,
                                        boolean zscore)
        Creates a new AlgorithmHaralickTexture object for black and white image.
        Parameters:
        destImg - image model where result image is to stored
        srcImg - source image model
        windowSize - the size of the square window
        offsetDistance - distance between 2 pixels of pair
        greyLevels - Number of grey levels used if rescaling performed
        ns - true if north south offset direction calculated
        nesw - true if northeast-southwest offset direction calculated
        ew - true if east west offset direction calculated
        senw - true if southeast-northwest offset direction calculated
        invariantDir - true if spatially invariant calculated
        contrast - true if contrast calculated
        dissimilarity - true if dissimilarity calculated
        homogeneity - true if homogeneity calculated
        inverseOrder1 - true if inverse difference moment of order 1 calculated
        asm - true if angular second moment calculated
        energy - true if energy calculated
        maxProbability - true if maximum probability calculated
        entropy - true if entropy calculated
        mean - true if gray level coordinate matrix mean calculated
        variance - true if gray level coordinate matrix variance calculated
        standardDeviation - true if gray level coordinate matrix standard deviation calculated
        correlation - true if gray level coordinate matrix correlation calculated
        shade - true if cluster shade calculated
        promenance - true if cluster promenance calculated
        concatenate - If true, only 1 result image formed by concatenating the original source to each of the calculated features
        zscore - If true, produce z score output
      • AlgorithmHaralickTexture

        public AlgorithmHaralickTexture​(ModelImage[] destImg,
                                        ModelImage srcImg,
                                        int RGBOffset,
                                        int windowSize,
                                        int offsetDistance,
                                        int greyLevels,
                                        boolean ns,
                                        boolean nesw,
                                        boolean ew,
                                        boolean senw,
                                        boolean invariantDir,
                                        boolean contrast,
                                        boolean dissimilarity,
                                        boolean homogeneity,
                                        boolean inverseOrder1,
                                        boolean asm,
                                        boolean energy,
                                        boolean maxProbability,
                                        boolean entropy,
                                        boolean mean,
                                        boolean variance,
                                        boolean standardDeviation,
                                        boolean correlation,
                                        boolean shade,
                                        boolean promenance,
                                        boolean concatenate,
                                        boolean zscore)
        Creates a new AlgorithmHaralickTexture object for color image.
        Parameters:
        destImg - image model where result image is to stored
        srcImg - source image model
        RGBOffset - selects red, green, or blue channel
        windowSize - the size of the square window
        offsetDistance - distance between 2 pixels of pair
        greyLevels - Number of grey levels used if rescaling performed
        ns - true if north south offset direction calculated
        nesw - true if northeast-southwest offset direction calculated
        ew - true if east west offset direction calculated
        senw - true if southeast-northwest offset direction calculated
        invariantDir - true if spatially invariant calculated
        contrast - true if contrast calculated
        dissimilarity - true if dissimilarity calculated
        homogeneity - true if homogeneity calculated
        inverseOrder1 - true if inverse difference moment of order 1 calculated
        asm - true if angular second moment calculated
        energy - true if energy calculated
        maxProbability - true if maximum probability calculated
        entropy - true if entropy calculated
        mean - true if gray level coordinate matrix mean calculated
        variance - true if gray level coordinate matrix variance calculated
        standardDeviation - true if gray level coordinate matrix standard deviation calculated
        correlation - true if gray level coordinate matrix correlation calculated
        shade - true if cluster shade calculated
        promenance - true if cluster promenance calculated
        concatenate - If true, only 1 result image formed by concatenating the original source to each of the calculated features
        zscore - If true, produce z score output
    • Method Detail

      • finalize

        public void finalize()
        Prepares this class for destruction.
        Overrides:
        finalize in class AlgorithmBase
      • calculateHaralick

        private void calculateHaralick()
        DOCUMENT ME!