java.lang.Object
org.bonej.utilities.DatasetUtil
Utility class for loading raw binary 3D image data into ImageJ2 Datasets.
This class constructs Datasets by wrapping native ImageJ1 ImagePlus objects. This ensures that when legacy plugins convert these Datasets back to ImagePlus, they receive the original native byte[]/short[]/float[] arrays, avoiding the performance overhead of imglib2 wrappers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic net.imagej.DatasetloadRaw2D(File filePath, long headerOffset, int width, int height, String pixelType, boolean zeroOneBinary, String byteOrder, double spacingX, double spacingY, net.imagej.DatasetService datasetService) Loads a raw file as a 2D Dataset with spatial calibration.static net.imagej.DatasetloadRaw3D(File filePath, long headerOffset, int width, int height, int depth, String pixelType, boolean zeroOneBinary, String byteOrder, double spacingX, double spacingY, double spacingZ, net.imagej.DatasetService datasetService) Loads a raw file as a 3D Dataset with spatial calibration.static net.imagej.DatasetloadRaw3D(File filePath, long headerOffset, int width, int height, int depth, String pixelType, String byteOrder, double spacingX, double spacingY, double spacingZ, net.imagej.DatasetService datasetService) Overloaded version ofloadRaw3D(File, long, int, int, int, String, boolean, String, double, double, double, DatasetService)that does not perform (0,1) to (0,255) binary conversion.static voidsaveAsRaw(net.imagej.Dataset dataset, File outputFile) Convenience method to save a Dataset to a raw file with default little-endian byte order and no binary conversion.static voidsaveAsRaw(net.imagej.Dataset dataset, File outputFile, boolean littleEndian) Convenience method to save a Dataset to a raw file with default little-endian byte order.static voidsaveAsRaw(net.imagej.Dataset dataset, File outputFile, boolean littleEndian, boolean zeroOneBinary) Writes the pixel data of a 3D Dataset to a raw binary file.static ij.ImagePlustoImagePlus(net.imagej.Dataset dataset, net.imagej.DatasetService datasetService) Converts a Dataset to a native ImagePlus using a DatasetService to retrieve the Context and ConvertService.static ij.ImagePlustoImagePlus(net.imagej.Dataset dataset, org.scijava.Context context) Converts a Dataset to a native ImagePlus using a Context to retrieve the ConvertService.static ij.ImagePlustoImagePlus(net.imagej.Dataset dataset, org.scijava.convert.ConvertService convertService) Converts a Dataset to a native ImagePlus backed by in-memory primitive arrays.
-
Method Details
-
loadRaw3D
public static net.imagej.Dataset loadRaw3D(File filePath, long headerOffset, int width, int height, int depth, String pixelType, boolean zeroOneBinary, String byteOrder, double spacingX, double spacingY, double spacingZ, net.imagej.DatasetService datasetService) throws IOException Loads a raw file as a 3D Dataset with spatial calibration.- Parameters:
filePath- Path to the raw file on diskheaderOffset- Number of bytes to skip at the start of the filewidth- Image width (X dimension)height- Image height (Y dimension)depth- Image depth (Z dimension)pixelType- One of: "uint8", "uint16", "int16", "float32"zeroOneBinary- true if the raw data is (0,1) binary and we want (0,255) binary. Ignored if image is not 8-bit.byteOrder- One of: "Little-endian", "Big-endian"spacingX- Voxel spacing in X (mm)spacingY- Voxel spacing in Y (mm)spacingZ- Voxel spacing in Z (mm)datasetService- The DatasetService for creating the Dataset- Returns:
- A calibrated 3D Dataset backed by a native ImagePlus
- Throws:
IOException- if the file cannot be read or is too smallIllegalArgumentException- if parameters are invalid
-
loadRaw3D
public static net.imagej.Dataset loadRaw3D(File filePath, long headerOffset, int width, int height, int depth, String pixelType, String byteOrder, double spacingX, double spacingY, double spacingZ, net.imagej.DatasetService datasetService) throws IOException Overloaded version ofloadRaw3D(File, long, int, int, int, String, boolean, String, double, double, double, DatasetService)that does not perform (0,1) to (0,255) binary conversion.- Parameters:
filePath- Path to the raw file on diskheaderOffset- Number of bytes to skip at the start of the filewidth- Image width (X dimension)height- Image height (Y dimension)depth- Image depth (Z dimension)pixelType- One of: "uint8", "uint16", "int16", "float32"byteOrder- One of: "Little-endian", "Big-endian"spacingX- Voxel spacing in X (mm)spacingY- Voxel spacing in Y (mm)spacingZ- Voxel spacing in Z (mm)datasetService- The DatasetService for creating the Dataset- Returns:
- A calibrated 3D Dataset backed by a native ImagePlus
- Throws:
IOException- if the file cannot be read or is too smallIllegalArgumentException- if parameters are invalid
-
loadRaw2D
public static net.imagej.Dataset loadRaw2D(File filePath, long headerOffset, int width, int height, String pixelType, boolean zeroOneBinary, String byteOrder, double spacingX, double spacingY, net.imagej.DatasetService datasetService) throws IOException Loads a raw file as a 2D Dataset with spatial calibration.- Parameters:
filePath- Path to the raw file on diskheaderOffset- Number of bytes to skip at the start of the filewidth- Image width (X dimension)height- Image height (Y dimension)pixelType- One of: "uint8", "uint16", "int16", "float32"zeroOneBinary- true if the raw data is (0,1) binary and we want (0,255) binary. Ignored if image is not 8-bit.byteOrder- One of: "Little-endian", "Big-endian"spacingX- Voxel spacing in X (mm)spacingY- Voxel spacing in Y (mm)datasetService- The DatasetService for creating the Dataset- Returns:
- A calibrated 3D Dataset backed by a native ImagePlus
- Throws:
IOException- if the file cannot be read or is too smallIllegalArgumentException- if parameters are invalid
-
saveAsRaw
public static void saveAsRaw(net.imagej.Dataset dataset, File outputFile, boolean littleEndian, boolean zeroOneBinary) throws IOException Writes the pixel data of a 3D Dataset to a raw binary file. Uses ArrayDataAccess to get the backing array efficiently (no reflection). If the Dataset is backed by a native ImagePlus (not an ArrayImg), it falls back to cursor iteration to write the data correctly.- Parameters:
dataset- The 3D Dataset to saveoutputFile- The output file pathlittleEndian- True for little-endian byte order, false for big-endianzeroOneBinary- True if writing (0,1) binary data where 1 should be written as 1 byte (not 255)- Throws:
IOException- if the file cannot be writtenIllegalArgumentException- if the dataset is not 3DUnsupportedOperationException- if the pixel type is unsupported
-
saveAsRaw
public static void saveAsRaw(net.imagej.Dataset dataset, File outputFile, boolean littleEndian) throws IOException Convenience method to save a Dataset to a raw file with default little-endian byte order.- Parameters:
dataset- The 3D Dataset to saveoutputFile- The output file pathlittleEndian- Byte order flag- Throws:
IOException- if the file cannot be written
-
saveAsRaw
Convenience method to save a Dataset to a raw file with default little-endian byte order and no binary conversion.- Parameters:
dataset- The 3D Dataset to saveoutputFile- The output file path- Throws:
IOException- if the file cannot be written
-
toImagePlus
public static ij.ImagePlus toImagePlus(net.imagej.Dataset dataset, org.scijava.convert.ConvertService convertService) Converts a Dataset to a native ImagePlus backed by in-memory primitive arrays.- Parameters:
dataset- The Dataset to convertconvertService- The SciJava ConvertService to perform the conversion- Returns:
- A legacy ImagePlus backed by in-memory ImageStack primitive arrays.
-
toImagePlus
Converts a Dataset to a native ImagePlus using a Context to retrieve the ConvertService.- Parameters:
dataset- The Dataset to convertcontext- The SciJava Context- Returns:
- A legacy ImagePlus backed by in-memory ImageStack primitive arrays.
-
toImagePlus
public static ij.ImagePlus toImagePlus(net.imagej.Dataset dataset, net.imagej.DatasetService datasetService) Converts a Dataset to a native ImagePlus using a DatasetService to retrieve the Context and ConvertService.- Parameters:
dataset- The Dataset to convertdatasetService- The DatasetService providing the Context- Returns:
- A legacy ImagePlus backed by in-memory ImageStack primitive arrays.
-