Skip to content

Instantly share code, notes, and snippets.

@imagejan
Created October 10, 2016 15:01
Show Gist options
  • Save imagejan/1a96f0744ccba13300565b95de7c9a2c to your computer and use it in GitHub Desktop.
Save imagejan/1a96f0744ccba13300565b95de7c9a2c to your computer and use it in GitHub Desktop.
import ij.IJ
import ij.ImageStack
import ij.ImagePlus
import ij.gui.Line
import ij.gui.OvalRoi
import ij.gui.PolygonRoi
import java.awt.Polygon
import sc.fiji.analyzeSkeleton.AnalyzeSkeleton_
imp = IJ.createImage("Untitled", "8-bit black", 100, 100, 1)
IJ.setForegroundColor(255, 255, 255);
imp.show()
//IJ.run("Set... ", "zoom=400")
Line.setWidth(1)
imp.setRoi(new OvalRoi(11,15,57,35));
IJ.run(imp, "Draw", "slice");
imp.setRoi(new OvalRoi(33,36,57,35));
IJ.run(imp, "Draw", "slice");
imp.setRoi(new Line(20,20,10,10))
IJ.run(imp, "Draw", "slice")
imp.setRoi(new Line(68,71,87,76))
IJ.run(imp, "Draw", "slice")
IJ.run(imp, "Skeletonize (2D/3D)", "");
// 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()
// imps = new ImageStack(imp.getWidth(), imp.getHeight())
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(50)
// imps.addSlice(imp.flatten().getProcessor())
}
pRoi = new PolygonRoi(poly, PolygonRoi.POLYLINE)
imp.setRoi(pRoi)
IJ.run(imp, "Straighten...", "line=20");
// new ImagePlus("Animation", imps).show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment