Class HistogramNd<T>
- All Implemented Interfaces:
Iterable<LongType>
,Dimensions
,EuclideanSpace
,Img<LongType>
,Interval
,IterableInterval<LongType>
,IterableRealInterval<LongType>
,RandomAccessible<LongType>
,RandomAccessibleInterval<LongType>
,RealInterval
Note: the last three classifications may not be present depending upon the makeup of the input data.
- Author:
- Barry DeZonia
-
Constructor Summary
ConstructorsConstructorDescriptionHistogramNd
(Iterable<List<T>> data, List<BinMapper1d<T>> mappers) Construct a histogram from an iterable set of data and a list of bin mapping algorithms.HistogramNd
(List<Iterable<T>> data, List<BinMapper1d<T>> mappers) Construct a histogram from an iterable set of data and a list of bin mapping algorithms.HistogramNd
(List<BinMapper1d<T>> mappers) Construct a histogram from a list of bin mapping algorithms.HistogramNd
(HistogramNd<T> other) Construct a histogram whose bin mappings match another histogram. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Counts additional data contained in a given iterable collection.void
Counts additional data contained in a given iterable collection.copy()
void
Counts the data contained in the given data source using the underlying bin distribution.void
Counts the data contained in the given data source using the underlying bin distribution.cursor()
Returns aRealCursor
that iterates with optimal speed without calculating the location at each iteration step.void
decrement
(long[] binPos) Directly decrement a bin by position.void
Directly decrement a bin by value,dfd()
Get the discrete frequency distribution associated with this histogram.long
dimension
(int d) Return the size of the given dimension of the frequency distribution of this histogram.void
dimensions
(long[] dims) Fill the provided long[] with the sizes of all dimensions of the frequency distribution of this histogram.long
Returns the frequency count of all values in the distribution: lower tail + middle + upper tail.long
distributionCount
(int dim, long dimVal) Returns the frequency count of all values in the specified dimension of the distribution: lower tail + middle + upper tail.factory()
Get aImgFactory
that createsImg
s of the same kind as this one.Get the first element of thisIterableRealInterval
.long
frequency
(long[] binPos) Returns the frequency count of the values within a bin.long
Returns the frequency count of values within a bin using a set of representative values.long
Returns the number of bins contained in the histogram.void
getCenterValues
(long[] binPos, List<T> values) Gets the values associated with the center of a bin.void
getLowerBounds
(long[] binPos, List<T> values) Gets the values associated with the left edge of a bin.void
getUpperBounds
(long[] binPos, List<T> values) Gets the values associated with the right edge of a bin.boolean
hasTails()
Returns true if the histogram has tail bins which count extreme values for one or more dimensionsboolean
hasTails
(int dim) Returns true if the histogram has tail bins which count extreme values for the given dimension.long
Returns the frequency count of values that were ignored because they could not be mapped to any bin.boolean
includesLowerBound
(int dim, long binPos) Returns true if the given bin interval is closed on the left for the given dimension.boolean
includesLowerBounds
(long[] binPos) Returns true if the given bin interval is closed on the leftboolean
includesUpperBound
(int dim, long binPos) Returns true if the given bin interval is closed on the right for the given dimension.boolean
includesUpperBounds
(long[] binPos) Returns true if the given bin interval is closed on the rightvoid
increment
(long[] binPos) Directly increment a bin by position.void
Directly increment a bin by value.boolean
isInLowerTail
(int dim, T value) Returns true if a given value for a given dimension is mapped to the lower tail of the distribution.boolean
isInLowerTail
(List<T> values) Returns true if a given set of values are mapped to the lower tail of the distribution.boolean
isInMiddle
(int dim, T value) Returns true if a given value for a given dimension is mapped to the middle of the distribution.boolean
isInMiddle
(List<T> values) Returns true if a given set of values are mapped to the middle of the distribution.boolean
isInUpperTail
(int dim, T value) Returns true if a given value for a given dimension is mapped to the upper tail of the distribution.boolean
isInUpperTail
(List<T> values) Returns true if a given set of values are mapped to the upper tail of the distribution.boolean
Returns true if a given value for a given dimension is outside the distribution.boolean
Returns true if a given set of values are outside the distribution.Returns the iteration order of thisIterableRealInterval
.iterator()
Returns aRealLocalizable
Iterator
that calculates its location at each iteration step.long
Returns the frequency count of values in all lower tail bins (if any).long
lowerTailCount
(int dim) Returns the frequency count of values in the lower tail bin (if any) for the given dimension.void
Fills a bin position by mapping from a set of representative values.long
max
(int d) Get the maximum in dimension d.void
max
(long[] max) Write the maximum of each dimension into long[].void
max
(Positionable max) Sets aPositionable
to the maximum of thisInterval
long
min
(int d) Get the minimum in dimension d.void
min
(long[] min) Write the minimum of each dimension into long[].void
min
(Positionable min) Sets aPositionable
to the minimum of thisInterval
int
Return the number of dimensions of the frequency distribution of this histogram.Create a random access sampler for integer coordinates.randomAccess
(Interval interval) Create a random access sampler for integer coordinates.void
realMax
(double[] max) Write the maximum of each dimension into double[].double
realMax
(int d) Get the maximum in dimension d.void
realMax
(RealPositionable max) Sets aRealPositionable
to the maximum of thisInterval
void
realMin
(double[] min) Write the minimum of each dimension into double[].double
realMin
(int d) Get the minimum in dimension d.void
realMin
(RealPositionable min) Sets aRealPositionable
to the minimum of thisInterval
double
relativeFrequency
(long[] binPos, boolean includeTails) Returns the relative frequency of values within a bin.double
relativeFrequency
(List<T> values, boolean includeTails) Returns the relative frequency of values within a bin using a set of representative values.void
Resets all data counts to 0.long
size()
Returns the number of elements in thisFunction
.void
subtractData
(Iterable<List<T>> data) Uncounts some original data contained in a given iterable collection.void
subtractData
(List<Iterable<T>> data) Uncounts some original data contained in a given iterable collection.long
Returns the total count of all values observed; both within and without the entire distribution.long
Returns the frequency count of values in all upper tail bins (if any).long
upperTailCount
(int dim) Returns the frequency count of values in the upper tail bin (if any) for the given dimension.long
Returns the frequency count of all values in the middle of the distribution.long
valueCount
(int dim) Returns the frequency count of all values in the middle of the distribution for a given dimension.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
HistogramNd
Construct a histogram from a list of bin mapping algorithms. Use countData() to populate it.- Parameters:
mappers
- The algorithms used to map values to bins
-
HistogramNd
Construct a histogram whose bin mappings match another histogram. After this construction the histogram bins are unpopulated.- Parameters:
other
- The histogram to copy.
-
HistogramNd
Construct a histogram from an iterable set of data and a list of bin mapping algorithms. Must be given one iterable data source that returns multiple data values at each point.- Parameters:
data
- The iterable set of values to calculate uponmappers
- The algorithms used to map values to bins
-
HistogramNd
Construct a histogram from an iterable set of data and a list of bin mapping algorithms. Must be given multiple iterable data sources that each return a single data value at each point.- Parameters:
data
- The iterable set of values to calculate uponmappers
- The algorithms used to map values to bins
-
-
Method Details
-
hasTails
public boolean hasTails(int dim) Returns true if the histogram has tail bins which count extreme values for the given dimension. -
hasTails
public boolean hasTails()Returns true if the histogram has tail bins which count extreme values for one or more dimensions -
lowerTailCount
public long lowerTailCount(int dim) Returns the frequency count of values in the lower tail bin (if any) for the given dimension. -
lowerTailCount
public long lowerTailCount()Returns the frequency count of values in all lower tail bins (if any). -
upperTailCount
public long upperTailCount(int dim) Returns the frequency count of values in the upper tail bin (if any) for the given dimension. -
upperTailCount
public long upperTailCount()Returns the frequency count of values in all upper tail bins (if any). -
valueCount
public long valueCount(int dim) Returns the frequency count of all values in the middle of the distribution for a given dimension. -
valueCount
public long valueCount()Returns the frequency count of all values in the middle of the distribution. -
distributionCount
public long distributionCount(int dim, long dimVal) Returns the frequency count of all values in the specified dimension of the distribution: lower tail + middle + upper tail. Does not include ignored values. -
distributionCount
public long distributionCount()Returns the frequency count of all values in the distribution: lower tail + middle + upper tail. Does not include ignored values. -
ignoredCount
public long ignoredCount()Returns the frequency count of values that were ignored because they could not be mapped to any bin. -
totalCount
public long totalCount()Returns the total count of all values observed; both within and without the entire distribution. Thus it includes ignored values. One should decide carefully between using distributionCount() and totalCount(). -
frequency
Returns the frequency count of values within a bin using a set of representative values. Note that multiple values can be mapped to one bin so this is NOT the frequency count of this exact set of values in the distribution.- Parameters:
values
- A set of representative values of interest
-
frequency
public long frequency(long[] binPos) Returns the frequency count of the values within a bin. -
relativeFrequency
Returns the relative frequency of values within a bin using a set of representative values. Note that multiple values can be mapped to one bin so this is NOT the relative frequency of this exact set of values in the distribution.This calculation is of the number of values in the bin divided by either the number of values in the distribution or the number of values in the center of the distribution (tails ignored).
One can devise other ways to count relative frequencies that consider ignored values also. If needed one can use the various count methods and frequency methods to calculate any relative frequency desired.
- Parameters:
values
- A representative set of values of interestincludeTails
- Flag for determining whether to include tails in calculation.
-
relativeFrequency
public double relativeFrequency(long[] binPos, boolean includeTails) Returns the relative frequency of values within a bin.This calculation is of the number of values in the bin divided by either the number of values in the distribution or the number of values in the center of the distribution (tails ignored).
One can devise other ways to count relative frequencies that consider ignored values also. If needed one can use the various count methods and frequency methods to calculate any relative frequency desired.
- Parameters:
binPos
- The position of the bin of interestincludeTails
- Flag for determining whether to include tails in calculation.
-
getBinCount
public long getBinCount()Returns the number of bins contained in the histogram. -
map
Fills a bin position by mapping from a set of representative values. -
getCenterValues
Gets the values associated with the center of a bin.- Parameters:
binPos
- The bin index of interestvalues
- The outputs to fill with the center values
-
getLowerBounds
Gets the values associated with the left edge of a bin.- Parameters:
binPos
- The bin index of interestvalues
- The outputs to fill with the left edge values
-
getUpperBounds
Gets the values associated with the right edge of a bin.- Parameters:
binPos
- The bin index of interestvalues
- The outputs to fill with the right edge values
-
includesUpperBounds
public boolean includesUpperBounds(long[] binPos) Returns true if the given bin interval is closed on the right- Parameters:
binPos
- The bin number of the interval of interest
-
includesLowerBounds
public boolean includesLowerBounds(long[] binPos) Returns true if the given bin interval is closed on the left- Parameters:
binPos
- The bin number of the interval of interest
-
includesUpperBound
public boolean includesUpperBound(int dim, long binPos) Returns true if the given bin interval is closed on the right for the given dimension.- Parameters:
dim
- The dimension of interestbinPos
- The bin number of the interval of interest
-
includesLowerBound
public boolean includesLowerBound(int dim, long binPos) Returns true if the given bin interval is closed on the left for the given dimension.- Parameters:
dim
- The dimension of interestbinPos
- The bin number of the interval of interest
-
isInLowerTail
Returns true if a given set of values are mapped to the lower tail of the distribution.- Parameters:
values
- The set of values to determine the location of
-
isInLowerTail
Returns true if a given value for a given dimension is mapped to the lower tail of the distribution.- Parameters:
dim
- The dimension number of the axis of interestvalue
- The value to determine the location of
-
isInUpperTail
Returns true if a given set of values are mapped to the upper tail of the distribution.- Parameters:
values
- The set of values to determine the location of
-
isInUpperTail
Returns true if a given value for a given dimension is mapped to the upper tail of the distribution.- Parameters:
dim
- The dimension number of the axis of interestvalue
- The value to determine the location of
-
isInMiddle
Returns true if a given set of values are mapped to the middle of the distribution.- Parameters:
values
- The set of values to determine the location of
-
isInMiddle
Returns true if a given value for a given dimension is mapped to the middle of the distribution.- Parameters:
dim
- The dimension number of the axis of interestvalue
- The value to determine the location of
-
isOutside
Returns true if a given set of values are outside the distribution.- Parameters:
values
- The set of values to determine the location of
-
isOutside
Returns true if a given value for a given dimension is outside the distribution.- Parameters:
value
- The value to determine the location of
-
dfd
Get the discrete frequency distribution associated with this histogram. -
countData
Counts the data contained in the given data source using the underlying bin distribution.- Parameters:
data
- The total data to count
-
countData
Counts the data contained in the given data source using the underlying bin distribution.- Parameters:
data
- The total data to count
-
addData
Counts additional data contained in a given iterable collection. One can use this to update an existing histogram with a subset of values.- Parameters:
data
- The new data to count
-
addData
Counts additional data contained in a given iterable collection. One can use this to update an existing histogram with a subset of values.- Parameters:
data
- The new data to count
-
subtractData
Uncounts some original data contained in a given iterable collection. One can use this to update an existing histogram with a subset of values.- Parameters:
data
- The old data to uncount
-
subtractData
Uncounts some original data contained in a given iterable collection. One can use this to update an existing histogram with a subset of values.- Parameters:
data
- The old data to uncount
-
increment
public void increment(long[] binPos) Directly increment a bin by position.- Parameters:
binPos
- The 1-d index of the bin
-
decrement
public void decrement(long[] binPos) Directly decrement a bin by position.- Parameters:
binPos
- The 1-d index of the bin
-
increment
Directly increment a bin by value.- Parameters:
values
- The values to map to a bin position
-
decrement
Directly decrement a bin by value,- Parameters:
values
- The values to map to a bin position
-
resetCounters
public void resetCounters()Resets all data counts to 0. -
numDimensions
public int numDimensions()Return the number of dimensions of the frequency distribution of this histogram.- Specified by:
numDimensions
in interfaceEuclideanSpace
-
dimension
public long dimension(int d) Return the size of the given dimension of the frequency distribution of this histogram.- Specified by:
dimension
in interfaceDimensions
-
dimensions
public void dimensions(long[] dims) Fill the provided long[] with the sizes of all dimensions of the frequency distribution of this histogram.- Specified by:
dimensions
in interfaceDimensions
-
randomAccess
Description copied from interface:RandomAccessible
Create a random access sampler for integer coordinates.The returned random access covers as much of the domain as possible.
Please note:RandomAccessibleInterval
s have a finite domain (theirInterval
), soRandomAccessible.randomAccess()
is only guaranteed to cover this finite domain. This may lead to unexpected results when usingViews
. In the following codeRandomAccessible<T> extended = Views.extendBorder( img ) RandomAccessibleInterval<T> cropped = Views.interval( extended, img ); RandomAccess<T> a1 = extended.randomAccess(); RandomAccess<T> a2 = cropped.randomAccess();
Theaccess
a1
on the extended image is valid everywhere. However, somewhat counter-intuitively, theaccess
a2
on the extended and cropped image is only valid on the intervalimg
to which the extended image was cropped. The access is only required to cover this interval, because it is the domain of the cropped image.Views
attempts to provide the fastest possible access that meets this requirement, and will therefore strip the extension. To deal with this, if you know that you need to access pixels outside the domain of theRandomAccessibleInterval
, and you know that theRandomAccessibleInterval
is actually defined beyond its interval boundaries, then use theRandomAccessible.randomAccess(Interval)
variant and specify which interval you actually want to access. In the above example,RandomAccess<T> a2 = cropped.randomAccess( Intervals.expand( img, 10 ) );
will provide the extended access as expected.- Specified by:
randomAccess
in interfaceRandomAccessible<T>
- Returns:
- random access sampler
-
randomAccess
Description copied from interface:RandomAccessible
Create a random access sampler for integer coordinates.The returned random access is intended to be used in the specified interval only. Thus, the RandomAccessible may provide optimized versions. If the interval is completely contained in the domain, the random access is guaranteed to provide the same values as that obtained by
RandomAccessible.randomAccess()
within the interval.- Specified by:
randomAccess
in interfaceRandomAccessible<T>
- Parameters:
interval
- in which interval you intend to use the random access.- Returns:
- random access sampler
-
min
public long min(int d) Description copied from interface:Interval
Get the minimum in dimension d. -
min
public void min(long[] min) Description copied from interface:Interval
Write the minimum of each dimension into long[]. -
min
Description copied from interface:Interval
Sets aPositionable
to the minimum of thisInterval
-
max
public long max(int d) Description copied from interface:Interval
Get the maximum in dimension d. -
max
public void max(long[] max) Description copied from interface:Interval
Write the maximum of each dimension into long[]. -
max
Description copied from interface:Interval
Sets aPositionable
to the maximum of thisInterval
-
realMin
public double realMin(int d) Description copied from interface:RealInterval
Get the minimum in dimension d.- Specified by:
realMin
in interfaceRealInterval
- Parameters:
d
- dimension- Returns:
- minimum in dimension d.
-
realMin
public void realMin(double[] min) Description copied from interface:RealInterval
Write the minimum of each dimension into double[].- Specified by:
realMin
in interfaceRealInterval
-
realMin
Description copied from interface:RealInterval
Sets aRealPositionable
to the minimum of thisInterval
- Specified by:
realMin
in interfaceRealInterval
-
realMax
public double realMax(int d) Description copied from interface:RealInterval
Get the maximum in dimension d.- Specified by:
realMax
in interfaceRealInterval
- Parameters:
d
- dimension- Returns:
- maximum in dimension d.
-
realMax
public void realMax(double[] max) Description copied from interface:RealInterval
Write the maximum of each dimension into double[].- Specified by:
realMax
in interfaceRealInterval
-
realMax
Description copied from interface:RealInterval
Sets aRealPositionable
to the maximum of thisInterval
- Specified by:
realMax
in interfaceRealInterval
-
cursor
Description copied from interface:IterableRealInterval
Returns a
RealCursor
that iterates with optimal speed without calculating the location at each iteration step. Localization is performed on demand.Use this where localization is required rarely/ not for each iteration.
- Specified by:
cursor
in interfaceIterableInterval<T>
- Specified by:
cursor
in interfaceIterableRealInterval<T>
- Returns:
- fast iterating iterator
-
localizingCursor
Description copied from interface:IterableRealInterval
Returns a
RealLocalizable
Iterator
that calculates its location at each iteration step. That is, localization is performed with optimal speed.Use this where localization is required often/ for each iteration.
- Specified by:
localizingCursor
in interfaceIterableInterval<T>
- Specified by:
localizingCursor
in interfaceIterableRealInterval<T>
- Returns:
- fast localizing iterator
-
size
public long size()Description copied from interface:IterableRealInterval
Returns the number of elements in this
Function
.- Specified by:
size
in interfaceIterableRealInterval<T>
- Returns:
- number of elements
-
firstElement
Description copied from interface:IterableRealInterval
Get the first element of thisIterableRealInterval
. This is a shortcut forcursor().next()
. This can be used to create a new variable of type T usingfirstElement().createVariable()
, which is useful in generic methods to store temporary results, e.g., a running sum over pixels in theIterableRealInterval
.- Specified by:
firstElement
in interfaceIterableRealInterval<T>
- Returns:
- the first element in iteration order.
-
iterationOrder
Description copied from interface:IterableRealInterval
Returns the iteration order of thisIterableRealInterval
. If the returned object equals (Object.equals(Object)
) the iteration order of anotherIterableRealInterval
f then they can be copied by synchronous iteration. That is, having anIterator
on this and anotherIterator
on f, moving both in synchrony will point both of them to corresponding locations in their source domain. In other words, this and f have the same iteration order and means and the same number of elements.- Specified by:
iterationOrder
in interfaceIterableRealInterval<T>
- Returns:
- the iteration order of this
IterableRealInterval
. - See Also:
-
iterator
-
factory
Description copied from interface:Img
Get aImgFactory
that createsImg
s of the same kind as this one. This is useful to create Imgs for temporary storage in generic methods where the specific Img type is unknown. Note, that the factory can be used even if all references to this Img have been invalidated. -
copy
-