Segment OMERO data using Fiji run headlessly in notebook


The following examples follow up on the script shown in Segment using Groovy script. But, unlike in Segment using Groovy script, here, Fiji is included into a Docker image and run in headless mode. The scripts are embedded into a Jupyter Notebook. The Groovy language is used, which is very similar to Java and can be used in Fiji scripting. The scripts show:

  • How to run a Fiji macro attached to an OMERO Dataset, save ROIs, Results and Images (as OME-TIFF) to OMERO

  • How to crop an image in OMERO using Fiji cropping functionality.


Fiji has been installed in a Docker image using repo2docker.



  1. Create a Fiji macro, for example by recording it and save it locally. You can for example use adjusted macro created in Manual Segmentation. See fiji-macro-segment.ijm.

    Note: Not all commands which can be run and recorded in the Fiji user interface can be also run in the Fiji in headless mode.

  2. In your browser, go to the server address provided.

  3. Log in using the credentials provided.

  4. Make sure you are selecting your own data. Select the Dataset A-Fiji-dataset.

  5. Open the Attachments harmonica in the right-hand panel and click on the plus icon. Browse and attach the fiji-macro-segment.ijm to this Dataset as File Annotation.

  6. Run the notebook run_attached_macro.ipynb.

  7. Select the first Step and click on the Run button to execute each step in turn.

  8. For the connection to OMERO, you will be asked to enter your login details when running the first cell under Description. Note that the connection itself happens only in the next cell, highlighted as Connect to OMERO.

  9. In the following cell, you will be asked to enter the ID of the Dataset onto which you attached the Macro file above.

  10. The code in the next cell is fetching the attachments on the Dataset and offering a dropdown menu for you to select a suitable attachment i.e. your attached macro.

  11. The next cell is asking for input about the types of data which should be saved back to OMERO (ROIs, Results or Images). This is of course dependent on the type of results your Macro is producing in Fiji. For this example, we select ROIs and Results.

  12. The script in the next cell will process all the Images in the specified Dataset, applying threshold, analyzing particles, i.e. steps which are captured inside your macro file. Further, it will save ROIs back in OMERO and create a CSV to be attached to each image in that Dataset in OMERO.

  13. Return to OMERO.web and open an Image from this Dataset in OMERO.iviewer.

  14. Click the ROIs tab to see the added ROIs.

  15. In the Settings tab, turning channels on/off will also show/hide ROIs assigned to those channels.

  16. Open the image in OMERO.figure for a quick publication by going to the Info tab in OMERO.iviewer and clicking on OMERO.figure in the Open with line.image1

  17. Click the ROIs tab to see the added ROIs. Note that the ROIs have been assigned a Channel index to indicate which Channel they were derived from.

  18. In the Settings tab, turning channels on/off will also show/hide ROIs assigned to those channels.

  19. Run the notebook crop_image.ipynb.

  20. Run through the notebook, logging in as previously and indicating the Image ID of the image you want to crop.

  21. In OMERO.web, refresh and note that the cropped image has been imported into a newly created Dataset Cropped image.