Class AlgorithmHaralickTexture
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.filters.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 Summary
Fields Modifier and Type Field Description private boolean
asm
If true calculate angular second moment Sum over i,j of Probability(i,j) * Probability(i,j).private boolean
concatenate
If true, form only 1 result image by concatenating the original source to each of the calculated features.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).private boolean
correlation
If true calculate glcm correlation Sum over i,j of Probability(i,j) * (i - glcm mean) * (j - glcm mean)/ glcm variance.private ModelImage[]
destImage
DOCUMENT ME!private boolean
dissimilarity
If true calculate dissimilarity Sum over i,j of Probability(i,j) * Absolute value(i-j).private boolean
energy
If true calculate energy Energy = square root(asm).private boolean
entropy
If true calcuate entropy Sum over i,j of -Probability(i,j) * ln(Probability(i,j)).private boolean
ew
If true east-west direction calculated.private int
greyLevels
Number of grey levels used if rescaling performed.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)).private boolean
invariantDir
If true spatially invariant direction calculated.private boolean
inverseOrder1
If true calculate inverse difference moment of order 1 Sum over i,j of Probability(i,j)/(1 + abs(i-j)).private boolean
maxProbability
If true calculate maximum probability maximum probability is the largest probability value within the window.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).private boolean
nesw
If true northeast-southwest direction calculated.private boolean
ns
If true north-south direction calculated.private int
offsetDistance
Distance between the 2 pixels in the pair - almost always 1.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)private static int
RED_OFFSET
Red channel.private int
RGBOffset
private boolean
senw
If true southeast-northwest direction calculated.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.private boolean
standardDeviation
If true calculate glcm standard deviation glcm standard deviation = square root(glcm 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).private int
windowSize
Size of square window used in calculating each glcm matrix - must be an odd number.private boolean
zscore
If true, produce zscore output.-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description 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.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
calculateHaralick()
DOCUMENT ME!void
finalize()
Prepares this class for destruction.void
runAlgorithm()
Starts the program.-
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
RED_OFFSET
private static final int RED_OFFSET
Red channel.- See Also:
- Constant Field Values
-
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 storedsrcImg
- source image modelwindowSize
- the size of the square windowoffsetDistance
- distance between 2 pixels of pairgreyLevels
- Number of grey levels used if rescaling performedns
- true if north south offset direction calculatednesw
- true if northeast-southwest offset direction calculatedew
- true if east west offset direction calculatedsenw
- true if southeast-northwest offset direction calculatedinvariantDir
- true if spatially invariant calculatedcontrast
- true if contrast calculateddissimilarity
- true if dissimilarity calculatedhomogeneity
- true if homogeneity calculatedinverseOrder1
- true if inverse difference moment of order 1 calculatedasm
- true if angular second moment calculatedenergy
- true if energy calculatedmaxProbability
- true if maximum probability calculatedentropy
- true if entropy calculatedmean
- true if gray level coordinate matrix mean calculatedvariance
- true if gray level coordinate matrix variance calculatedstandardDeviation
- true if gray level coordinate matrix standard deviation calculatedcorrelation
- true if gray level coordinate matrix correlation calculatedshade
- true if cluster shade calculatedpromenance
- true if cluster promenance calculatedconcatenate
- If true, only 1 result image formed by concatenating the original source to each of the calculated featureszscore
- 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 storedsrcImg
- source image modelRGBOffset
- selects red, green, or blue channelwindowSize
- the size of the square windowoffsetDistance
- distance between 2 pixels of pairgreyLevels
- Number of grey levels used if rescaling performedns
- true if north south offset direction calculatednesw
- true if northeast-southwest offset direction calculatedew
- true if east west offset direction calculatedsenw
- true if southeast-northwest offset direction calculatedinvariantDir
- true if spatially invariant calculatedcontrast
- true if contrast calculateddissimilarity
- true if dissimilarity calculatedhomogeneity
- true if homogeneity calculatedinverseOrder1
- true if inverse difference moment of order 1 calculatedasm
- true if angular second moment calculatedenergy
- true if energy calculatedmaxProbability
- true if maximum probability calculatedentropy
- true if entropy calculatedmean
- true if gray level coordinate matrix mean calculatedvariance
- true if gray level coordinate matrix variance calculatedstandardDeviation
- true if gray level coordinate matrix standard deviation calculatedcorrelation
- true if gray level coordinate matrix correlation calculatedshade
- true if cluster shade calculatedpromenance
- true if cluster promenance calculatedconcatenate
- If true, only 1 result image formed by concatenating the original source to each of the calculated featureszscore
- If true, produce z score output
-
-
Method Detail
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalize
in classAlgorithmBase
-
runAlgorithm
public void runAlgorithm()
Starts the program.- Specified by:
runAlgorithm
in classAlgorithmBase
-
calculateHaralick
private void calculateHaralick()
DOCUMENT ME!
-
-