Skip to content

Instantly share code, notes, and snippets.

@frauzufall
Created August 9, 2019 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frauzufall/bcac3921d2ea6e0f19cd5edfba0df794 to your computer and use it in GitHub Desktop.
Save frauzufall/bcac3921d2ea6e0f19cd5edfba0df794 to your computer and use it in GitHub Desktop.
Macro running skeleton analysis in batch mode
#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".jpg") suffix
processFolder(input);
function processFolder(input) {
list = getFileList(input);
list = Array.sort(list);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + File.separator + list[i]))
processFolder(input + File.separator + list[i]);
if(endsWith(list[i], suffix)) {
setBatchMode(true);
processFile(input, output, list[i]);
setBatchMode(false);
}
}
}
function processFile(input, output, file) {
open(input + File.separator + file);
run("8-bit");
run("Duplicate...", "title=duplicate");
selectWindow("duplicate");
run("Gaussian Blur...", "sigma=5");
run("Auto Local Threshold", "method=Mean radius=150 parameter_1=0 parameter_2=0");
run("Fill Holes");
run("Skeletonize (2D/3D)");
selectWindow("duplicate");
run("Divide...", "value=255.000");
imageCalculator("Multiply create", file,"duplicate");
run("Analyze Skeleton (2D/3D)", "prune=none show");
close("Tagged skeleton");
selectWindow("Branch information");
saveAs("Results", output + File.separator + file + ".csv");
close(file + ".csv");
close("Result of " + file);
close("duplicate");
close(file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment