1

I'm using ImageJ macro to batch process images. Specifically, I'm trying to run a plugin called Log3D on each image. For some reason, ImageJ macro won't wait for the command to finish running before running the next line in the script.

Is there a way around this?

Thank you!

I'm currently using "waitForUser" to manually let ImageJ know when to continue but this is quite annoying and not useful when I process hundreds of images at once.

selectWindow(file + " - C=" + chFISH);
run("LoG 3D", "sigmax=1.5 sigmay=1.5 sigmaz=1.5 displaykernel=0 volume=1");
waitForUser("Proceed when Log3D is complete");
run("Invert", "stack");
run("16-bit");
print("Saving smFIHS channel to: " + output);
saveAs("Tiff", output + File.separator + file + ".chFISH"); 
close();
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Omer Shkedi
  • 41
  • 1
  • 4

2 Answers2

1

You could try running Log3D over all the images first and then running the rest over the newly processed images.

openPath = getDirectory("Choose Source Directory");
files = getFileList(openPath);
savePath = getDirectory("Choose Destination Directory");

for (timePoint = 0; timePoint < (files.length); timePoint++)
{
    if (indexOf(files[timePoint], chFISH) >= 0) //Screens file names for your variable
    {
        tempName = getTitle();
        open(openPath + files[timePoint]);
        run("LoG 3D", "sigmax=1.5 sigmay=1.5 sigmaz=1.5 displaykernel=0 volume=1");
        saveAs("Tiff", savePath + tempName);
        close();
    }
}

files = getFileList(savePath);

for (timePoint = 0; timePoint < (files.length); timePoint++)
{
    run("Invert", "stack");
    run("16-bit");
    print("Saving smFIHS channel to: " + savePath);
    saveAs("Tiff", savePath + File.separator + file + ".chFISH"); 
    close();
}
ekiely
  • 92
  • 8
0

If your images are of a consistent file size, you could use the "wait" command, which causes ImageJ to wait "n" milliseconds before continuing.

selectWindow(file + " - C=" + chFISH);
run("LoG 3D", "sigmax=1.5 sigmay=1.5 sigmaz=1.5 displaykernel=0 volume=1");
wait(30000); //Waits for 30 seconds
run("Invert", "stack");
run("16-bit");
print("Saving smFIHS channel to: " + output);
saveAs("Tiff", output + File.separator + file + ".chFISH"); 
close();

You'll have to work out how long it takes for your plugin to run on a given image, but in principle this should resolve your issue.

J. Kovacs
  • 157
  • 1
  • 1
  • 10