com.pearsoneduc.ip.op
Class Histogram

java.lang.Object
  |
  +--com.pearsoneduc.ip.op.Histogram

public final class Histogram
extends java.lang.Object
implements java.lang.Cloneable

A class which calculates the histogram of a BufferedImage, together with associated statistics such as minimum and maximum values in all bands, mean value in all bands, etc.

Version:
1.3 [1999/06/30]
Author:
Nick Efford
See Also:
BufferedImage

Constructor Summary
Histogram()
          Default constructor.
Histogram(java.awt.image.BufferedImage image)
          Constructs the histogram of a BufferedImage.
Histogram(java.io.Reader reader)
          Constructs a histogram using a Reader as the data source.
 
Method Summary
 java.lang.Object clone()
          Clones a histogram.
 void computeHistogram(java.awt.image.BufferedImage image)
          Calculates histogram data for a BufferedImage.
 boolean equals(java.lang.Object obj)
          Tests for equivalence of Histogram objects.
 int getCumulativeFrequency(int value)
          Retrieves the frequency of occurrence of a grey level less than or equal to the specified value.
 int getCumulativeFrequency(int band, int value)
          Retrieves the frequency of occurrence of values less than or equal to the specified value in a given band.
 int getFrequency(int value)
          Retrieves the frequency of occurrence of a specified grey level.
 int getFrequency(int band, int value)
          Retrieves the frequency of occurrence of a particular value in a given band.
 int getMaxFrequency()
          Gives the largest frequency recorded in the histogram.
 int getMaxFrequency(int band)
          Gives the largest frequency recorded in the histogram.
 int getMaxValue()
          Gives maximum value for which counts have been recorded.
 int getMaxValue(int band)
          Gives maximum value for which counts have been recorded in the specified band.
 double getMeanValue()
          Gives mean value of a greyscale histogram.
 double getMeanValue(int band)
          Gives mean value in one band of a colour histogram.
 int getMinFrequency()
          Gives the smallest frequency recorded in the histogram.
 int getMinFrequency(int band)
          Gives the smallest frequency recorded in the histogram.
 int getMinValue()
          Gives minimum value for which counts have been recorded.
 int getMinValue(int band)
          Gives minimum value for which counts have been recorded in the specified band.
 int getNumBands()
          Gives number of histogram bands.
 int getNumSamples()
          Gives number of samples taken from source image.
 void read(java.io.Reader source)
          Reads histogram data from the specified source.
 boolean sourceIsGrey()
          Indicates whether histogram was computed from a greyscale image or not.
 java.lang.String toString()
           
 void write(java.io.Writer destination)
          Writes histogram data to the specified destination.
 void writeCumulative(java.io.Writer destination)
          Writes cumulative histogram data to the specified destination.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Histogram

public Histogram()
Default constructor.

Histogram

public Histogram(java.io.Reader reader)
          throws java.io.IOException
Constructs a histogram using a Reader as the data source.
Parameters:
reader - the Reader used to obtain histogram data
Throws:
java.io.IOException - if the input data are not formatted correctly.

Histogram

public Histogram(java.awt.image.BufferedImage image)
          throws HistogramException
Constructs the histogram of a BufferedImage.
Parameters:
image - the image for which a histogram is required
Throws:
HistogramException - if image is of wrong type.
Method Detail

clone

public java.lang.Object clone()
Clones a histogram.
Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Tests for equivalence of Histogram objects.
Returns:
true if histograms contain the same data, false otherwise.
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Returns:
a String object giving the number of bands and samples in the histogram.
Overrides:
toString in class java.lang.Object

computeHistogram

public void computeHistogram(java.awt.image.BufferedImage image)
                      throws HistogramException
Calculates histogram data for a BufferedImage.
Parameters:
image - BufferedImage for which a histogram is required
Throws:
HistogramException - if the image is of an unsupported type.

read

public void read(java.io.Reader source)
          throws java.io.IOException
Reads histogram data from the specified source.
Parameters:
source - Reader used to obtain histogram data
Throws:
java.io.IOException - if the input data are not formatted correctly.

write

public void write(java.io.Writer destination)
Writes histogram data to the specified destination.
Parameters:
destination - Writer used to output histogram data

writeCumulative

