I want to make a simple ImageJ macro that draws a profile plot along a given linescan and saves the results in a .txt file. So far, I have:
run("Plot Profile");
saveAs("Text", "/path/to/file/Values.txt");
This creates the plot in a new window, but then returns an error, stating that a TextWindow is required. I have the suspicion that the macro tries to save the image itself as text instead of the plot data.
How can I implement a macro that does exactly the same as if I were clicking on the "Save As" button of the profile plot or "List -> Save As" ?
The buttons in the plot window are not recorded by ImageJ's macro recorder. (Since you asked the same question on the ImageJ mailing list, there is a chance that this will change in the future.)
Use the getProfile()
macro function to get the list of values (as shown in this example macro), or use Plot.getValues(xpoints, ypoints)
to get the values from the plot window (as shown in the other example macro on the ImageJ website).
For example:
run("Clear Results");
profile = getProfile();
for (i=0; i<profile.length; i++)
setResult("Value", i, profile[i]);
updateResults();
saveAs("Measurements", "/path/to/file/Values.txt");