Help with batch Processing analyze particles macro

Hello,

I am new in macro coding. I have some images (.jpg) in a folder and I need to quantify the area of some particles in those images and get a .csv file with the measure of particles of all the images. Before using the “Analyze particle tool”, I need to convert the image to 8-bit and adjust the Threshold.

So, I’m trying with this macro:

extension = “.jpg”;
dir1 = getDirectory("/Users/olmangomez/Desktop/test “);
//dir2 = getDirectory(”/Users/olmangomez/Desktop/result ");
setBatchMode(true);
n = 0;
processFolder(dir1);

function processFolder(dir1) {
list = getFileList(dir1);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], “/”))
processFolder(dir1+list[i]);
else if (endsWith(list[i], extension))
processImage(dir1, list[i]);
}
}

function processImage(dir1, name) {
open(dir1+name);
print(n++, name);
run(“8-bit”);
setAutoThreshold(“Minimum dark no-reset”);
//run(“Threshold…”);
run(“Analyze Particles…”, “size=200-Infinity circularity=0.30-1.00 display”);
saveAs(.csv, dir2+name);
close();
}

The I open Fiji, go to Plugins -> Macros -> Run : and open the .ijm file with the macro. But, just after that, a new window is automatically open, so in this new window a look for the folder the images, then click on open …. and I got a macro error:

“Number or numeric function is expected in line 25
saveAs(<.>csv, dir2+name);

Line number is on clipboard”

So, if anyone could help me know what I’m doing wrong or improve my macro, I’d appreciate it.

Thank you
OG

Hi,

Try replacing this line

With

saveAs( “results”, dir2+name+”.csv”);

You might prefer to change the extension to csv by doing this

saveAs( “results”, dir2+File.nameWithoutExtension+”.csv”);

Cheers,

Chrid

Hi evenhuis,

Thanks for taking the time to clarify my doubt. I changed it and it worked. At the end the line worked as follows:

saveAs(“Results”, dir2 + name + “.csv”);

Again thank you for the answer.

Do you know why when I try to run the macro, a window opens and I have to look for the image folder manually?

Hi,

the macro functions is a really useful reference for all the things that can be done in the ijm language.

getDirectory(string) will present the user with a directory chooser window and the name of the window will be what is in string. In your case a window will pop up with the path in the name.

If you want to hard-code the paths to the directory just do

dir1 = "/Users/olmangomez/Desktop/test/“;

Just be aware that on other systems the slashes go the other way.

Cheers,

Chris

I got it, now I understand.

Thank you soo much.

OG