Client API for embedding ImageJ

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Client API for embedding ImageJ

TonyOHagan
ijclient_10.zip

The attached API provides a simple Client API for
embedding ImageJ into an application.

Use IJClientFactory to get a local or remote interface reference:
  IJClient ijClient = IJClientFactory.getIJClient(true);

If ImageJ has already been started within the current JVM
or another JVM on localhost  it will transparently invoke the
method calls to this ImageJ instance.  If ImageJ is not found,
it will start up a new instance in the current JVM.

public interface IJClient {
  void quit();
  void setDefaultDirectory(File dir) throws IOException;
  void openImage(File file) throws IOException;
  void runMenuCommand(String menuCommand) throws IOException;
  void runMacro(String macro) throws IOException;
  void runMacroFile(File file) throws IOException;
  void runMacroFile(File file, String arg) throws IOException;
}


Example Usage:
-------------
runImageJ(File[] imageFiles, String macro) {

    try {
        // Get either current JVM or external JVM connection to ImageJ.
        // Creates an instance of ImageJ if none exists in current JVM.
        ijClient = IJClientFactory.getIJClient();

        // Load up image files
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            if (!file.exists()) {
                log.error(file + ": Image file not found");
            } else {
                log.debug("open: " + file.getPath());
                ijClient.openImage(file);
            }
        }

        // Execute the optional macro
        if (macro != null && macro.trim().length() > 0) {
            log.debug("macro: " + macro);
            ijClient.runMacro(macro);
        }
    } catch (IOException e) {
        log.error("Failed to connect to or execute ImageJ commands.  " + e.getMessage());
    }
}


This source code is submitted to the public domain.
Use at your own risk.  No liability is expressed or implied.
Tony O'Hagan  http://www.itee.uq.edu.au/~tohagan

I'd be delighted if IJClient was added to the ImageJ source code.
I'd recommend that the following improvements be considered
to better support IJClient.

* I added support for remote execution of multi-line macros in IJClientRemote.runMacro();
  It implementats a 'hack' that converts them to a temporary file and invokes runMacroFile().
  The file is removed after a time delay.
  This workaround would not be needed if SocketListener supported mult-line macros.

  An alternative hack might be to replace '\n' with ' ' or maybe ';'
  but I'm uncertain that this would work in all cases.
   
* Allow IJClientRemote.runMacroFile() to respond with
  the String result returned by IJ.runMacroFile().
  SocketListener does not currently support this.

* IJClient API might be used to simplify existing
  code by removing the need to decode the command line
  parameters twice in ImageJ.main() and ImageJ.isRunning().
Reply | Threaded
Open this post in threaded view
|

ImageJ as an applet

jwcnmr
Can the ImageJ UI be embedded as an applet rather than as a Frame that is
rendered in a separate window?
I want to create a web page with the display of 2 or more images in the
same frame.

James W. Cooper
Text Analytics
IBM T J Watson Research Center
[hidden email]
914-784-7285
http://flahdo.watson.ibm.com/
http://www.research.ibm.com/people/j/jwcnmr/
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ as an applet

dscho
Hi James,

On Mon, 4 Jun 2007, James Cooper wrote:

> Can the ImageJ UI be embedded as an applet rather than as a Frame that is
> rendered in a separate window?
> I want to create a web page with the display of 2 or more images in the
> same frame.

There is some code to do that in ImageJA: http://imageja.sourceforge.net.
Until a week ago, I was not aware of any regular user of this, but it
appears that it has been in use for several months with only minor
glitches.

Hth,
Dscho