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

Lendl,Thomas
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.

Best,
Thomas


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
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 (http://forum.imagej.net/t/getting-line-selection-from-longest-skeleton-path/2963) 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.

Cheers,
Mark

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")
IJ.run(imp, "Skeletonize (2D/3D)", "")
imp.show()
//IJ.run("Set... ", "zoom=400 x=60 y=77")
//imp.setSlice(50)

// Initialize AnalyzeSkeleton_
skel = new AnalyzeSkeleton_()
skel.calculateShortestPath = true
skel.setup("", imp)
 
// Perform analysis in silent mode
skelResult = skel.run(AnalyzeSkeleton_.NONE, 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))
    IJ.wait(20)    
}

pRoi = new PolygonRoi(poly, PolygonRoi.POLYLINE)
imp.setRoi(pRoi)

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html