public void writeCumulative(java.io.Writer destination)
Writes cumulative histogram data to the specified destination.
Parameters:
destination - Writer used to output data

sourceIsGrey

public boolean sourceIsGrey()
Indicates whether histogram was computed from a greyscale image or not.
Returns:
true if source is a greyscale image, false otherwise.

getNumBands

public int getNumBands()
Gives number of histogram bands.
Returns:
number of bands, as an integer (1 if the source of the histogram is a greyscale image, 3 if the source is a colour image).

getNumSamples

public int getNumSamples()
Gives number of samples taken from source image.
Returns:
number of samples, as an integer.

getFrequency

public int getFrequency(int value)
                 throws HistogramException
Retrieves the frequency of occurrence of a specified grey level.
Parameters:
value - pixel value for which a frequency is required
Returns:
frequency as an integer (0 or greater).
Throws:
HistogramException - if source is not a greyscale image.

getFrequency

public int getFrequency(int band,
                        int value)
Retrieves the frequency of occurrence of a particular value in a given band.
Parameters:
band - band for which a frequency is required (0, 1 or 2)
value - pixel value for which a frequency is required
Returns:
frequency as an integer (0 or greater).

getCumulativeFrequency

public int getCumulativeFrequency(int value)
                           throws HistogramException
Retrieves the frequency of occurrence of a grey level less than or equal to the specified value.
Parameters:
value - pixel value for which a cumulative frequency is required
Returns:
cumulative frequency as an integer (0 or greater).
Throws:
HistogramException - if source is not a greyscale image.

getCumulativeFrequency

public int getCumulativeFrequency(int band,
                                  int value)
Retrieves the frequency of occurrence of values less than or equal to the specified value in a given band.
Parameters:
band - band for which a cumulative frequency is required
value - pixel value for which a cumulative frequency is required
Returns:
cumulative frequency as an integer (0 or greater).

getMinFrequency

public int getMinFrequency()
                    throws HistogramException
Gives the smallest frequency recorded in the histogram.
Returns:
minimum frequency as an integer (0 or greater).
Throws:
HistogramException - if source is not a greyscale image.

getMinFrequency

public int getMinFrequency(int band)
Gives the smallest frequency recorded in the histogram.
Parameters:
band - band for which a minimum frequency is required (0, 1 or 2)
Returns:
minimum frequency in that band, as an integer (0 or greater).

getMaxFrequency

public int getMaxFrequency()
                    throws HistogramException
Gives the largest frequency recorded in the histogram.
Returns:
maximum frequency as an integer (0 or greater).
Throws:
HistogramException - if source is not a greyscale image.

getMaxFrequency

public int getMaxFrequency(int band)
Gives the largest frequency recorded in the histogram.
Parameters:
band - band from which maximum frequency is required (0, 1 or 2)
Returns:
maximum frequency in that band, as an integer (0 or greater).

getMinValue

public int getMinValue()
                throws HistogramException
Gives minimum value for which counts have been recorded.
Returns:
minimum value as an integer (0 or greater).
Throws:
HistogramException - if source is not a greyscale image.

getMinValue

public int getMinValue(int band)
Gives minimum value for which counts have been recorded in the specified band.
Parameters:
band - band for which a minimum value is required (0, 1 or 2)
Returns:
minimum value in that band, as an integer (0 or greater).

getMaxValue

public int getMaxValue()
                throws HistogramException
Gives maximum value for which counts have been recorded.
Returns:
maximum value, as an integer (0 or greater).
Throws:
HistogramException - if source is not a greyscale image.

getMaxValue

public int getMaxValue(int band)
Gives maximum value for which counts have been recorded in the specified band.
Parameters:
band - the band for which maximum value is required (0, 1 or 2)
Returns:
maximum value in that band, as an integer (0 or greater).

getMeanValue

public double getMeanValue()
                    throws HistogramException
Gives mean value of a greyscale histogram.
Returns:
mean value, as a double-precision real number.
Throws:
HistogramException - if source is not a greyscale image.

getMeanValue

public double getMeanValue(int band)
Gives mean value in one band of a colour histogram.
Parameters:
band - the band for which mean value is required (0, 1 or 2)
Returns:
mean value in the specified band, as a double-precision real number.