Batch processing by macro recording

I recorded a macro for an image and intend to use the macro to do batch processing for several images. I have two issues with the macro

  1. Onely the first image is thresholded within the limit I set
  2. I could not save the excel result for all the processed image.

I will appreciate if anyone can help me with the right code

run("Set Scale...", "distance=1536 known=34.5 unit=um");
setAutoThreshold("Default");
//run("Threshold...");
//setThreshold(0, 30);
setOption("BlackBackground", false);
run("Convert to Mask");
run("Close");
run("Median...", "radius=2");

run("Volume Fraction", "algorithm=Surface surface=6 use");
saveAs("Results", "C:\\Users\\removeable\\Documents\\Images\\New folder\\Results.xls");

You need to tell the Macro to look at other Images unless you do that before the first run step you have shown, I’m not sure why it didn’t save

@susan-sheehan thanks. The macro was able to run by little modification but after trying to batch process it will run for a set of image save and overwrite the results. It doe not run through all the images a go and the final result will be the last batch which it runs through. Do you have any info have to tell the macro to look at all the images in a folder?

Dear @Sab6,

as pointed out by @susan-sheehan you will have to change the second argument you pass to the saveAs function which denotes the location for where to store your results. Furthermore, your are calling run("Close") somewhere in the middle of your macro, which closes the currently active window such that processing cannot continue.

I propose to change your macro to:

run("Set Scale...", "distance=1536 known=34.5 unit=um");
setAutoThreshold("Default");
//run("Threshold...");
//setThreshold(0, 30);
setOption("BlackBackground", false);
run("Convert to Mask");
run("Close");

run("Median...", "radius=2");
run("Volume Fraction", "algorithm=Surface surface=6 use");

fileNameWithoutExtension = File.nameWithoutExtension;
saveAs("Results", "C:\\Users\\removeable\\Documents\\Images\\New folder\\"+fileNameWithoutExtension+".xls");

I hope this also solves that problem:

It doe not run through all the images a go

All the best,
Stefan

Dear Stelfrich,

Sorry for the late response. I have been away for sometime and did not check the imageJ forum. Thank you for you help. I was able to make some modifications on the macro code which works better now.

Regards
Shereef

1 Like