Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Part 4: AI-based Analysis

Modern AI tools can dramatically improve segmentation accuracy and speed. In this section, you’ll learn to use two powerful tools: Labkit for pixel classification and StarDist for nucleus segmentation.

Setup: Install AI Update Sites

Before starting, install the required update sites:

  1. Go to Help > Update

  2. Click Manage Update Sites

  3. Activate these update sites:

    • CSBDeep

    • StarDist

    • Labkit

    • Tensorflow

  4. Click Close and Apply Changes

  5. Restart FIJI

Download Example Images

Download the example images from: Example images

The folder contains 4 images:

Goal: Quantify the number of foci using pixel classification, then segment nuclei using a neural network.

Labkit: Pixel Classification

Labkit uses machine learning to classify pixels based on examples you provide.

1. Prepare the Image

  1. Open one of the example images

  2. Split the channels

  3. Select the channel with foci

2. Open Labkit

Go to Plugins > Labkit > Open current image with Labkit

(Usually found at the bottom of the menu)

3. Define Classes

  1. In the Labeling panel, rename “foreground” to “foci”

  2. Keep “background” as is

4. Create Annotations

  1. Select the pencil tool

  2. Switch between “foci” and “background” labels

  3. Draw a few annotations for each class:

    • Mark some foci with the “foci” label

    • Mark some background regions with the “background” label

5. Train the Classifier

  1. In the menu, select Segmentation > Labkit Pixel Classifier

  2. Click the Play button to run the classification

Labkit interface with segmentation

You’ll see the predicted classification overlaid on your image.

6. Refine the Classifier

If the classification isn’t perfect:

  1. Add more annotations where mistakes occur

  2. Run the classifier again

  3. Repeat until satisfied

7. Export the Result

Create a binary image based on your classifier:

Segmentation > Show segmentation result in ImageJ

8. Save the Classifier

  1. Go to Segmentation > Save classifier

  2. Choose a location and filename

  3. Close the Labkit window

9. Apply to New Images

  1. Open another image (from untreated cells)

  2. Split channels and select the foci channel

  3. Open with Labkit

  4. Load your saved classifier: Segmentation > Load classifier

  5. Export the segmentation to ImageJ

The classifier trained on one image can now segment foci in other images automatically.

StarDist: Deep Learning Nucleus Segmentation

StarDist is a pre-trained deep learning model specifically designed for nucleus segmentation.

More information: https://imagej.net/plugins/stardist

1. Open Nucleus Channel

Select the image from the nucleus channel (DAPI or similar staining).

2. Run StarDist

  1. Go to Plugins > StarDist > StarDist 2D

  2. Click Restore Defaults to ensure proper settings

  3. Click OK

3. Evaluate Results

Does StarDist segment all nuclei properly?
Look for:

4. The Importance of Scale

StarDist was trained on images where nuclei have a specific size range. Let’s test this:

  1. Duplicate the nucleus image: Image > Duplicate

  2. Resize the image: Image > Adjust > Size

  3. Change from 1024×1024 to 256×256 pixels (4× smaller)

  4. Run StarDist again

5. Compare Results

How well does StarDist work on the resized image compared to the original?

Combining Labkit and StarDist

For a complete analysis workflow:

  1. Use StarDist to segment nuclei

  2. Use Labkit to segment foci

  3. Combine both segmentations to:

    • Count foci per nucleus

    • Measure nuclear intensity

    • Quantify foci distribution