Class AlgorithmHistogram

java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.AlgorithmHistogram
All Implemented Interfaces:
ActionListener, WindowListener, Runnable, 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:
  • Field Details

    • WHOLE_IMAGE

      private static final int WHOLE_IMAGE
      See Also:
    • TOTAL_VOIS

      private static final int TOTAL_VOIS
      See Also:
    • SEPARATE_VOIS

      private static final int SEPARATE_VOIS
      See Also:
    • 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 Details

    • AlgorithmHistogram

      public AlgorithmHistogram(ModelImage image, int summaryBins)
      Constructs the histogram calculation object for an image.
      Parameters:
      image - ModelImage the image
      summaryBins - 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 histogram
      image - model of the source image
      maskFlag - 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 image
      summaryBins - number of bins in the histogram
      maskFlag - 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 image
      summaryBins - number of bins in the histogram
      processMode - WHOLE_IMAGE, TOTAL_VOIS, or SEPARATE_VOIS
      displayGraph - If true, produces a graph for display
      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, boolean maskFlag, boolean displayGraph, boolean userLimits, double userMin, double userMax)
      Constructs the histogram calculation object for an image.
      Parameters:
      image - ModelImage the image
      summaryBins - number of bins in the histogram
      maskFlag - Flag that indicates that the histogram will be calculated for the whole image if equal to true
      displayGraph - If true, produces a graph for display
      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)
      Constructs the histogram calculation object for an RGB image.
      Parameters:
      image - ModelImage the image
      summaryBins - number of bins in the histogram
      RGBOffset - 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 component
      RGBOffset - correct offset for RED = 1 , GREEN = 2, or BLUE = 3 component to be exported
      image - model of the source image
      maskFlag - 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 image
      summaryBins - number of bins in the histogram
      RGBOffset - correct offset for RED = 1 , GREEN = 2, or BLUE = 3 component to be exported
      maskFlag - 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 image
      summaryBins - number of bins in the histogram
      RGBOffset - correct offset for RED = 1 , GREEN = 2, or BLUE = 3 component to be exported
      processMode - WHOLE_IMAGE, TOTAL_VOIS, or SEPARATE_VOIS
      displayGraph - 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 image
      summaryBins - number of bins in the histogram
      RGBOffset - correct offset for RED = 1 , GREEN = 2, or BLUE = 3 component to be exported
      maskFlag - Flag that indicates that the histogram will be calculated for the whole image if equal to true
      displayGraph - 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 Details

    • 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 class AlgorithmBase
    • 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 class AlgorithmBase
    • 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:
      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!