Skip to content

Instantly share code, notes, and snippets.

@cdw
Created February 22, 2016 21:21
Show Gist options
  • Save cdw/53c9673c33b94fe2fee7 to your computer and use it in GitHub Desktop.
Save cdw/53c9673c33b94fe2fee7 to your computer and use it in GitHub Desktop.
// StackProfileData
// This ImageJ macro gets the profile of all slices in a stack
// and writes the data for each slice to a separate CSV in the
// directory the images came from.
//
// Version 1.0, 24-Sep-2010 Michael Schmid
// Version 1.1 22-Feb-2016 Dave Williams
macro "Stack profile Data Action Tool - C059T3e16S [S]" {
if (!(selectionType()==0 || selectionType==5 || selectionType==6))
exit("Line or Rectangle Selection Required");
setBatchMode(true);
n = nSlices;
for (slice=1; slice<=n; slice++) { // for each slice
showProgress(slice, n); // update progress bar
run("Clear Results"); // clear prior results buffer
setSlice(slice); // move to current slice
profile = getProfile(); // get profile
sliceData = split(getMetadata("Label"),"\n");
sliceLabelWithExt = split(sliceData[0], '.');
sliceLabel = sliceLabelWithExt[0];
for (i=0; i<profile.length; i++)
setResult(sliceLabel, i, profile[i]);
dir = getDirectory("image");
saveAs("Results", dir + sliceLabel + ".csv");
}
run("Clear Results"); // clear prior results buffer
//setBatchMode(false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment