How to annotate a dataset for segmentation

This guide shows you how to annotate images to train a segmentation model for the population of interest.

Reference keys: instance segmentation, cell population

  1. Launch the software, load an experiment containing the imaging modaliti(es) and cell population of interest. Expand the single-cell processing block for your population of interest.

  2. Recommended: pre-segment the cells you want using either a generic segmentation model (CP_cyto3, SD_versatile_fluo for nuclei, see How to apply a segmentation model) or with a traditional segmentation pipeline (see How to segment with the Threshold Configuration Wizard). You can also pre-segment only the frames you annotate, from napari (see below).

  3. Click on the button on the right side of the SEGMENT option to open the initial masks in napari.

  4. In the layer list section, select the channel layer of interest and play with the contrast limits slider to adjust contrast. Activate or deactivate other channels to be able to see your cell population of interest clearly.

  5. Use the sliders to find a frame of interest where you would like to annotate. Your dataset should sample everything that can be found in your data, with special emphasis on rare cases.

  6. Optional: to start from a segmentation rather than from scratch, use the panel at the top right: in its Model tab pick a model and press Segment this frame, or in its Threshold tab load a threshold configuration and press Threshold this frame — the latter can be restricted to the region you are about to annotate (see Segmenting a single frame from napari). The result can be undone with Ctrl+Z.

  7. Recommended: press the New shapes layer button in the layer list section and the Add Rectangle button in the layer controls to draw a crop of a sub-region of the current field of view, limiting the amount of annotations to perform and allowing you to move to another time point to take a different sub-region without spatial repetition. Use the opacity slider to make it as transparent as possible so that cell masks can be annotated properly.

  8. Click on the segmentation layer. Use the segmentation layer controls to paint new cells (press M to increment a new label value), the rubber to erase cells or part of cells. Use the fill bucket with a label value of 0 to erase a cell. Work within the crop region, for the current timepoint only. You can use the time slider to see what happens before/after the current timepoint but the annotation should be done only for the current timepoint.

  9. Optional: above the save button, adjust the auto-fix options applied on export. Split merged labels separates objects that accidentally share a label value, Remove small objects discards objects below the Min object area (px²) threshold, and Fill holes in masks fills holes inside masks. By default, splitting and small-object removal are enabled and hole filling is disabled. Disable any of them if you want your annotation saved exactly as drawn.

  10. Once the cell masks are as perfect as they can be within the annotated region, press the Export the annotation of the current frame button. The frame (or the crop), its mask and a .json file recording its channels and spatial calibration are written in an annotations_population-name folder at the root of the experiment. (Save the modified labels would instead overwrite the masks of the position.)

  11. Repeat the process for as many regions as possible. Try to sample both spatially and temporally, limiting sub-region repetitions. Once you reach about 10-30 samples, you may attempt to train a deep learning model on your data, with the proper strategy.

  12. To correct an exported annotation later, go to Plugins > Correct a segmentation annotation in the start window and open its .tif file. The single-frame segmentation panel is available there too, both of its tabs.

Note

Deep learning models struggle with inconsistencies. Performance tends to degrade if annotations conventions are not clearly defined and robust.

roi_annotation

Exporting a ROI of annotations for segmentation. In this demo, a false positive cell mask is removed. A rectangular ROI is defined at this given frame, locally to the modification. Upon export, only this crop is exported as a training sample.