Use ilastik using Fiji scripting facility and OMERO


In this section, the segmentation (using Pixel classification routine of ilastik) of the multi-z images is run in a batch mode. For this we provide scripts which run ilastik in a headless mode. The scripts provide for ilastik a batch of images (coming from an OMERO Dataset) and ilastik is segmenting these images according to the parameters configured and saved in the ilp in the manual step above. We offer two scripts covering this workflow, one running in Fiji, and the other using the python frames to export images directly from OMERO to the ilastik running headlessly. Also, we describe in this part how to use ilastik routine Object classification to classify objects on images from OMERO manually.

We will show:

  • How to run a script in Fiji, consuming the ilp file and running the segmentation of the images coming from an OMERO Dataset,
  • How to save the ROIs on the original images in OMERO.


ilastik installation

ilastik plugin for Fiji installation instructions

  • Start Fiji. Update it (Help > Update ImageJ).
  • in the Manage Update Sites check the checkbox next to the “ilastik” site.
  • After the update was successful, restart your Fiji.
  • The new ilastik menu item should be under Plugins menu.

Note: The ilastik menu item might be the last in the Plugins dropdown, not necessarily alphabetically ordered.

OMERO plugin for Fiji installation instructions



Scripting workflow on z-stacks using ilastik headless, Fiji and OMERO

For this example we will use the Groovy script analyse_dataset_ilastik.groovy. The script uses the OMERO JAVA API.

Connect to the server:

def connect_to_omero() {
    "Connect to OMERO"

    credentials = new LoginCredentials()
    simpleLogger = new SimpleLogger()
    gateway = new Gateway(simpleLogger)
    return gateway


Load the images contained in the specified dataset:

def get_images(gateway, ctx, dataset_id) {
    "List all images contained in a Dataset"

    browse = gateway.getFacility(BrowseFacility)
    ids = new ArrayList(1)
    ids.add(new Long(dataset_id))
    return browse.getImagesForDatasets(ctx, ids)

Open the images one-by-one using the Bio-Formats plugin:

def open_image_plus(HOST, USERNAME, PASSWORD, PORT, group_id, image_id) {
    "Open the image using the Bio-Formats Importer"

    StringBuilder options = new StringBuilder()
    options.append("location=[OMERO] open=[omero:server=")
    options.append("] ")
    options.append("windowless=true view=Hyperstack ")
    IJ.runPlugIn("loci.plugins.LociImporter", options.toString())

Export each image as h5 to a local folder specified interactively by the user during the run of the script. It is assumed that the folder specified by the user contains the ilastik Project prepared beforehand. The export is facilitated by the ilastik plugin for Fiji."Export HDF5", args);
        imp = IJ.getImage()

Start ilastik headless, using the Pixel classification module The script feeds into the Pixel classification ilastik module the ilastik Project created during the manual step and also the raw the new created h5 image in the step above.

    args = "select=" + output_file + " datasetname=" + inputDataset +  " axisorder=" + axisOrder            
    println "opening h5 file""Import HDF5", args)
    // run pixel classification
    input_image = output_file + "/data";
    args = "projectfilename=" + pixelClassificationProject + " saveonly=false inputimage=" + input_image + " chosenoutputtype=" + outputType;
    println "running Pixel Classification Prediction""Run Pixel Classification Prediction", args);

The headless ilastik Pixel classification" module produces Probabilities map - this map is immediately opened into Fiji via the ilastik plugin for Fiji.

In Fiji, the Analyze Particles plugin is run on the “Probabilities” map to produce ROIs."8-bit")
    //white might be required depending on the version of Fiji, "Auto Threshold", "method=MaxEntropy stack"), "Analyze Particles...", "size=50-Infinity pixel display clear add stack summarize")

Once the ROIs are produced, they are saved to OMERO onto the original image which.

def save_rois_to_omero(ctx, image_id, imp) {
    " Save ROI's back to OMERO"
    reader = new ROIReader()
    roi_list = reader.readImageJROIFromSources(image_id, imp)
    roi_facility = gateway.getFacility(ROIFacility)
    result = roi_facility.saveROIs(ctx, image_id, exp_id, roi_list)

Disconnect when done