Package biopb.image

Class Utils

java.lang.Object
biopb.image.Utils

public final class Utils extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.imglib2.RandomAccessibleInterval<?>
    Deserialize an ImageData protobuf message to a RandomAccessibleInterval.
    static List<String>
    Get dimension labels from ImageData.
    static long[]
    Get shape from ImageData.
    static net.imglib2.RandomAccessibleInterval<?>
    Deserialize a Tensor protobuf to a RandomAccessibleInterval.
    static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>>
    ImageData
    serializeFromIntervalToImageData(net.imglib2.RandomAccessibleInterval<T> crop)
    Serialize a RandomAccessibleInterval to ImageData protobuf with eager_data.
    static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>>
    ImageData
    serializeFromIntervalToImageData(net.imglib2.RandomAccessibleInterval<T> crop, List<String> dimLabels)
    Serialize a RandomAccessibleInterval to ImageData protobuf with eager_data and dimension labels.
    static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>>
    Tensor
    tensorFromInterval(net.imglib2.RandomAccessibleInterval<T> interval)
    Serialize a RandomAccessibleInterval to Tensor protobuf without dimension labels.
    static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>>
    Tensor
    tensorFromInterval(net.imglib2.RandomAccessibleInterval<T> interval, List<String> dimLabels)
    Serialize a RandomAccessibleInterval to Tensor protobuf.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • deserializeImageData

      public static net.imglib2.RandomAccessibleInterval<?> deserializeImageData(ImageData imageData)
      Deserialize an ImageData protobuf message to a RandomAccessibleInterval. Handles both eager_data (inline Tensor) and lazy_data (SerializedTensor). Also handles legacy pixels field for backward compatibility.
      Parameters:
      imageData - the protobuf message containing serialized image data
      Returns:
      a RandomAccessibleInterval (ArrayImg for eager_data, or a lazy Flight-plan-backed interval for lazy_data)
      Throws:
      IllegalArgumentException - if no data field is set or dtype is unsupported
    • tensorFromInterval

      public static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>> Tensor tensorFromInterval(net.imglib2.RandomAccessibleInterval<T> interval, List<String> dimLabels)
      Serialize a RandomAccessibleInterval to Tensor protobuf.

      Creates a generic nd tensor with optional dimension labels. The data is stored in C-order (last dimension varies fastest).

      Parameters:
      interval - the input RandomAccessibleInterval to serialize
      dimLabels - optional dimension labels (null if not needed)
      Returns:
      a Tensor protobuf message
    • tensorFromInterval

      public static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>> Tensor tensorFromInterval(net.imglib2.RandomAccessibleInterval<T> interval)
      Serialize a RandomAccessibleInterval to Tensor protobuf without dimension labels.
    • intervalFromTensor

      public static net.imglib2.RandomAccessibleInterval<?> intervalFromTensor(Tensor tensor)
      Deserialize a Tensor protobuf to a RandomAccessibleInterval.

      The returned interval has dimensions matching the Tensor's dims field, in C-order (last dimension varies fastest).

      Parameters:
      tensor - the Tensor protobuf message
      Returns:
      a RandomAccessibleInterval (ArrayImg)
    • getImageDataDimLabels

      public static List<String> getImageDataDimLabels(ImageData imageData)
      Get dimension labels from ImageData.
      Parameters:
      imageData - the ImageData protobuf
      Returns:
      list of dimension labels, or null if not available
    • getImageDataShape

      public static long[] getImageDataShape(ImageData imageData)
      Get shape from ImageData.
      Parameters:
      imageData - the ImageData protobuf
      Returns:
      array of dimension sizes, or null if not available
    • serializeFromIntervalToImageData

      public static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>> ImageData serializeFromIntervalToImageData(net.imglib2.RandomAccessibleInterval<T> crop)
      Serialize a RandomAccessibleInterval to ImageData protobuf with eager_data.
      Parameters:
      crop - the input RandomAccessibleInterval to serialize
      Returns:
      an ImageData protobuf message with eager_data set
      Throws:
      IllegalArgumentException - if dimensions are invalid
    • serializeFromIntervalToImageData

      public static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>> ImageData serializeFromIntervalToImageData(net.imglib2.RandomAccessibleInterval<T> crop, List<String> dimLabels)
      Serialize a RandomAccessibleInterval to ImageData protobuf with eager_data and dimension labels.
      Parameters:
      crop - the input RandomAccessibleInterval to serialize
      dimLabels - dimension labels for the tensor (must match number of dimensions)
      Returns:
      an ImageData protobuf message with eager_data set