Class DiscreteFrequencyDistribution
- java.lang.Object
-
- net.imglib2.histogram.DiscreteFrequencyDistribution
-
- All Implemented Interfaces:
java.lang.Iterable<LongType>,Dimensions,EuclideanSpace,Img<LongType>,Interval,IterableInterval<LongType>,IterableRealInterval<LongType>,RandomAccessible<LongType>,RandomAccessibleInterval<LongType>,RealInterval,Typed<LongType>
public class DiscreteFrequencyDistribution extends java.lang.Object implements Img<LongType>
This class represents an n-dimensional set of counters. Histogram implementations use these for tracking value counts.
-
-
Field Summary
Fields Modifier and Type Field Description private RandomAccess<LongType>accessorprivate Img<LongType>countsprivate longtotalValues
-
Constructor Summary
Constructors Constructor Description DiscreteFrequencyDistribution(long[] binCounts)Construct an n-dimensional counter with the given number of binsDiscreteFrequencyDistribution(Img<LongType> img)Construct an n-dimensional counter using a providedImg<LongType>to store counts.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DiscreteFrequencyDistributioncopy()Cursor<LongType>cursor()Returns aRealCursorthat iterates with optimal speed without calculating the location at each iteration step.voiddecrement(long[] binPos)Decrements the frequency count of a specified bin.longdimension(int d)Default implementation ofDimensions.dimension(int).voiddimensions(long[] dimensions)Write the number of pixels in each dimension into long[].ImgFactory<LongType>factory()Get aImgFactorythat createsImgs of the same kind as this one.LongTypefirstElement()Get the first element of thisIterableRealInterval.longfrequency(long[] binPos)Returns the frequency count associated with a given bin.LongTypegetType()Get an instance ofT.voidincrement(long[] binPos)Increments the frequency count of a specified bin.java.lang.ObjectiterationOrder()Returns the iteration order of thisIterableRealInterval.java.util.Iterator<LongType>iterator()Cursor<LongType>localizingCursor()Returns aRealLocalizableIteratorthat calculates its location at each iteration step.longmax(int d)Get the maximum in dimension d.voidmax(long[] max)Write the maximum of each dimension into long[].voidmax(Positionable max)Sets aPositionableto the maximum of thisIntervallongmin(int d)Get the minimum in dimension d.voidmin(long[] min)Write the minimum of each dimension into long[].voidmin(Positionable min)Sets aPositionableto the minimum of thisIntervallongmodeCount()Returns the highest frequency count found within the bins.java.util.List<long[]>modePositions()Returns a list of bin positions of the highest frequency bins.intnumDimensions()Gets the space's number of dimensions.RandomAccess<LongType>randomAccess()Create a random access sampler for integer coordinates.RandomAccess<LongType>randomAccess(Interval interval)Create a random access sampler for integer coordinates.voidrealMax(double[] max)Write the maximum of each dimension into double[].doublerealMax(int d)Get the maximum in dimension d.voidrealMax(RealPositionable max)Sets aRealPositionableto the maximum of thisIntervalvoidrealMin(double[] min)Write the minimum of each dimension into double[].doublerealMin(int d)Get the minimum in dimension d.voidrealMin(RealPositionable min)Sets aRealPositionableto the minimum of thisIntervaldoublerelativeFrequency(long[] binPos)Returns the relative frequency(0 <= f <= 1)associated with a given bin.voidresetCounters()Resets all frequency counts to zero.voidsetFrequency(long[] binPos, long value)Sets the frequency count associated with a given bin.longsize()Returns the number of elements in thisFunction.longtotalValues()Returns the total number of values counted by this distribution.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.imglib2.Dimensions
dimensions, dimensionsAsLongArray, dimensionsAsPoint
-
Methods inherited from interface net.imglib2.Interval
maxAsLongArray, maxAsPoint, minAsLongArray, minAsPoint
-
Methods inherited from interface net.imglib2.IterableInterval
localizingSpliterator, spliterator
-
Methods inherited from interface net.imglib2.IterableRealInterval
parallelStream, stream
-
Methods inherited from interface net.imglib2.RandomAccessible
getAt, getAt, getAt
-
Methods inherited from interface net.imglib2.RealInterval
maxAsDoubleArray, maxAsRealPoint, minAsDoubleArray, minAsRealPoint
-
-
-
-
Field Detail
-
accessor
private final RandomAccess<LongType> accessor
-
totalValues
private long totalValues
-
-
Method Detail
-
resetCounters
public void resetCounters()
Resets all frequency counts to zero.
-
frequency
public long frequency(long[] binPos)
Returns the frequency count associated with a given bin.
-
setFrequency
public void setFrequency(long[] binPos, long value)Sets the frequency count associated with a given bin.
-
relativeFrequency
public double relativeFrequency(long[] binPos)
Returns the relative frequency(0 <= f <= 1)associated with a given bin.
-
increment
public void increment(long[] binPos)
Increments the frequency count of a specified bin.
-
decrement
public void decrement(long[] binPos)
Decrements the frequency count of a specified bin.
-
totalValues
public long totalValues()
Returns the total number of values counted by this distribution.
-
modeCount
public long modeCount()
Returns the highest frequency count found within the bins.
-
modePositions
public java.util.List<long[]> modePositions()
Returns a list of bin positions of the highest frequency bins.
-
randomAccess
public RandomAccess<LongType> randomAccess()
Description copied from interface:RandomAccessibleCreate a random access sampler for integer coordinates.The returned random access covers as much of the domain as possible.
Please note:RandomAccessibleIntervals 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();
Theaccessa1on the extended image is valid everywhere. However, somewhat counter-intuitively, theaccessa2on the extended and cropped image is only valid on the intervalimgto which the extended image was cropped. The access is only required to cover this interval, because it is the domain of the cropped image.Viewsattempts 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 theRandomAccessibleIntervalis 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:
randomAccessin interfaceRandomAccessible<LongType>- Returns:
- random access sampler
-
randomAccess
public RandomAccess<LongType> randomAccess(Interval interval)
Description copied from interface:RandomAccessibleCreate 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:
randomAccessin interfaceRandomAccessible<LongType>- Parameters:
interval- in which interval you intend to use the random access.- Returns:
- random access sampler
-
numDimensions
public int numDimensions()
Description copied from interface:EuclideanSpaceGets the space's number of dimensions.- Specified by:
numDimensionsin interfaceEuclideanSpace
-
min
public long min(int d)
Description copied from interface:IntervalGet the minimum in dimension d.
-
min
public void min(long[] min)
Description copied from interface:IntervalWrite the minimum of each dimension into long[].
-
min
public void min(Positionable min)
Description copied from interface:IntervalSets aPositionableto the minimum of thisInterval
-
max
public long max(int d)
Description copied from interface:IntervalGet the maximum in dimension d.
-
max
public void max(long[] max)
Description copied from interface:IntervalWrite the maximum of each dimension into long[].
-
max
public void max(Positionable max)
Description copied from interface:IntervalSets aPositionableto the maximum of thisInterval
-
realMin
public double realMin(int d)
Description copied from interface:RealIntervalGet the minimum in dimension d.- Specified by:
realMinin interfaceInterval- Specified by:
realMinin interfaceRealInterval- Parameters:
d- dimension- Returns:
- minimum in dimension d.
-
realMin
public void realMin(double[] min)
Description copied from interface:RealIntervalWrite the minimum of each dimension into double[].- Specified by:
realMinin interfaceRealInterval
-
realMin
public void realMin(RealPositionable min)
Description copied from interface:RealIntervalSets aRealPositionableto the minimum of thisInterval- Specified by:
realMinin interfaceRealInterval
-
realMax
public double realMax(int d)
Description copied from interface:RealIntervalGet the maximum in dimension d.- Specified by:
realMaxin interfaceInterval- Specified by:
realMaxin interfaceRealInterval- Parameters:
d- dimension- Returns:
- maximum in dimension d.
-
realMax
public void realMax(double[] max)
Description copied from interface:RealIntervalWrite the maximum of each dimension into double[].- Specified by:
realMaxin interfaceRealInterval
-
realMax
public void realMax(RealPositionable max)
Description copied from interface:RealIntervalSets aRealPositionableto the maximum of thisInterval- Specified by:
realMaxin interfaceRealInterval
-
dimensions
public void dimensions(long[] dimensions)
Description copied from interface:DimensionsWrite the number of pixels in each dimension into long[].- Specified by:
dimensionsin interfaceDimensions
-
dimension
public long dimension(int d)
Description copied from interface:IntervalDefault implementation ofDimensions.dimension(int).- Specified by:
dimensionin interfaceDimensions- Specified by:
dimensionin interfaceInterval
-
cursor
public Cursor<LongType> cursor()
Description copied from interface:IterableRealIntervalReturns a
RealCursorthat 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:
cursorin interfaceIterableInterval<LongType>- Specified by:
cursorin interfaceIterableRealInterval<LongType>- Specified by:
cursorin interfaceRandomAccessibleInterval<LongType>- Returns:
- fast iterating iterator
-
localizingCursor
public Cursor<LongType> localizingCursor()
Description copied from interface:IterableRealIntervalReturns a
RealLocalizableIteratorthat 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:
localizingCursorin interfaceIterableInterval<LongType>- Specified by:
localizingCursorin interfaceIterableRealInterval<LongType>- Specified by:
localizingCursorin interfaceRandomAccessibleInterval<LongType>- Returns:
- fast localizing iterator
-
size
public long size()
Description copied from interface:IterableRealIntervalReturns the number of elements in this
Function.- Specified by:
sizein interfaceIterableRealInterval<LongType>- Specified by:
sizein interfaceRandomAccessibleInterval<LongType>- Returns:
- number of elements
-
firstElement
public LongType firstElement()
Description copied from interface:IterableRealIntervalGet the first element of thisIterableRealInterval. This is a shortcut forcursor().next().This can be used to create a new variable of type T using
firstElement().createVariable(), which is useful in generic methods to store temporary results, e.g., a running sum over pixels in theIterableRealInterval.- Specified by:
firstElementin interfaceIterableRealInterval<LongType>- Returns:
- the first element in iteration order.
-
iterationOrder
public java.lang.Object iterationOrder()
Description copied from interface:IterableRealIntervalReturns the iteration order of thisIterableRealInterval. If the returned object equals (Object.equals(Object)) the iteration order of anotherIterableRealIntervalf then they can be copied by synchronous iteration. That is, having anIteratoron this and anotherIteratoron 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:
iterationOrderin interfaceIterableRealInterval<LongType>- Specified by:
iterationOrderin interfaceRandomAccessibleInterval<LongType>- Returns:
- the iteration order of this
IterableRealInterval. - See Also:
FlatIterationOrder
-
iterator
public java.util.Iterator<LongType> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<LongType>- Specified by:
iteratorin interfaceIterableRealInterval<LongType>
-
factory
public ImgFactory<LongType> factory()
Description copied from interface:ImgGet aImgFactorythat createsImgs 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
public DiscreteFrequencyDistribution copy()
-
-