Saving CSVs from Macro

I am trying to analyze several images within a folder. For each image, I want to run a directionality plugin. After the plugin has run, it outputs a table of results, which I want to save as a csv file.

The problem is that it does not continuously output CSVs. Instead, it will output the first one CSV (and maybe the second) before slowing to a stop. When it doesn’t slow to a stop, it just processes all the pictures, but does not save any CSVs. Is there anything wrong in my code? I am familiar with Python, but not ImageJ macro code. Thanks for any help!!!

Here is my code:
// Macro to measure directionality

// Show the user a dialog to select a directory of images
inputDirectory = getDirectory(“Choose a Directory of Images”);

// Get the list of files from that directory
fileList = getFileList(inputDirectory);

for (i = 0; i < fileList.length; i++)
function orientation(imageFile)
run(“Directionality “, “method=[Fourier components] nbins=180 histogram_start=0 histogram_end=180 build display_table”);
saveAs(“Results”, inputDirectory + imageFile +”.csv”);
run(“Clear Results”);

Hi @dillonnolt,

you are not closing the tables after you saved them as .csv-files. Something like


after the saveAs should do the trick. Maybe you should also consider copying these results into a common table, instead of creating a lot of tables with just one line each.


Is there an easy way to copy the results to a common table? I wouldn’t want to copy all of the results, but rather, just two columns from each image’s analysis.

The following picture shows the table that is generated from each analysis. Is there a way that I can copy the columns (“DIrection” and “Slice_1G”) to a csv? If so, how would I differentiate between results from different images? Could I add a column with the filename? Or is there a better way?

Hi @dillonnolt

You might want to look into Table Functions:

For example, you could copy a specific column by Table.getColumn(“Direction (°)”)


1 Like