Skeleton to line

Previous Topic Next Topic
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Skeleton to line

Dear all,

Does anyone know of an easy way to transform a skeleton of an elongated structure into a segmented line? I'm trying to write a macro for that but It's hard to get it running properly. I also tried all the Selection tools but they don't give me what I need.


ImageJ mailing list:
Reply | Threaded
Open this post in threaded view

Re: Skeleton to line

Mark Krebs-2
Hi Thomas,

I've tried the script below from a thread that seems to have input from multiple contributors on the ImageJ forum ( on a Mac 10.9.5 and it seems to work.  You need to change the path name for the file of interest (line "imp = IJ.openImage("/Users/...").  Is that what you're looking for?

The desire to convert a Skeleton to a polyline comes up often enough that I wonder if someone might be interested in including it as part of Analyze>Skeleton>Analyze Skeleton 2D/3D.


import ij.IJ
import ij.gui.PolygonRoi
import java.awt.Polygon
import sc.fiji.analyzeSkeleton.AnalyzeSkeleton_

// Load Sample image, skeletonize, and zoom for illustration purposes
imp = IJ.openImage("/Users/mpk/Desktop/Gayle PH3 Images/Mask-1.tif"), "Skeletonize (2D/3D)", "")
//"Set... ", "zoom=400 x=60 y=77")

// Initialize AnalyzeSkeleton_
skel = new AnalyzeSkeleton_()
skel.calculateShortestPath = true
skel.setup("", imp)
// Perform analysis in silent mode
skelResult =, false, true, null, true, false)

// Read the results
shortestPaths = skelResult.getShortestPathList().toArray()
sppoints = skel.getShortestPathPoints()

poly = new Polygon()
for (p in sppoints[0]) {
    poly.addPoint((int)p.x, (int)p.y)
    imp.setRoi(new PolygonRoi(poly, PolygonRoi.POLYLINE))

pRoi = new PolygonRoi(poly, PolygonRoi.POLYLINE)

ImageJ mailing list: