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.

Deep learning for image analysis

In this session we segment cells and detect spots with pretrained deep learning models. We do not train any AI models ourselves, but we look at how to use those in an image analysis workflow.

The three notebooks we use follow the same logic: first an example image that suits the model, then our own images and a few exercises.

Each notebook has a matching _answers.ipynb with answers to the exercises.

Learning goals

After these notebooks you can:

  1. Run different pretrained deep learning models on your own images from Python.

  2. Say what each of the three models predicts, and choose the one that fits your objects: outlines of nuclei (StarDist), outlines of cells of any shape (Cellpose), or positions of small spots (Spotiflow).

  3. Recognise that the size of your objects, compared to the images the model was trained on, decides whether a pretrained model works, and set it with scale (StarDist) or diameter (Cellpose).

  4. Explain why the input has to be normalized, and recognise what goes wrong when it is not.

  5. Combine the output of two models into a measurement (foci per nucleus), and apply it to several images with a function and a loop.

Installation instructions

conda create -n 2026_deep_learning -c conda-forge python=3.12 ipykernel nbformat pip
conda activate 2026_deep_learning
pip install "tensorflow>=2.16,<2.22" stardist "cellpose<4" spotiflow numpy matplotlib tifffile scikit-image pandas colorcet

The deep learning packages come from pip rather than conda-forge: conda-forge has no recent TensorFlow build for Windows, and currently no Spotiflow package.

Notes:

To start JupyterLab, use conda activate jlab and then jupyter-lab, and pick the kernel Python [conda env:2026_deep_learning].

The data

Apart from the example data we have several images of cells that were either irradiated (IR) or left untreated (control), fixed 2 hours later, and imaged in two channels: the DNA damage foci and the nuclei. In the last notebook we count the foci per nucleus and compare the two conditions.

Files in data/

Files to download

Running the notebooks

In your terminal go to the folder with the Github repository.

cd NL-BioImageAnalysis-course2026

Then activate the jlab environment.

conda activate jlab
jupyter lab

After jupyter lab has opened in your browser, go to day_2/deep_learning open the first notebook 01_stardist.ipynb.