0
votes

I have written a macro in ImageJ to run batch "Measurements" on a list of BMP image files. I am running the code on a remote linux machine in headless mode using headless.jar.

Whenever ImageJ encounters an error or exception while reading/loading an image in the list, it exits the process. Hence, I have to constantly monitor the process and manually force ImageJ to skip the file.

Is there a way I can force ImageJ to continue with the process even though it encountered an error/exception? and report the filename maybe in the logs or another file?

1
It sounds like you should consider rewriting your macro as a Java Plugin. That would give you the option of performing the error handling you need. - Codey McCodeface

1 Answers

0
votes

It is not possible to explicitly handle exceptions in the ImageJ macro language. However, you can guard against certain types of exceptions by checking preconditions and such before making a problematic macro call.

For example, if your list of files includes nonexistent ones, you can use File.exists(path) [1] to ensure the file exists before you attempt to open it.

Of course, not all error conditions can be easily checked this way (e.g., malformed BMPs), so I agree with medPhys-pl that rewriting your macro as an Imagej plugin is the most complete solution. You can get a good start using the Macro Recorder (Plugins > Macros > Record) set to record in Plugin mode rather than Macro. Once you have the relevant commands to execute, you can package them into a plugin easily by using Fiji's Script Editor:

  1. File > New > Script
  2. Language > Java
  3. Templates > Java > Bare PlugIn
  4. Paste your commands into the run method.

See the Fiji wiki's Introduction into Developing Plugins for more details on writing ImageJ plugins.