Image not found error

Hi all,

I have a problem with scripting. I have an IJm macro in which I handle an image stack A.tif. The results go into a stack B (plain B). I handle the stacks in a loop over x,y and the stack channels. To access the values in the stacks alternatingly in the loop I give a selectImage(“A.tif”), read the values that I need, do the calculations and then store the results in B after a selectImage(“B”).

This code runs OK

To prevent flicker and a slow code I want to hide the images, so before the loop I do selectImage(“A.tif”); setBatchMode(“hide”); and the same for image B.

Problem: when I run this code I get an error: “A.tif” not found in line …

I have been trying a lot of things… without success.

Can anyone give me a hint ?



It would help if we could see your code - or at least the piece that is causing the issue… so a minimal working example would be perfect. And share a sample image as well that runs with that code.

You can double-check the setBatchMode() function description from the Built-In Macro Functions list:

Controls whether images are visible or hidden during macro execution. If arg is ‘true’, the interpreter enters batch mode and newly opened images are not displayed. If arg is ‘false’, exits batch mode and disposes of all hidden images except for the active image, which is displayed in a window. The interpreter also exits batch mode when the macro terminates, disposing of all hidden images.

With ImageJ 1.48h or later, you can use ‘show’ and ‘hide’ arguments to individually show or hide images. By not displaying and updating images, batch mode macros run up to 20 times faster. Examples: BatchModeTest, BatchMeasure, BatchSetScale and ReplaceRedWithMagenta.

setBatchMode(“exit and display”)
Exits batch mode and displays all hidden images.

Displays the active hidden image, while batch mode remains in same state.

Enters (or remains in) batch mode and hides the active image

Perhaps going back to “true” and “false” as args is best? At least it’s worth testing… (check out the linked examples there too!)

1 Like

Thanks for your reply @etadobson!

I had a look into my somewhat messy :frowning: code. The problem was (as almost ever) very trivial. There was a missing } , so a setBatchMode(“false”) command was actually inside the loop and not outside.

I can now go on with the real stuff.


1 Like