Manual segmentation

Spread the love

In this tutorial, we are going to manually segment cells or nuclei. This can be useful if you need to segment only a few cells. Alternatively, if you are using an automated segmentation, you might need to segment things manually to correct the output, or to provide training data.

We will be using the program napari. You can follow our installation instructions here.

We will be using this example image. Please download and save it somewhere.

Now open the Anaconda Prompt, run conda activate napari-env and then run napari. The napari window should open. Now, drag the example image that you just downloaded into the program. Napari should now look like this:

Now, at the top of the layers list, press the button with the image of a name tag. If you hover your mouse over that button, a tooltip with “New labels layer” will show. Once you have clicked the button, a layer named “Labels” will be added. The panel on the left will change into this:

On the top, you can see the tools. We will start with the paintbrush. Click on that button and fully paint a single nucleus:

Then, change the label from 1 to 2. You can do this here:

Now you can paint nucleus number 2. It’s important that you change the label for every cell, otherwise you won’t know what pixels belong to one cell and what pixels to another cell. Repeat this for all cells.

Once you’re done, you can save the labels layer using File -> Save Selected Layer(s). The labels will be saved as an image, with a pixel value of 0 for the background, 1 for the first cell, etc.

If you made a mistake, there’s an eraser tool left of the paintbrush. You can also undo your changes by pressing Ctrl + Z.

Loading a layer

Since label images are just images, napari will not load them as a labels layer by default. Instead, just load them as an image, and then right-click on your image in the layers list. In the right-click menu, there will be an option “Convert to Labels”.

Conclusion

We have shown how to manually segment images using napari. It’s quite a cumbersome process, but it can still be the best option in some specific cases.