Assists in training a Machine Learning model to segment nuclei.
Updated 12 Oct 2017

View License

To run, execute 'nucleiSegmentationBot' from Matlab's prompt.
After setting the resize factor, click on one of the four options
(label, train, setup post-processing, segment), and follow the instructions.
They don't need to be called sequentially: you can, for example, label in one section,
continue labeling in another, train in yet another, and so on.
To close, close the window.

nucleiSegmentationBot contains all tools necessary to train a model
to segment nuclei. There are, however, a few guidelines to follow, as described below.

Note: if you're using this bot to train a model for spotsInNucleiBot,
you only need to perform the steps Label and Train.


The images to be labeled should be in an independent folder.
They don't need to be square, but they do need to have the same dimensions
(that is, all the same width, and all the same height).

Data images of 3 channels (e.g. RGB images) are converted to grayscale by the algorithm.
This means the segmenter does not use color information, just pixel intensity information.

Label masks for a particular image are saved in the same folder
with the addition of the term '_ClassX', where X is an integer (1 for background,
2 for contour, 3 for nuclei).

For example, if there are two data images, I001.tif and I002.tif, in folder Examples,
after proper annotation the folder will contain the following files:


You can re-label an image, in which case the corresponding label maps will be overwritten.


If you decide to save the trained model (there'll be a prompt after training), it
will be located in the same folder as the labeled images, as rfModel.mat.

The training process might take a long time (several minutes) if there are a lot
of training images, or if the training images are large.


After training the pixel classification model, these steps
help split touching nuclei (via watershed segmentation),
filter out objects based on area and eccentricity, and
change size via morphological thickening or erosion.


The images to be segmented should be in an independent folder.
They don't need to have the same dimensions, or be square.

The segmenter will create a nuclei map for each image, with _Nuclei
added to the name.

The segmenter will ignore images with _Nuclei in the name. This means you can
re-classify a folder, without having to delete the _Nuclei images. They'll be


Video Tutorial:


MatBots are primitive AIs, 'assistants' if you will, that use minimalistic GUI dialogs to guide the user through a data processing pipeline in Matlab.

Isn't that an 'app'? Bots are much more restrictive than apps. Users are, to a greater extent than in an app, guided through the correct steps to perform a task. A bot usually performs a much more limited task than an app.

When possible, bots have a 'headless' mode, which allows them to execute a processing pipeline as a typical Matlab function, either on an image or a folder of images.

For more bots and tools for bio-image analysis, see

Cite As

Marcelo Cicconet (2024). NucleiSegmentationBot (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2017a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Read, Write, and Modify Image in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes