Analyzing Images via REST-API

navigate has the ability to communicate with other image analysis software through REST-API interfaces. In general, the REST-API is used to communicate with software that has different or conflicting dependencies with the navigate codebase. Data is transferred via HTTP requests and responses, which is faster and more efficient than locally saving the data and then loading it into another piece of software, but slower than direct access of the data in memory.

Here is an example using ilastik to segment images and mark positions for higher resolution in a multiscale microscope. ilastik is a powerful image analysis software that enables users to train a support vector machine learning classifier to segment images using a combination of intensity, texture, and shape features. More information about ilastik can be found here.

Install navigate-ilastik server

Install ilastik first and then follow the steps below:

conda activate your-ilastik-environment
python -m pip install --upgrade pip
mkdir ~/Git/
cd ~/Git/
git clone https://github.com/TheDeanLab/navigate-ilastik-server
cd navigate-ilastik-server
pip install -e .

Visit navigate-ilastik-server for more information.

Run navigate-ilastik-server

In the conda environment command window, go to the folder “navigate-ilastik-server”, run the command:

flask --app navigate_server run

If ilastik server runs on a different machine, run the command:

flask --app navigate_server run --host 0.0.0.0

If want to specify a specific port, add parameter --port port-number.

Set REST-API configuration

Specify url address of the ilastik server in the configuration file (.navigate/config/rest_api_config.yml). If the ilastik server runs on the same machine as navigate, set the configuration as follow:

ilastik:
url: 'http://127.0.0.1:5000/ilastik'

If the ilastik server runs on a different machine, set the configuration as follow:

ilastik:
url: 'http://remote-url:5000/ilastik'

Note

As shown here, the default port is 5000. If another port is used, provide it here.

Load and set ilastik project

  1. Select and click menu Features ‣ ilastik Settings.

    ../../_images/ilastik_1.png
  2. Load one ilastik segmentation project file from the pop-up window

    ../../_images/ilastik_2.png ../../_images/ilastik_3.png
  3. Select target labels and the way to use the segmentation (display or mark positions), then click Confirm.

    ../../_images/ilastik_5.png

Use ilastik feature

  1. Choose Customize acquisition mode, and select the menu Features ‣ ilastik Segmentation.

    ../../_images/ilastik_6.png
  2. Click Acquire to run acquisition.

If you choose to show segmentation only, click Confirm in the popup window directly.

../../_images/ilastik_7.png ../../_images/ilastik_9.png

If you choose to Mark Position, please click ilastik in the pop-up window and set the target microscope name and zoom value.

../../_images/ilastik_10.png ../../_images/ilastik_8.png

The positions will be populated to the multi-position table.

../../_images/ilastik_11.png

The positions looks like the following if saves it in a CSV file.

../../_images/ilastik_12.png ../../_images/ilastik_13.png