Reach a database from ImageJ Macro


I am in a need to make imageJ access to some kind of database (mysql is a good cancidate), and let my macros add results from results table to database table, or modify some values (to indicate other processes that, image processing is complete). Ive found and example regarding to Java connection via RDBMS but its a bit outdated, from 2004 and I am looking to reach databases from a macro, if possible. What are the current possibilities, if there is any?
Thanks !

Good day,

do you have any experience with platform-independent interaction of different applications?

There exist bridging modules for the communication between ImageJ and MathLab and studying their code might give you an idea …



To my knowledge, this is not implemented in the ImageJ macro language.

Recently, @gab1one did some work on the SciJava Location framework that might enable access to databases via scripting in the future, but I don’t know the details. Maybe he can advise himself.

@anon96376101 thank you but my programming experience is very limited. I was hoping for an existing code to modify to my needs but, its too bad such a great software, without dbase connection abilities… Here is the only plugin, but I dont understand how (if) can I use it from a macro.

@imagejan I will look for whats available, but if all fails, what an alternative approach can be, only to give info to other processes? csv formatted text file output is one option in mind, or creating an empty text file to use as a flag (upon completion of a specific job), or anything smarter?


Sorry, but I can’t test this plugin!

Did you install it with all dependencies?
Is there a GUI? If, yes, is it macro recordable?

Good luck


HI @OntheWay,
I have recently developed an application for the company I work for, that communicates with ImageJ through macros. The application has been developed in C++ and uses Postgresql as a backend database.
This is the workflow:

  • The user uploads/captures an image and then pushes a buttonn to start processing the image;
  • The application creates a lockfile and launches an ImageJ’s macro via a .bat file (but you can also use ShellExecute);
  • When the macro has done with processing, it saves the result in a .txt file and deletes the lockfile;
  • When the lockfile is deleted, the application reads the result from the text file and saves them (along with the processed image) in the database.

Hope this can help!


Hi @gio,

Thank you very much for sharing your workflow, it looks great to me! Its a better implementation of what was in my mind. I will probably use python in the app. part (another option is delphi but feel rusted with it, need to check).

I need just a small clarification on last couple of your steps.

  1. Upon completion, the lockfile is deleted by the macro, right?

  2. What kind of approach is appropriate for an app. to check whether a lockfile is deleted? I am asking this because I will need 24/7 unattended operation. Should I need a seperate background process just to check this?

  3. And a final question, do you consider this approach a safe way against failures (hardware failures, electricity etc…) ? It will run in my own server computer, so its not a highly protected environment.

Thanks again,

hi @OntheWay

  1. Yes, is the macro that must delete the lockfile.
  2. In my application I use something like this (in pseudocode):
    std::ofstream lockfile (path_to_lockfile);
    while(true) {
    if(not file exists) {
    //Read data from the text file created by the macro
    Everything is in the main thread, but my application is interactive, so user can interrupt the process if it takes too much time. In your case you should check regularly for stale lock file. The file could be staled because the application has been crashed before deleting it (in this case just removing the file is ok), because ImageJ is hung (in this case you should kill ImageJ), because for some reason the macro failed to delete the lock file (also in this case jus remove the lock file). A way to check if the lock file is staled, could be trying to open it after some time (so you first operation in the macro should be opening the file: usually if the file is opened by another process trying to open it will fail).
  3. I think that as per point 2, your main concerns should be stale lock file and ImageJ hanging.
1 Like

This answer clarified many concerns, thanks a lot.