Count Segments

The Count Segment Tools allow to estimate the number of segment like objects in an image like for example this one: example image. The segments can cross each other.

Getting started

To install the tools, drag the link MRI_Count_Segments.txt to the ImageJ launcher window, save it under macros/toolsets in the ImageJ installation and restart ImageJ.

Select the "MRI Count Segments" toolset from the >> button of the ImageJ launcher.

  • the first button (the one with the image) opens this help page
  • the o button opens the options-dialog
  • the c button runs the Count-Segments macro on the active image
  • the b button runs the Count-Segments macro in batch mode on a list of images

If you want to use the batch-mode, you need to have the Macro_IO_Settings plugin installed. Download the file and unzip the archive file in the plugins folder of your ImageJ installation.


Open the options-dialog by pressing the o-button. The options are use by the Count-Segments macro and by the Count-Segments batch macro. Changed options remain valid until you change the tool-set or restart ImageJ. After that the default options will be active again. You can change the default-options permanently in the text-file of the macro toolset. To open it hold down the shift-key when selecting the toolset. Save the file after you changed the options.

the options dialog of the count segments macro toolset

  • subtract radius is the radius of the blurring filter that is applied to subtract a blurred version from the original image to get rid of background and uneven illumination. The smaller the value the more background and eventually signal is removed.
  • filter radius is the radius of the blurring filter that is applied before the threshold-segmentation. The filter avoids that segments are split into multiple parts. The radius should be rather low in general.
  • min. size the minimum size of segments that are taken into account. This can be used to eliminate segmentation artefacts that are to small to be segments. Note that sometimes smaller values can help to find segments that are not bright enough as a whole but have some bright parts

Count Segments

Load the image and make sure that there is no selection on the image (ctrl+shift+a). Press the c-button. A log window containing the name of the image, the count of the segments and the folder of the image, separated by commas is displayed. A point selection marking the end points of the segments found is displayed on the image.


A blurred version of the image is subtracted from the original image. A gaussian-blur filter is applied to the result and the image is segmented by using the IsoData-auto-threshold. The result is converted into a mask and skeletonized. The end points of the segments are detected as points that have exactly one neighbour.