Convert Multipage Tiff to HDF5

Hi there,

I’m new to this forum but hoping that someone can help me out. I’m using ilastik pixel classification to identify cells in a multipage tiff image. This works well but is really slow, and as a result, I want to first convert my multipage tiff images into HDF5 images. I have used the Ilastik Fiji plugin for this purpose with some success, but I have hundreds of images that need to be converted, so I’m hoping to write a script that I can run to open the images and export them as HDF5.

I’m tried looking at the Fiji ilastik plugin source code, but I’m not familiar enough with Java to understand it. I’ve come across code using this forum for processing multiple images in a folder (here) but I don’t know how to take this one step further and call on the Export HDF5 plug in.

If anyone could point me in the right direction, I would be very grateful!

Thanks!

The code I’m found thus far.

/*

  • Macro template to process multiple images in a folder
    */

#@ File (label = “Input directory”, style = “directory”) input
#@ File (label = “Output directory”, style = “directory”) output
#@ String (label = “File suffix”, value = “.tif”) suffix

// See also Process_Folder.py for a version of this code
// in the Python scripting language.

processFolder(input);

// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
list = getFileList(input);
list = Array.sort(list);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + File.separator + list[i]))
processFolder(input + File.separator + list[i]);
if(endsWith(list[i], suffix))
processFile(input, output, list[i]);
}
}

function processFile(input, output, file) {
// Do the processing here by adding your own code.
// Leave the print statements until things work, then remove them.
// THIS IS WHERE YOU CAN OPEN YOUR FILES, ETC AS YOU WANT
print("Processing: " + input + File.separator + file);
print("Saving to: " + output);
}

Hi @Presley,

I am, too, no Fiji Macro expert. But I found that there is one crucial thing that you need to know, to make it very enjoyable: the macro recorder.

With the ilastik import/export plugin, you’d get an output like the following (calling it manually, from the gui, with the recorder running):

run("Export HDF5", "select=/tmp/test.h5 exportpath=/tmp/test.h5 datasetname=data compressionlevel=0 input=2d_cells_apoptotic_1channel.png");

So you can see the basic syntax of the run command is the plugin command name (Export HDF5) and a string of arguments that you’d then have to compose…

So for your case

function processFile(input, output, file) {
    // Do the processing here by adding your own code.
    // Leave the print statements until things work, then remove them.
    // THIS IS WHERE YOU CAN OPEN YOUR FILES, ETC AS YOU WANT
    outputFile = output + File.separator + file + ".h5";
    inputFile =  input + File.separator + file;
    print("Processing: " + inputFile);
    print("Saving to: " + output);
    // open the image
    open(inputFile);
    // rename window, to have convenient access
    rename("inputImage");
    // do the export
    run("Export HDF5", "select="+ outputFile +" datasetname=data compressionlevel=0 input=inputImage");
    // close the input image in each iteration, otherwise, there will be a lot of open windows
    close("inputImage");
}

Disclaimer: this code is not tested, but should get you started

note that you don’t have to supply the select AND the exportpath. I only specified select.