Package org.esa.snap.core.util.math
Class Histogram
- java.lang.Object
-
- org.esa.snap.core.util.math.Range
-
- org.esa.snap.core.util.math.Histogram
-
public class Histogram extends Range
Instances of theHistogram
class store histogram data.
-
-
Field Summary
Fields Modifier and Type Field Description static float
LEFT_AREA_SKIPPED_95
static float
RIGHT_AREA_SKIPPED_95
-
Constructor Summary
Constructors Constructor Description Histogram(int[] binCounts, double min, double max)
Constructs a new instance for the given bin counts and the given value range.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
aggregate(Object values, boolean unsigned, IndexValidator validator, ProgressMonitor pm)
static Histogram
computeHistogram(RenderedImage image, javax.media.jai.ROI roi, int numBins, Range range)
static Histogram
computeHistogramByte(byte[] values, IndexValidator validator, int numBins, Range range, Histogram histo, ProgressMonitor pm)
Computes the histogram for the values in the givenbyte
array in the given value range.static Histogram
computeHistogramDouble(double[] values, IndexValidator validator, int numBins, Range range, Histogram histogram, ProgressMonitor pm)
Computes the histogram for the values in the givendouble
array in the given value range.static Histogram
computeHistogramDouble(DoubleList values, IndexValidator validator, int numBins, Range range, Histogram histo, ProgressMonitor pm)
Computes the histogram for the values in the givenHistogram.DoubleList
in the given value range.static Histogram
computeHistogramFloat(float[] values, IndexValidator validator, int numBins, Range range, Histogram histogram, ProgressMonitor pm)
Computes the histogram for the values in the givenfloat
array in the given value range.static Histogram
computeHistogramGeneric(Object values, boolean unsigned, IndexValidator validator, int numBins, Range range, Histogram histogram, ProgressMonitor pm)
Computes the histogram for the values in the givenHistogram.DoubleList
in the given value range.static Histogram
computeHistogramInt(int[] values, IndexValidator validator, int numBins, Range range, Histogram histogram, ProgressMonitor pm)
Computes the histogram for the values in the givenint
array in the given value range.static Histogram
computeHistogramShort(short[] values, IndexValidator validator, int numBins, Range range, Histogram histo, ProgressMonitor pm)
Computes the histogram for the values in the givenshort
array in the given value range.static Histogram
computeHistogramUByte(byte[] values, IndexValidator validator, int numBins, Range range, Histogram histo, ProgressMonitor pm)
Computes the histogram for the values in the givenbyte
array in the given value range.static Histogram
computeHistogramUInt(int[] values, IndexValidator validator, int numBins, Range range, Histogram histogram, ProgressMonitor pm)
Computes the histogram for the values in the givenint
array in the given value range.static Histogram
computeHistogramUShort(short[] values, IndexValidator validator, int numBins, Range range, Histogram histo, ProgressMonitor pm)
Computes the histogram for the values in the givenshort
array in the given value range.Range
findRange(double leftHistoAreaSkipped, double rightHistoAreaSkipped)
Returns the value range for the case that the given ratios of the sum of all bin values are skipped from the lower and upper bounds of this histogram.Range
findRange(double leftHistoAreaSkipped, double rightHistoAreaSkipped, boolean skipLeftPeek, boolean skipRightPeek)
Range
findRangeFor95Percent()
Returns the value range for the case that 2.5% of the sum of all bin values are skipped from the the lower and upper bounds of this histogram.Range
findRangeForPercent(double threshold)
Returns the value range for any threshold of 0% to 100% where the sum of all bin values are skipped from the the lower and upper bounds of this histogram.int[]
getBinCounts()
Gets the bin values of this histogram.int
getBinCountsSum()
Gets the sum of all countsint
getBinIndex(double value)
Gets the bin index for the given value.int
getMaxBinCount()
Gets the maximum bin value found this histogram.int
getNumBins()
Gets the number of bins in this histogram.Range
getRange(int binIndex)
Gets the data value range for the given bin index.Range
getRange(int binIndex1, int binIndex2)
Gets the data value range for the given bin index range.void
setBinCounts(int[] binCounts)
Sets the bin values of this histogram.void
setBinCounts(int[] binValues, double min, double max)
Sets the bin values and range of this histogram.-
Methods inherited from class org.esa.snap.core.util.math.Range
computeRangeByte, computeRangeDouble, computeRangeDouble, computeRangeDouble, computeRangeFloat, computeRangeGeneric, computeRangeInt, computeRangeShort, computeRangeUByte, computeRangeUInt, computeRangeUShort, getMax, getMin, isValid, setMax, setMin, setMinMax, toString
-
-
-
-
Field Detail
-
LEFT_AREA_SKIPPED_95
public static final float LEFT_AREA_SKIPPED_95
- See Also:
- Constant Field Values
-
RIGHT_AREA_SKIPPED_95
public static final float RIGHT_AREA_SKIPPED_95
- See Also:
- Constant Field Values
-
-
Method Detail
-
getNumBins
public int getNumBins()
Gets the number of bins in this histogram.- Returns:
- the number of bins
-
getBinCounts
public int[] getBinCounts()
Gets the bin values of this histogram.- Returns:
- the bin values
-
setBinCounts
public void setBinCounts(int[] binValues, double min, double max)
Sets the bin values and range of this histogram.- Parameters:
binValues
- the bin valuesmin
- the minimum value of the rangemax
- the maximum value of the range
-
setBinCounts
public void setBinCounts(int[] binCounts)
Sets the bin values of this histogram.- Parameters:
binCounts
- the bin values
-
getMaxBinCount
public int getMaxBinCount()
Gets the maximum bin value found this histogram.- Returns:
- the maximum bin value
-
getBinCountsSum
public int getBinCountsSum()
Gets the sum of all counts- Returns:
- the sum of all counts.
-
findRangeFor95Percent
public Range findRangeFor95Percent()
Returns the value range for the case that 2.5% of the sum of all bin values are skipped from the the lower and upper bounds of this histogram.- Returns:
- the skipped value range, that include 95% of the sum of all bin values
-
findRangeForPercent
public Range findRangeForPercent(double threshold)
Returns the value range for any threshold of 0% to 100% where the sum of all bin values are skipped from the the lower and upper bounds of this histogram.- Returns:
- the skipped value range, that include given percent of the sum of all bin values
-
findRange
public Range findRange(double leftHistoAreaSkipped, double rightHistoAreaSkipped)
Returns the value range for the case that the given ratios of the sum of all bin values are skipped from the lower and upper bounds of this histogram.- Parameters:
leftHistoAreaSkipped
- the normalized area (a ratio of the entire area) of samples skipped from the left end of the histogram, must be greater than or equal to0.0
and less than1.0 - rightHistoAreaSkipped
rightHistoAreaSkipped
- the normalized area (a ratio of the entire area) of samples skipped from the upper end of the histogram must be greater than or equal to0.0
and less than1.0 - leftHistoAreaSkipped
- Returns:
- the readjusted range
-
findRange
public Range findRange(double leftHistoAreaSkipped, double rightHistoAreaSkipped, boolean skipLeftPeek, boolean skipRightPeek)
-
getRange
public Range getRange(int binIndex)
Gets the data value range for the given bin index.- Parameters:
binIndex
- the bin index- Returns:
- the data value range
-
getRange
public Range getRange(int binIndex1, int binIndex2)
Gets the data value range for the given bin index range.- Parameters:
binIndex1
- the first bin indexbinIndex2
- the second bin index- Returns:
- the data value range
-
getBinIndex
public int getBinIndex(double value)
Gets the bin index for the given value.- Parameters:
value
- the value- Returns:
- the bin index or
-1
if the value is not covered by this histogram.
-
aggregate
public void aggregate(Object values, boolean unsigned, IndexValidator validator, ProgressMonitor pm)
-
computeHistogramByte
public static Histogram computeHistogramByte(byte[] values, IndexValidator validator, int numBins, Range range, Histogram histo, ProgressMonitor pm)
Computes the histogram for the values in the givenbyte
array in the given value range. The array elements are interpreted as signed byte values. Values at a given indexi
for whichvalidator.validate(i)
returnsfalse
are excluded from the computation.- Parameters:
values
- the array whose histogram to computevalidator
- used to validate the array indexes, must not benull
. UseIndexValidator.TRUE
instead.numBins
- the number of bins for the histogramrange
- the value range, ifnull
the range is automatically computedpm
- a monitor to inform the user about progress- Returns:
- the histogram for the given array
- See Also:
computeHistogramUByte(byte[], org.esa.snap.core.util.math.IndexValidator, int, org.esa.snap.core.util.math.Range, org.esa.snap.core.util.math.Histogram, com.bc.ceres.core.ProgressMonitor)
-
computeHistogramUByte
public static Histogram computeHistogramUByte(byte[] values, IndexValidator validator, int numBins, Range range, Histogram histo, ProgressMonitor pm)
Computes the histogram for the values in the givenbyte
array in the given value range. The array elements are interpreted as unsigned byte values. Values at a given indexi
for whichvalidator.validate(i)
returnsfalse
are excluded from the computation.- Parameters:
values
- the array whose histogram to computevalidator
- used to validate the array indexes, must not benull
. UseIndexValidator.TRUE
instead.numBins
- the number of bins for the histogramrange
- the value range, ifnull
the range is automatically computedpm
- a monitor to inform the user about progress- Returns:
- the histogram for the given array
- See Also:
computeHistogramByte(byte[], org.esa.snap.core.util.math.IndexValidator, int, org.esa.snap.core.util.math.Range, org.esa.snap.core.util.math.Histogram, com.bc.ceres.core.ProgressMonitor)
-
computeHistogramShort
public static Histogram computeHistogramShort(short[] values, IndexValidator validator, int numBins, Range range, Histogram histo, ProgressMonitor pm)
Computes the histogram for the values in the givenshort
array in the given value range. The array elements are interpreted as signed short values. Values at a given indexi
for whichvalidator.validate(i)
returnsfalse
are excluded from the computation.- Parameters:
values
- the array whose histogram to computevalidator
- used to validate the array indexes, must not benull
. UseIndexValidator.TRUE
instead.numBins
- the number of bins for the histogramrange
- the value range, ifnull
the range is automatically computed- Returns:
- the histogram for the given array
- See Also:
computeHistogramUShort(short[], org.esa.snap.core.util.math.IndexValidator, int, org.esa.snap.core.util.math.Range, org.esa.snap.core.util.math.Histogram, com.bc.ceres.core.ProgressMonitor)
-
computeHistogramUShort
public static Histogram computeHistogramUShort(short[] values, IndexValidator validator, int numBins, Range range, Histogram histo, ProgressMonitor pm)
Computes the histogram for the values in the givenshort
array in the given value range. The array elements are interpreted as unsigned short values. Values at a given indexi
for whichvalidator.validate(i)
returnsfalse
are excluded from the computation.- Parameters:
values
- the array whose histogram to computevalidator
- used to validate the array indexes, must not benull
. UseIndexValidator.TRUE
instead.numBins
- the number of bins for the histogramrange
- the value range, ifnull
the range is automatically computedpm
- a monitor to inform the user about progress- Returns:
- the histogram for the given array
- See Also:
computeHistogramShort(short[], org.esa.snap.core.util.math.IndexValidator, int, org.esa.snap.core.util.math.Range, org.esa.snap.core.util.math.Histogram, com.bc.ceres.core.ProgressMonitor)
-
computeHistogramInt
public static Histogram computeHistogramInt(int[] values, IndexValidator validator, int numBins, Range range, Histogram histogram, ProgressMonitor pm)
Computes the histogram for the values in the givenint
array in the given value range. The array elements are interpreted as signed byte values. Values at a given indexi
for whichvalidator.validate(i)
returnsfalse
are excluded from the computation.- Parameters:
values
- the array whose histogram to computevalidator
- used to validate the array indexes, must not benull
. UseIndexValidator.TRUE
instead.numBins
- the number of bins for the histogramrange
- the value range, ifnull
the range is automatically computedhistogram
- a histogram instance to be reused, can benull
pm
- a monitor to inform the user about progress- Returns:
- the histogram for the given array
- See Also:
computeHistogramUInt(int[], org.esa.snap.core.util.math.IndexValidator, int, org.esa.snap.core.util.math.Range, org.esa.snap.core.util.math.Histogram, com.bc.ceres.core.ProgressMonitor)
-
computeHistogramUInt
public static Histogram computeHistogramUInt(int[] values, IndexValidator validator, int numBins, Range range, Histogram histogram, ProgressMonitor pm)
Computes the histogram for the values in the givenint
array in the given value range. The array elements are interpreted as unsigned byte values. Values at a given indexi
for whichvalidator.validate(i)
returnsfalse
are excluded from the computation.- Parameters:
values
- the array whose histogram to computevalidator
- used to validate the array indexes, must not benull
. UseIndexValidator.TRUE
instead.range
- the value range, ifnull
the range is automatically computedhistogram
- a histogram instance to be reused, can benull
pm
- a monitor to inform the user about progress- Returns:
- the histogram for the given array of values
- See Also:
computeHistogramInt(int[], org.esa.snap.core.util.math.IndexValidator, int, org.esa.snap.core.util.math.Range, org.esa.snap.core.util.math.Histogram, com.bc.ceres.core.ProgressMonitor)
-
computeHistogramFloat
public static Histogram computeHistogramFloat(float[] values, IndexValidator validator, int numBins, Range range, Histogram histogram, ProgressMonitor pm)
Computes the histogram for the values in the givenfloat
array in the given value range. Values at a given indexi
for whichvalidator.validate(i)
returnsfalse
are excluded from the computation.- Parameters:
values
- the array whose histogram to computevalidator
- used to validate the array indexes, must not benull
. UseIndexValidator.TRUE
instead.numBins
- the number of bins for the histogramrange
- the value range, ifnull
the range is automatically computedhistogram
- a histogram instance to be reused, can benull
pm
- a monitor to inform the user about progress- Returns:
- the histogram for the given array of values
- See Also:
computeHistogramDouble(double[], org.esa.snap.core.util.math.IndexValidator, int, org.esa.snap.core.util.math.Range, org.esa.snap.core.util.math.Histogram, com.bc.ceres.core.ProgressMonitor)
-
computeHistogramDouble
public static Histogram computeHistogramDouble(double[] values, IndexValidator validator, int numBins, Range range, Histogram histogram, ProgressMonitor pm)
Computes the histogram for the values in the givendouble
array in the given value range. Values at a given indexi
for whichvalidator.validate(i)
returnsfalse
are excluded from the computation.- Parameters:
values
- the array whose histogram to computevalidator
- used to validate the array indexes, must not benull
. UseIndexValidator.TRUE
instead.numBins
- the number of bins for the histogramrange
- the value range, ifnull
the range is automatically computedhistogram
- a histogram instance to be reused, can benull
pm
- a monitor to inform the user about progress- Returns:
- the histogram for the given array of values
- See Also:
computeHistogramFloat(float[], org.esa.snap.core.util.math.IndexValidator, int, org.esa.snap.core.util.math.Range, org.esa.snap.core.util.math.Histogram, com.bc.ceres.core.ProgressMonitor)
-
computeHistogramDouble
public static Histogram computeHistogramDouble(DoubleList values, IndexValidator validator, int numBins, Range range, Histogram histo, ProgressMonitor pm)
Computes the histogram for the values in the givenHistogram.DoubleList
in the given value range. Values at a given indexi
for whichvalidator.validate(i)
returnsfalse
are excluded from the computation.- Parameters:
values
- theHistogram.DoubleList
whose histogram to computevalidator
- used to validate the indexes, must not benull
. UseIndexValidator.TRUE
instead.numBins
- the number of bins for the histogramrange
- the value range, ifnull
the range is automatically computedpm
- a monitor to inform the user about progress- Returns:
- the histogram for the given values
- See Also:
computeHistogramByte(byte[], org.esa.snap.core.util.math.IndexValidator, int, org.esa.snap.core.util.math.Range, org.esa.snap.core.util.math.Histogram, com.bc.ceres.core.ProgressMonitor)
-
computeHistogramGeneric
public static Histogram computeHistogramGeneric(Object values, boolean unsigned, IndexValidator validator, int numBins, Range range, Histogram histogram, ProgressMonitor pm)
Computes the histogram for the values in the givenHistogram.DoubleList
in the given value range. Values at a given indexi
for whichvalidator.validate(i)
returnsfalse
are excluded from the computation.- Parameters:
values
- theHistogram.DoubleList
whose histogram to computevalidator
- used to validate the indexes, must not benull
. UseIndexValidator.TRUE
instead.numBins
- the number of bins for the histogramrange
- the value range, ifnull
the range is automatically computedpm
- a monitor to inform the user about progress- Returns:
- the histogram for the given values
- See Also:
computeHistogramByte(byte[], org.esa.snap.core.util.math.IndexValidator, int, org.esa.snap.core.util.math.Range, org.esa.snap.core.util.math.Histogram, com.bc.ceres.core.ProgressMonitor)
-
computeHistogram
public static Histogram computeHistogram(RenderedImage image, javax.media.jai.ROI roi, int numBins, Range range)
-
-