Class FlatCollections


  • public final class FlatCollections
    extends java.lang.Object
    Utility class for wrapping ImgLib2 images as read-only Collections.

    This is useful when you want to pass an ImgLib2 IterableInterval or RandomAccessibleInterval to an API that works with Java Collection objects, such as Google Guava's Quantiles.

    • Constructor Detail

      • FlatCollections

        public FlatCollections()
    • Method Detail

      • collection

        public static <T,​E> java.util.Collection<E> collection​(IterableInterval<T> image,
                                                                     java.util.function.Function<T,​E> converter)
        Wraps an IterableInterval as a Collection. The wrapped collection is read-only, throwing UnsupportedOperationException if the caller attempts to mutate it.

        With this method, and unlike list(RandomAccessibleInterval, Function), the iteration order of the wrapped collection will match that of the source image. It is best not to make any assumptions about the iteration order of the collection—only that each element of the wrapped image will appear once in the iteration.

        Parameters:
        image - The IterableInterval to wrap as a Java collection.
        converter - Conversion function to use for accessing elements of the collection. This function will be transparently called on the corresponding source sample from the ImgLib2 image.
        Returns:
        Wrapped Collection of the converted type.
      • booleanCollection

        public static java.util.Collection<java.lang.Boolean> booleanCollection​(IterableInterval<? extends BooleanType<?>> image)
        Wraps a BooleanType iterable image as a collection.

        Warning: Don't make any assumption on the iteration order, only that each pixel will appear once. Performance may be low as the collection uses boxed types.

        Parameters:
        image - The IterableInterval to wrap as a Java collection.
        Returns:
        Wrapped Collection with Boolean elements.
        See Also:
        collection(IterableInterval, Function)
      • doubleCollection

        public static java.util.Collection<java.lang.Double> doubleCollection​(IterableInterval<? extends RealType<?>> image)
        Wraps a RealType iterable image as a collection.

        Warning: Don't make any assumption on the iteration order, only that each pixel will appear once. Performance may be low as the collection uses boxed types.

        Parameters:
        image - The IterableInterval to wrap as a Java collection.
        Returns:
        Wrapped Collection with Double elements.
        See Also:
        collection(IterableInterval, Function)
      • floatCollection

        public static java.util.Collection<java.lang.Float> floatCollection​(IterableInterval<? extends RealType<?>> image)
        Wraps a RealType iterable image as a collection.

        Warning: Don't make any assumption on the iteration order, only that each pixel will appear once. Performance may be low as the collection uses boxed types.

        Parameters:
        image - The IterableInterval to wrap as a Java collection.
        Returns:
        Wrapped Collection with Float elements.
        See Also:
        collection(IterableInterval, Function)
      • integerCollection

        public static java.util.Collection<java.lang.Integer> integerCollection​(IterableInterval<? extends IntegerType<?>> image)
        Wraps an IntegerType iterable image as a collection.

        Warning: Don't make any assumption on the iteration order, only that each pixel will appear once. Performance may be low as the collection uses boxed types.

        Parameters:
        image - The IterableInterval to wrap as a Java collection.
        Returns:
        Wrapped Collection with Integer elements.
        See Also:
        collection(IterableInterval, Function)
      • longCollection

        public static java.util.Collection<java.lang.Long> longCollection​(IterableInterval<? extends IntegerType<?>> image)
        Wraps an IntegerType iterable image as a collection.

        Warning: Don't make any assumption on the iteration order, only that each pixel will appear once. Performance may be low as the collection uses boxed types.

        Parameters:
        image - The IterableInterval to wrap as a Java collection.
        Returns:
        Wrapped Collection with Long elements.
        See Also:
        collection(IterableInterval, Function)
      • bigIntegerCollection

        public static java.util.Collection<java.math.BigInteger> bigIntegerCollection​(IterableInterval<? extends IntegerType<?>> image)
        Wraps an IntegerType iterable image as a collection.

        Warning: Don't make any assumption on the iteration order, only that each pixel will appear once. Performance may be low as the collection uses boxed types.

        Parameters:
        image - The IterableInterval to wrap as a Java collection.
        Returns:
        Wrapped Collection with BigInteger elements.
        See Also:
        collection(IterableInterval, Function)
      • sizeAsInt

        private static int sizeAsInt​(long size)