First you’d have to determine what is causing the slow down.
If “Use SCIFIO” is unchecked in the “Edit - Options - ImageJ2”, then ImageJ is using its own internal libraries, or if the format is unknown to ImageJ, it delegates to the BioFormats library.
If your image is e.g. a TIFF file, use then
ij.io.TiffDecoder directly, see TiffDecoder, and also see Opener at its
openImage method, whose code is self-explanatory.
To bypass it all, if your image is uncompressed, you can also open images raw. One high-level way is to use the Raw class, by passing it to a FileInfo.open that you filled in with the details (dimensions, bit type, filepath, etc.).
If your file format is uncompressed, you can also read the image data directly into an array and make the appropriate
ImageProcessor from that. E.g. if you know the dimensions and pixel depth, read the image part of from the file with a RandomAccessFile by skipping the length of the header, reading the data into a
byte of length
width * height * pixelDepth, then wrapping the
byte array in a ByteBuffer, then converting the buffer to that of the pixel type (e.g. a float, therefore a
FloatBuffer) and reading the data by filling an e.g.
float array (if the image is 32-bit gray) from the
Here is an example of reading a 32-bit image into a
FloatProcessor using the
RandomAccessFile approach: https://github.com/acardona/scripts/blob/master/python/imagej/IsoView-GCaMP/lib/io.py#L38
def readFloats(path, dimensions, header=0, byte_order=ByteOrder.LITTLE_ENDIAN):
""" Read a file as an ArrayImg of FloatType """
size = reduce(operator.mul, dimensions)
ra = RandomAccessFile(path, 'r')
if header < 0:
# Interpret from the end: useful for files with variable header lengths
# such as some types of uncompressed TIFF formats
header = ra.length() + header
bytes = zeros(size * 4, 'b')
floats = zeros(size, 'f')
return ArrayImgs.floats(floats, dimensions)
There are many ways. But first you should determine why the slow loading is happening.