Package biopb.image
Class Utils
java.lang.Object
biopb.image.Utils
-
Method Summary
Modifier and TypeMethodDescriptionstatic net.imglib2.RandomAccessibleInterval<?>deserializeImageData(ImageData imageData) Deserialize an ImageData protobuf message to a RandomAccessibleInterval.getImageDataDimLabels(ImageData imageData) Get dimension labels from ImageData.static long[]getImageDataShape(ImageData imageData) Get shape from ImageData.static net.imglib2.RandomAccessibleInterval<?>intervalFromTensor(Tensor tensor) Deserialize a Tensor protobuf to a RandomAccessibleInterval.static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>>
ImageDataserializeFromIntervalToImageData(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>>
ImageDataserializeFromIntervalToImageData(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>>
TensortensorFromInterval(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>>
TensortensorFromInterval(net.imglib2.RandomAccessibleInterval<T> interval, List<String> dimLabels) Serialize a RandomAccessibleInterval to Tensor protobuf.
-
Method Details
-
deserializeImageData
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 serializedimLabels- 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
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
Get dimension labels from ImageData.- Parameters:
imageData- the ImageData protobuf- Returns:
- list of dimension labels, or null if not available
-
getImageDataShape
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 serializedimLabels- dimension labels for the tensor (must match number of dimensions)- Returns:
- an ImageData protobuf message with eager_data set
-