Package gov.nih.mipav.model.algorithms
Class AlgorithmHistogram
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.AlgorithmHistogram
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmHistogram extends AlgorithmBase
Calculates the histogram for an image. The number of bins is determined by the extents of the histogram model. The calling algorithm can specify if the histogram is to be calculated for whole image or only over VOI regions. The Otsu and Maximum Entrophy thresholds are also automatically calculated and stored in the ModelHistogram structure. The Otsu and Max entropy can take time (minutes) to calculate for histgrams with bins larger than (10,000).- Version:
- 0.1 September 18, 1997
- See Also:
ModelHistogram
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
AlgorithmHistogram.GrayLevelClass
Used specifally by the Otsu threshold algorithm to define a gray level object for calculating probabilities.
-
Field Summary
Fields Modifier and Type Field Description private boolean
dataOutput
Flag indicating whether or not histogram data is output to the data window.private boolean
displayGraph
private boolean
entireImage
If true the histogram should be calculated for the entire image.private double[]
highValue
DOCUMENT ME!private int[]
histoBuffer
DOCUMENT ME!private ModelHistogram
histogram
Reference to the histogram storage object.private ModelImage
image
Reference to the image.private double[]
lowValue
DOCUMENT ME!private int
processMode
private int
RGBOffset
Indicates which channel of the RGB image the histogram should be calculated. 1 = Red channel 2 = Green channel 3 = Blue channelprivate static int
SEPARATE_VOIS
private int
summaryBins
Used to indicate the number of histogram bins when using the constructors that do NOT pass in the histogram object.private static int
TOTAL_VOIS
private boolean
userLimits
private double
userMax
private double
userMin
private static int
WHOLE_IMAGE
-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmHistogram(ModelHistogram histogram, int RGBOffset, ModelImage image, boolean maskFlag)
Constructs the histogram calculation object for an RGB image.AlgorithmHistogram(ModelHistogram histogram, ModelImage image, boolean maskFlag)
Constructs the histogram calculation object.AlgorithmHistogram(ModelImage image, int summaryBins)
Constructs the histogram calculation object for an image.AlgorithmHistogram(ModelImage image, int summaryBins, boolean maskFlag)
Constructs the histogram calculation object for an image.AlgorithmHistogram(ModelImage image, int summaryBins, boolean maskFlag, boolean displayGraph, boolean userLimits, double userMin, double userMax)
Constructs the histogram calculation object for an image.AlgorithmHistogram(ModelImage image, int summaryBins, int RGBOffset)
Constructs the histogram calculation object for an RGB image.AlgorithmHistogram(ModelImage image, int summaryBins, int RGBOffset, boolean maskFlag)
Constructs the histogram calculation object for an RGB image.AlgorithmHistogram(ModelImage image, int summaryBins, int RGBOffset, boolean maskFlag, boolean displayGraph, boolean userLimits, double userMin, double userMax)
Constructs the histogram calculation object for an RGB image.AlgorithmHistogram(ModelImage image, int summaryBins, int processMode, boolean displayGraph, boolean userLimits, float userMin, float userMax)
Constructs the histogram calculation object for an image.AlgorithmHistogram(ModelImage image, int summaryBins, int RGBOffset, int processMode, boolean displayGraph, boolean userLimits, float userMin, float userMax)
Constructs the histogram calculation object for an RGB image.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
disposeLocal()
Dispose of local variables.void
entireImage(boolean flag)
Sets a flag to indicate if the histogram is to be calculated for the entire image or just the VOI.private int
entropySplit(int[] hist)
Calculate maximum entropy split of a histogram.void
finalize()
Prepares this class for destruction.double[]
getHighValue()
DOCUMENT ME!int[]
getHistoBuffer()
The buffer of all histogram values.double[]
getLowValue()
DOCUMENT ME!ModelHistogram
getModelHistogram()
Accessor to the histogram.private int
otsuThreshold(ModelImage image, int[] histoBuffer)
This algorithm is an implementation of Otsu thresholding technique based on the minimization of inter-class variance [otsu79].void
runAlgorithm()
Calculates the histogram.void
runData(int bins, int VOINum)
Calculates the histogram and outputs the number of counts per bin and area/volume information.-
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
-
WHOLE_IMAGE
private static final int WHOLE_IMAGE
- See Also:
- Constant Field Values
-
TOTAL_VOIS
private static final int TOTAL_VOIS
- See Also:
- Constant Field Values
-
SEPARATE_VOIS
private static final int SEPARATE_VOIS
- See Also:
- Constant Field Values
-
dataOutput
private boolean dataOutput
Flag indicating whether or not histogram data is output to the data window.
-
entireImage
private boolean entireImage
If true the histogram should be calculated for the entire image.
-
highValue
private double[] highValue
DOCUMENT ME!
-
histoBuffer
private int[] histoBuffer
DOCUMENT ME!
-
histogram
private ModelHistogram histogram
Reference to the histogram storage object.
-
image
private ModelImage image
Reference to the image.
-
lowValue
private double[] lowValue
DOCUMENT ME!
-
RGBOffset
private int RGBOffset
Indicates which channel of the RGB image the histogram should be calculated. 1 = Red channel 2 = Green channel 3 = Blue channel
-
summaryBins
private int summaryBins
Used to indicate the number of histogram bins when using the constructors that do NOT pass in the histogram object.
-
displayGraph
private boolean displayGraph
-
userLimits
private boolean userLimits
-
userMin
private double userMin
-
userMax
private double userMax
-
processMode
private int processMode
-
-
Constructor Detail
-
AlgorithmHistogram
public AlgorithmHistogram(ModelImage image, int summaryBins)
Constructs the histogram calculation object for an image.- Parameters:
image
- ModelImage the imagesummaryBins
- number of bins in the histogram
-
AlgorithmHistogram
public AlgorithmHistogram(ModelHistogram histogram, ModelImage image, boolean maskFlag)
Constructs the histogram calculation object.- Parameters:
histogram
- model of a histogramimage
- model of the source imagemaskFlag
- Flag that indicates that the histogram will be calculated for the whole image if equal to true
-
AlgorithmHistogram
public AlgorithmHistogram(ModelImage image, int summaryBins, boolean maskFlag)
Constructs the histogram calculation object for an image.- Parameters:
image
- ModelImage the imagesummaryBins
- number of bins in the histogrammaskFlag
- Flag that indicates that the histogram will be calculated for the whole image if equal to true
-
AlgorithmHistogram
public AlgorithmHistogram(ModelImage image, int summaryBins, int processMode, boolean displayGraph, boolean userLimits, float userMin, float userMax)
Constructs the histogram calculation object for an image.- Parameters:
image
- ModelImage the imagesummaryBins
- number of bins in the histogramprocessMode
- WHOLE_IMAGE, TOTAL_VOIS, or SEPARATE_VOISdisplayGraph
- If true, produces a graph for displayuserLimits
- If true, histogram goes from userMin to userMax instead of image.getMin() to image.getMax()userMin
-usermax
-
-
AlgorithmHistogram
public AlgorithmHistogram(ModelImage image, int summaryBins, boolean maskFlag, boolean displayGraph, boolean userLimits, double userMin, double userMax)
Constructs the histogram calculation object for an image.- Parameters:
image
- ModelImage the imagesummaryBins
- number of bins in the histogrammaskFlag
- Flag that indicates that the histogram will be calculated for the whole image if equal to truedisplayGraph
- If true, produces a graph for displayuserLimits
- If true, histogram goes from userMin to userMax instead of image.getMin() to image.getMax()userMin
-usermax
-
-
AlgorithmHistogram
public AlgorithmHistogram(ModelImage image, int summaryBins, int RGBOffset)
Constructs the histogram calculation object for an RGB image.- Parameters:
image
- ModelImage the imagesummaryBins
- number of bins in the histogramRGBOffset
- correct offset for RED = 1 , GREEN = 2, or BLUE = 3 component to be exported
-
AlgorithmHistogram
public AlgorithmHistogram(ModelHistogram histogram, int RGBOffset, ModelImage image, boolean maskFlag)
Constructs the histogram calculation object for an RGB image.- Parameters:
histogram
- model of a histogram for a RGB componentRGBOffset
- correct offset for RED = 1 , GREEN = 2, or BLUE = 3 component to be exportedimage
- model of the source imagemaskFlag
- Flag that indicates that the histogram will be calculated for the whole image if equal to true
-
AlgorithmHistogram
public AlgorithmHistogram(ModelImage image, int summaryBins, int RGBOffset, boolean maskFlag)
Constructs the histogram calculation object for an RGB image.- Parameters:
image
- ModelImage the imagesummaryBins
- number of bins in the histogramRGBOffset
- correct offset for RED = 1 , GREEN = 2, or BLUE = 3 component to be exportedmaskFlag
- Flag that indicates that the histogram will be calculated for the whole image if equal to true
-
AlgorithmHistogram
public AlgorithmHistogram(ModelImage image, int summaryBins, int RGBOffset, int processMode, boolean displayGraph, boolean userLimits, float userMin, float userMax)
Constructs the histogram calculation object for an RGB image.- Parameters:
image
- ModelImage the imagesummaryBins
- number of bins in the histogramRGBOffset
- correct offset for RED = 1 , GREEN = 2, or BLUE = 3 component to be exportedprocessMode
- WHOLE_IMAGE, TOTAL_VOIS, or SEPARATE_VOISdisplayGraph
- If true, produces a graph for display * @param userLimits If true, histogram goes from userMin to userMax instead of image.getMin() to image.getMax()userMin
-usermax
-
-
AlgorithmHistogram
public AlgorithmHistogram(ModelImage image, int summaryBins, int RGBOffset, boolean maskFlag, boolean displayGraph, boolean userLimits, double userMin, double userMax)
Constructs the histogram calculation object for an RGB image.- Parameters:
image
- ModelImage the imagesummaryBins
- number of bins in the histogramRGBOffset
- correct offset for RED = 1 , GREEN = 2, or BLUE = 3 component to be exportedmaskFlag
- Flag that indicates that the histogram will be calculated for the whole image if equal to truedisplayGraph
- If true, produces a graph for display * @param userLimits If true, histogram goes from userMin to userMax instead of image.getMin() to image.getMax()userMin
-usermax
-
-
-
Method Detail
-
disposeLocal
public void disposeLocal()
Dispose of local variables.
-
entireImage
public void entireImage(boolean flag)
Sets a flag to indicate if the histogram is to be calculated for the entire image or just the VOI.- Parameters:
flag
- true = histogram of entire image, false = histogram of VOI
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalize
in classAlgorithmBase
-
getHighValue
public double[] getHighValue()
DOCUMENT ME!- Returns:
- double[]
-
getHistoBuffer
public int[] getHistoBuffer()
The buffer of all histogram values.- Returns:
- int[]
-
getLowValue
public double[] getLowValue()
DOCUMENT ME!- Returns:
- double[]
-
getModelHistogram
public ModelHistogram getModelHistogram()
Accessor to the histogram.- Returns:
- returns the model of the histogram
-
runAlgorithm
public void runAlgorithm()
Calculates the histogram.- Specified by:
runAlgorithm
in classAlgorithmBase
-
runData
public void runData(int bins, int VOINum)
Calculates the histogram and outputs the number of counts per bin and area/volume information.- Parameters:
bins
- number of bins in the histogram
-
entropySplit
private int entropySplit(int[] hist)
Calculate maximum entropy split of a histogram. This method is very similar to Otsu's method. Rather than maximising the inter-class variance, it maximizes the inter-class entropy. Entropy is a measure of the uncertainity of an event taking place. You can calculate it as: S = -(sum)p*log2(p) so it is very straightforward to do using the histogram data. (p is the probability of a pixel greyscale value in the image, and (sum) is the greek capital sigma. It is customary to use log in base 2. P.K. Sahoo, S. Soltani, K.C. Wong and, Y.C. Chen "A Survey of Thresholding Techniques", Computer Vision, Graphics, and Image Processing, Vol. 41, pp.233-260, 1988.- Parameters:
hist
- histogram to be thresholded.- Returns:
- index of the maximum entropy split.`
- Throws:
java.lang.IllegalArgumentException
- DOCUMENT ME!
-
otsuThreshold
private int otsuThreshold(ModelImage image, int[] histoBuffer)
This algorithm is an implementation of Otsu thresholding technique based on the minimization of inter-class variance [otsu79].- Parameters:
image
- DOCUMENT ME!histoBuffer
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
-