Macro Failing to open image

Trying to create a batch analyze particles macro to measure area. Working with jpg file and my macro will run on a single open image but my batch code is failing to open.
image

Here is the code:

run(“Clear Results”); // clear the results table of any previous measurements
setBatchMode(true);
inputDirectory = getDirectory(“Choose a Directory of Images”);
outputDirectory = getDirectory(“Choose a Directory to Save Results”);
fileList = getFileList(inputDirectory);
for (i = 0; i < fileList.length; i++)
{
processImage(fileList[i]);
}
setBatchMode(false);

function processImage(imageFile)
{
open(imageFile);
name = getTitle;
run(“Set Scale…”, “distance=4.0267 known=1 pixel=1 unit=µm global”);
run(“8-bit”);
setAutoThreshold(“Triangle”);
//run(“Threshold…”);
//setThreshold(0, 134);
setOption(“BlackBackground”, true);
run(“Convert to Mask”);
run(“Analyze Particles…”, “size=1000-5000 show=Masks display exclude clear include”);
selectWindow(“Results”);
saveAs(“Results”, outputDirectory + name + “.csv”);
close("*");
}

1 Like

Hey @rc123,

the dialog tries to hint you, that “m11.jpg” cannot be found. The reason might be that Fiji doesn’t know in which folder to look for that image.

Instead of

processImage(fileList[i]);

try:

processImage(inputDirectory + "/" + fileList[i]);

And let us know if this works!

Cheers,
Robert

Not sure what the problem is, but rather than “/” it is better to use File.separator which returns the file name separator character ("/" or “”) that can vary across operating systems.
See the file demo: https://imagej.nih.gov/ij/macros/FileDemo.txt

1 Like

adding the inputdirectory to the path worked. I figured it was something like that but am new to writing macros so did not know how to do it.
Thanks for the help.

1 Like