Class DiscreteFrequencyDistribution

java.lang.Object
net.imglib2.histogram.DiscreteFrequencyDistribution
All Implemented Interfaces:
Iterable<LongType>, Dimensions, EuclideanSpace, Img<LongType>, Interval, IterableInterval<LongType>, IterableRealInterval<LongType>, RandomAccessible<LongType>, RandomAccessibleInterval<LongType>, RealInterval

public class DiscreteFrequencyDistribution extends Object implements Img<LongType>
This class represents an n-dimensional set of counters. Histogram implementations use these for tracking value counts.
Author:
Barry DeZonia
  • Constructor Details

    • DiscreteFrequencyDistribution

      public DiscreteFrequencyDistribution(long[] binCounts)
      Construct an n-dimensional counter with the given number of bins
    • DiscreteFrequencyDistribution

      public DiscreteFrequencyDistribution(Img<LongType> img)
      Construct an n-dimensional counter using a provided Img<LongType> to store counts.
  • Method Details

    • 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 List<long[]> modePositions()
      Returns a list of bin positions of the highest frequency bins.
    • randomAccess

      public RandomAccess<LongType> 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: RandomAccessibleIntervals have a finite domain (their Interval), so RandomAccessible.randomAccess() is only guaranteed to cover this finite domain. This may lead to unexpected results when using Views. In the following code
       RandomAccessible<T> extended = Views.extendBorder( img )
       RandomAccessibleInterval<T> cropped = Views.interval( extended, img );
       RandomAccess<T> a1 = extended.randomAccess();
       RandomAccess<T> a2 = cropped.randomAccess();
       
      The access a1 on the extended image is valid everywhere. However, somewhat counter-intuitively, the access a2 on the extended and cropped image is only valid on the interval img 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 the RandomAccessibleInterval, and you know that the RandomAccessibleInterval is actually defined beyond its interval boundaries, then use the RandomAccessible.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 interface RandomAccessible<LongType>
      Returns:
      random access sampler
    • randomAccess

      public RandomAccess<LongType> randomAccess(Interval interval)
      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 interface RandomAccessible<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: EuclideanSpace
      Gets the space's number of dimensions.
      Specified by:
      numDimensions in interface EuclideanSpace
    • min

      public long min(int d)
      Description copied from interface: Interval
      Get the minimum in dimension d.
      Specified by:
      min in interface Interval
      Parameters:
      d - dimension
      Returns:
      minimum in dimension d.
    • min

      public void min(long[] min)
      Description copied from interface: Interval
      Write the minimum of each dimension into long[].
      Specified by:
      min in interface Interval
      Parameters:
      min -
    • min

      public void min(Positionable min)
      Description copied from interface: Interval
      Sets a Positionable to the minimum of this Interval
      Specified by:
      min in interface Interval
      Parameters:
      min -
    • max

      public long max(int d)
      Description copied from interface: Interval
      Get the maximum in dimension d.
      Specified by:
      max in interface Interval
      Parameters:
      d - dimension
      Returns:
      maximum in dimension d.
    • max

      public void max(long[] max)
      Description copied from interface: Interval
      Write the maximum of each dimension into long[].
      Specified by:
      max in interface Interval
      Parameters:
      max -
    • max

      public void max(Positionable max)
      Description copied from interface: Interval
      Sets a Positionable to the maximum of this Interval
      Specified by:
      max in interface Interval
      Parameters:
      max -
    • realMin

      public double realMin(int d)
      Description copied from interface: RealInterval
      Get the minimum in dimension d.
      Specified by:
      realMin in interface RealInterval
      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 interface RealInterval
      Parameters:
      min -
    • realMin

      public void realMin(RealPositionable min)
      Description copied from interface: RealInterval
      Sets a RealPositionable to the minimum of this Interval
      Specified by:
      realMin in interface RealInterval
      Parameters:
      min -
    • realMax

      public double realMax(int d)
      Description copied from interface: RealInterval
      Get the maximum in dimension d.
      Specified by:
      realMax in interface RealInterval
      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 interface RealInterval
      Parameters:
      max -
    • realMax

      public void realMax(RealPositionable max)
      Description copied from interface: RealInterval
      Sets a RealPositionable to the maximum of this Interval
      Specified by:
      realMax in interface RealInterval
      Parameters:
      max -
    • dimensions

      public void dimensions(long[] dimensions)
      Description copied from interface: Dimensions
      Write the number of pixels in each dimension into long[].
      Specified by:
      dimensions in interface Dimensions
      Parameters:
      dimensions -
    • dimension

      public long dimension(int d)
      Description copied from interface: Dimensions
      Get the number of pixels in a given dimension d.
      Specified by:
      dimension in interface Dimensions
      Parameters:
      d -
    • cursor

      public Cursor<LongType> 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 interface IterableInterval<LongType>
      Specified by:
      cursor in interface IterableRealInterval<LongType>
      Returns:
      fast iterating iterator
    • localizingCursor

      public Cursor<LongType> 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 interface IterableInterval<LongType>
      Specified by:
      localizingCursor in interface IterableRealInterval<LongType>
      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 interface IterableRealInterval<LongType>
      Returns:
      number of elements
    • firstElement

      public LongType firstElement()
      Description copied from interface: IterableRealInterval
      Get the first element of this IterableRealInterval. This is a shortcut for cursor().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 the IterableRealInterval.
      Specified by:
      firstElement in interface IterableRealInterval<LongType>
      Returns:
      the first element in iteration order.
    • iterationOrder

      public Object iterationOrder()
      Description copied from interface: IterableRealInterval
      Returns the iteration order of this IterableRealInterval. If the returned object equals (Object.equals(Object)) the iteration order of another IterableRealInterval f then they can be copied by synchronous iteration. That is, having an Iterator on this and another Iterator 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 interface IterableRealInterval<LongType>
      Returns:
      the iteration order of this IterableRealInterval.
      See Also:
    • iterator

      public Iterator<LongType> iterator()
      Specified by:
      iterator in interface Iterable<LongType>
    • factory

      public ImgFactory<LongType> factory()
      Description copied from interface: Img
      Get a ImgFactory that creates Imgs 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.
      Specified by:
      factory in interface Img<LongType>
      Returns:
      a factory for Imgs of the same kind as this one.
    • copy

      Specified by:
      copy in interface Img<LongType>
      Returns:
      - A copy of the current Img instance, all pixels are duplicated