How to close an open ROI

Hello everyone.

I have some .swc tracings that I import to the ROI manager in ImageJ through the Simple Neurite Tracer (SNT) plugin.
The problem that I am facing is that these ROI’s are an open polygon,

And I want to use the Analyze particles plugin only on the area inside this tracing (after thresholding, the analyze particles workflow is already made). Is there a way to modify a ROI so that it gets “closed” via the shortest possible path and that it is recognized as a closed, not an open ROI?
Currently, when I try to Analyze particles it analyzes the whole picture.

Thank you for your help,


here is something to get you started:

Add your Roi to the Roi manager. Then run this macro:

Roi.getCoordinates(xpoints, ypoints);

It will create a line Roi which connect the 2 ends. Add it to the Roi Manager. Next goal is to combine the 2 outlines and fill it.
There may be easier ways but it works with:

  • Deselect all
  • RoiManager > More > OR (Combine)
  • Add to the manager (just for safety)
  • Convert into a mask which we can fill: Select the combined Roi, then Edit > Selection > Create Mask
  • Fill the holes: Process > Binary > Fill
  • And back to Roi: Edit > Selection > Create Selection
    This Roi is the filled one you want to use for measuring

All these steps can also be combined into a single macro…Use the macro recorder for this.

PS: You could also do a Convex Hull to get an area Roi. It’s quick and easy but it will also fill up concave shaped outlines

1 Like

To convert an open polygon ROI into a closed one use:

  getSelectionCoordinates(xpoints, ypoints);
  makeSelection("freehand", xpoints, ypoints);
1 Like