Class SHisto
- java.lang.Object
-
- jhplot.utils.SHisto
-
public class SHisto extends java.lang.Object
This class represents a histogram operation class. Some parts of this class are not free for commercial use and licensed by JAVA RESEARCH LICENSE. Please look at https://jai.dev.java.net/jrl.html. The program is based on JAI Histogram.java class.
-
-
Constructor Summary
Constructors Constructor and Description SHisto(int[] numBins, double[] lowValue, double[] highValue)
Constructor.SHisto(int[] numBins, double[] lowValue, double[] highValue, int numBands)
Constructor.SHisto(int numBins, double lowValue, double highValue, int numBands)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description void
clearHistogram()
Resets the values of all bins to zero.double
getBinLowValue(int band, int bin)
Returns the lowest inclusive pixel value of a given bin for a specific band.double[][]
getBins()
Returns the array of bands of bins, each bin is the histogram for a band, i.e., the format of the returned array isint[bands][bins]
.double[]
getBins(int band)
Returns the bins of the histogram for a specific band by reference.double[]
getBinsFirstBand()
Returns the bins of the first band.double
getBinsFirstBand(int j)
Returns the bin content of the first band.double
getBinSize(int band, int bin)
Returns the number of pixel samples found in a given bin for a specific band.double[]
getEntropy()
Returns the entropy of the histogram.SHisto
getGaussianSmoothed(double standardDeviation)
Computes a Gaussian smoothed version of the histogram.double[]
getHighValue()
Returns the highest exclusive pixel value checked for all bands.double
getHighValue(int band)
Returns the highest value checked for a specific band.double[]
getIterativeThreshold()
Calculates the threshold using iterative bisection.double[]
getLowValue()
Returns the lowest inclusive pixel value checked for all bands.double
getLowValue(int band)
Returns the lowest inclusive pixel value checked for a specific band.double[]
getMaxEntropyThreshold()
Calculates the threshold which maximizes the entropy.double[]
getMaxVarianceThreshold()
Calculates the threshold which maximizes the ratio of the between-class variance to the within-class variance for each band.double[]
getMean()
Returns the mean values for all bands of the histogram.double[]
getMinErrorThreshold()
Calculates the threshold which minimizes the probability of error.double[]
getMinFuzzinessThreshold()
Calculates the threshold which minimizes the fuzziness.double[]
getModeThreshold(double power)
Calculates the threshold using the mode method.double[]
getMoment(int moment, boolean isAbsolute, boolean isCentral)
Returns a specified (absolute) (central) moment of the histogram.int
getNumBands()
Returns the number of bands of the histogram.int[]
getNumBins()
Returns the number of bins of the histogram for all bands.int
getNumBins(int band)
Returns the number of bins of the histogram for a specific band.double[]
getPTileThreshold(double p)
Calculates the p-tile threshold.SHisto
getSmoothed(boolean isWeighted, int k)
Computes a smoothed version of the histogram.double[]
getStandardDeviation()
Returns the standard deviation for all bands of the histogram.int
getSubTotal(int band, int minBin, int maxBin)
Returns the total bin count for the specified sub-range (via "min" and "max" bin) of the indicated band.int[]
getTotals()
Returns the total bin count over all bins for all bands.void
setBins(double[] xbin)
Set bin values assuming that there only one bandvoid
setBins(double[][] xbin)
Set bin values
-
-
-
Constructor Detail
-
SHisto
public SHisto(int[] numBins, double[] lowValue, double[] highValue)
Constructor.This constructor should be used when
numBins
,lowValue
, and/orhighValues
are different for each band of the image. The length of the arrays indicates the number of bands the image has, and the three arrays must have the same length.Since this constructor has no way of knowing the actual number of bands of the image, the length of the arrays is not checked against anything. Therefore, it is very important that the caller supplies the correct arrays of correct lengths, or errors will occur.
- Parameters:
numBins
- The number of bins for each band of the image. The length of this array indicates the number of bands for this histogram.lowValue
- The lowest inclusive pixel value checked for each band.highValue
- The highest exclusive pixel value checked for each band.
-
SHisto
public SHisto(int[] numBins, double[] lowValue, double[] highValue, int numBands)
Constructor.This constructor should be used when
numBins
,lowValue
, and/orhighValues
may be different for each band of the image. The number of bands in the image is provided explicitly. If any of the arrays provided has a length which is less than the number of bands, the first element in that array is used to fill out the array to a length ofnumBands
.- Parameters:
numBins
- The number of bins for each band of the image.lowValue
- The lowest value checked for each band.highValue
- The highest value checked for each band.numBands
- The number of bands in the image.
-
SHisto
public SHisto(int numBins, double lowValue, double highValue, int numBands)
Constructor.The same
numBins
,lowValue
, andhighValue
is applied to every band of the image.- Parameters:
numBins
- The number of bins for all bands of the image.lowValue
- The lowest inclusive pixel value checked for all bands.highValue
- The highest exclusive pixel value checked for all bands.numBands
- The number of bands of the image.
-
-
Method Detail
-
getNumBins
public int[] getNumBins()
Returns the number of bins of the histogram for all bands.
-
getNumBins
public int getNumBins(int band)
Returns the number of bins of the histogram for a specific band.- Parameters:
band
- The index of the band whosenumBins
is to be returned.
-
getLowValue
public double[] getLowValue()
Returns the lowest inclusive pixel value checked for all bands.
-
getLowValue
public double getLowValue(int band)
Returns the lowest inclusive pixel value checked for a specific band.- Parameters:
band
- The index of the band whoselowValue
is to be returned.
-
getHighValue
public double[] getHighValue()
Returns the highest exclusive pixel value checked for all bands.
-
getHighValue
public double getHighValue(int band)
Returns the highest value checked for a specific band.- Parameters:
band
- The index of the band whosehighValue
is to be returned.
-
getNumBands
public int getNumBands()
Returns the number of bands of the histogram. This value is the same as the number of bands of the bins,bins.length
.
-
getBins
public double[][] getBins()
Returns the array of bands of bins, each bin is the histogram for a band, i.e., the format of the returned array isint[bands][bins]
.
-
setBins
public void setBins(double[][] xbin)
Set bin values- Parameters:
xbin
- bin values for a specific band
-
setBins
public void setBins(double[] xbin)
Set bin values assuming that there only one band- Parameters:
xbin
- bin values for a specific band
-
getBins
public double[] getBins(int band)
Returns the bins of the histogram for a specific band by reference.- Parameters:
band
- The index of the band whosebins
are to be returned.
-
getBinsFirstBand
public double[] getBinsFirstBand()
Returns the bins of the first band.- Parameters:
bins
- from the first band
-
getBinsFirstBand
public double getBinsFirstBand(int j)
Returns the bin content of the first band.- Parameters:
bin
- index
-
getBinSize
public double getBinSize(int band, int bin)
Returns the number of pixel samples found in a given bin for a specific band.- Parameters:
band
- The index of the band-of-interest.bin
- The index of the bin whose value is to be returned.
-
getBinLowValue
public double getBinLowValue(int band, int bin)
Returns the lowest inclusive pixel value of a given bin for a specific band.- Parameters:
band
- The index of the band-of-interest.bin
- The index of the bin whoselowValue
is to be returned.
-
clearHistogram
public void clearHistogram()
Resets the values of all bins to zero. Ifbins
has not been initialized (null
), this method does nothing.
-
getTotals
public int[] getTotals()
Returns the total bin count over all bins for all bands.An array which stores the total bin count is kept in this class and a reference to this array is returned by this method for performance reasons. The elements of the returned array should not be modified or undefined errors may occur. The array format is
int[numBands]
.
-
getSubTotal
public int getSubTotal(int band, int minBin, int maxBin)
Returns the total bin count for the specified sub-range (via "min" and "max" bin) of the indicated band. The sub-rangee must fall within the actual range of the bins.- Parameters:
band
- The index of the band-of-interest.minBin
- The minimum bin index to be counted.maxBin
- The maximum bin index to be counted.
-
getMean
public double[] getMean()
Returns the mean values for all bands of the histogram.
-
getMoment
public double[] getMoment(int moment, boolean isAbsolute, boolean isCentral)
Returns a specified (absolute) (central) moment of the histogram.The ith moment in each band is defined to be the mean of the image pixel values raised to the ith power in that band. For central moments the average of the ith power of the deviation from the mean is used. For absolute moments the absolute value of the exponentiated term is used.
Note that the mean is the first moment, the average energy the second central moment, etc.
- Parameters:
moment
- The moment number or index which must be positive or anIllegalArgumentException
will be thrown.isAbsolute
- Whether to calculate the absolute moment.isCentral
- Whether to calculate the central moment.- Returns:
- The requested (absolute) (central) moment of the histogram.
-
getStandardDeviation
public double[] getStandardDeviation()
Returns the standard deviation for all bands of the histogram. This is a convenience method as the returned values could be calculated using the first and second moments which are available via the moment generation function.- Returns:
- The standard deviation values for all bands.
-
getEntropy
public double[] getEntropy()
Returns the entropy of the histogram.The histogram entropy is defined to be the negation of the sum of the products of the probability associated with each bin with the base-2 log of the probability.
- Returns:
- The entropy of the histogram.
-
getSmoothed
public SHisto getSmoothed(boolean isWeighted, int k)
Computes a smoothed version of the histogram.Each band of the histogram is smoothed by averaging over a moving window of a size specified by the method parameter: if the value of the parameter is k then the width of the window is 2*k + 1. If the window runs off the end of the histogram only those values which intersect the histogram are taken into consideration. The smoothing may optionally be weighted to favor the central value using a "triangular" weighting. For example, for a value of k equal to 2 the central bin would have weight 1/3, the adjacent bins 2/9, and the next adjacent bins 1/9.
- Parameters:
isWeighted
- Whether bins will be weighted using a triangular weighting scheme favoring bins near the central bin.k
- The smoothing parameter which must be non-negative or anIllegalArgumentException
will be thrown. If zero, the histogram object will be returned with no smoothing applied.- Returns:
- A smoothed version of the histogram.
-
getGaussianSmoothed
public SHisto getGaussianSmoothed(double standardDeviation)
Computes a Gaussian smoothed version of the histogram.Each band of the histogram is smoothed by discrete convolution with a kernel approximating a Gaussian impulse response with the specified standard deviation.
- Parameters:
standardDeviation
- The standard deviation of the Gaussian smoothing kernel which must be non-negative or anIllegalArgumentException
will be thrown. If zero, the histogram object will be returned with no smoothing applied.- Returns:
- A Gaussian smoothed version of the histogram.
-
getPTileThreshold
public double[] getPTileThreshold(double p)
Calculates the p-tile threshold.Computes thresholds such that a specified proportion of the sample values in each band are below the threshold.
- Parameters:
p
- The proportion of samples in each band which should be below the threshold in the band. Ifp
is not in the range (0.0, 1.0) anIllegalArgumentException
will be thrown.- Returns:
- The requested p-tile thresholds.
-
getModeThreshold
public double[] getModeThreshold(double power)
Calculates the threshold using the mode method.The threshold is defined to be the minimum between two peaks. The first peak is the highest peak in the histogram. The second peak is the highest peak in the histogram weighted by a specified power of the distance from the first peak.
- Parameters:
power
- The exponent of the distance weighting from the first peak.- Returns:
- The requested thresholds.
-
getIterativeThreshold
public double[] getIterativeThreshold()
Calculates the threshold using iterative bisection. For each band an initial threshold is defined to be the midpoint of the range of data represented by the histogram. The mean value is calculated for each sub-histogram and a new threshold is defined as the arithmetic mean of the two sub-histogram means. This process is repeated until the threshold value no longer changes.- Returns:
- The requested thresholds.
-
getMaxVarianceThreshold
public double[] getMaxVarianceThreshold()
Calculates the threshold which maximizes the ratio of the between-class variance to the within-class variance for each band.- Returns:
- The requested thresholds.
-
getMaxEntropyThreshold
public double[] getMaxEntropyThreshold()
Calculates the threshold which maximizes the entropy.The entropy of a range of gray levels is defined to be the negation of the sum of products of the probability and the logarithm thereof over all gray levels in the range. The maximum entropy threshold is defined to be that value which maximizes the sum of the entropy of the two ranges which are above and below the threshold, respectively. This computation is effected for each band.
- Returns:
- The requested thresholds.
-
getMinErrorThreshold
public double[] getMinErrorThreshold()
Calculates the threshold which minimizes the probability of error.For each band the histogram is modeled as the sum of two Gaussian distributions and the threshold which minimizes the misclassification error is computed. If the underlying histogram is unimodal the mean value of each band will be returned as the threshold. The bimodality of the histogram for that band will be identically zero.
- Returns:
- The requested thresholds.
-
getMinFuzzinessThreshold
public double[] getMinFuzzinessThreshold()
Calculates the threshold which minimizes the fuzziness.
-
-
DMelt 3.0 © DataMelt by jWork.ORG