First of all, I'm not very well-versed in Java. In fact, I'm using JLink/Mathematica to do what I want to do.
In our lab, we are taking pictures of our experiment using cameras controlled by Mathematica. We want to convert our image display program to ImageJ. The other program is a memory hog and it's slow.
From my research, I can make this happen by either writing a plug-in, a script, or a macro. I am also under the impression that whatever I write will be installed into ImageJ and controlled by the default GUI.
My question is, can I write an external program that controls an already-running instance of ImageJ? Ideally, the sequence of events would be.
I have successfully imported ImageJ's ij class and played with it. Here's my attempt to create a picture in ImageJ. It's in Mathematica's JLink, but it's fairly translatable to Java.
Needs["JLink`"];
InstallJava[];
AddToClassPath["C:\\Program Files\\ImageJ\\ij.jar"];
ijClass = LoadJavaClass["ij.IJ"];
imagePlusClass = LoadJavaClass["ij.ImagePlus"];
JavaNew[imagePlusClass, "My New Image",
JavaNew["ij.process.ByteProcessor", 400, 400]]@show[]
ij`IJ`log["test"];
ij`IJ`getLog[]
The image created, however, was in some kind of Java windows. The already-running imageJ doesn't interact with it at all. Furthermore, I can seem to capture the log of the already-running ImageJ using getLog[].
Again, the question is, can I use an external script that is not installed in ImageJ as plugin,script, or macro to display an image on an already-running ImageJ? Alternatively, can I use an external script to call a pre-installed macro on an already-running instance of ImageJ?
What you are trying to do is called inter-process communication. ImageJ has a mechanism to pass information to a running instance. Go to Edit ▶ Options ▶ Misc... and check the "Run single instance listener" box. However, this feature is limited to command line arguments. So you can tell a running instance to, for example, open an image from disk, by attempting to launch a second ImageJ with the desired arguments (which will then be passed to the running instance). But you cannot feed it pixels directly over the wire—you would have to write them to a temp file.
Your simplest option is to do everything through ImageJ. But it is not the easiest jump from your current scenario with Mathematica in the mix.
So, the next simplest thing would be to launch ImageJ from Mathematica, and always communicate with that same instance of ImageJ to do everything. Maybe you can do that?
If you must communicate with an externally launched ImageJ instance, you will need to either use the CLI argument passing scheme I mentioned above, or implement your own interprocess communication scheme of some sort.