Why I'm using Miji instead of ImageJ-Matlab

Tags: #<Tag:0x00007fd546e056f0>


In another post, @imagejan asked why I was using Miji instead of ImageJ (from the ImageJ-Matlab project) in my Matlab scripts. I was having a number of issues with ImageJ, so I decided to reply on a new thread.

I’m trying to use ImageJ-Matlab with R2016b. I have matlab using the same jvm as Fiji.

My first problem is that I haven’t found a way to start it without the gui:

>> ImageJ(false);
No method 'start' with matching signature found for class

Error in ImageJ (line 45)

I did some searching in the source code, but searches for ‘net.imagej.matlab.ImageJMATLAB’ and ‘–headless’ came up empty. Perhaps the actual source is somewhere else?

When I do start it with the gui, it works but I get a bunch of errors:

>> ImageJ();
[ERROR] Cannot create plugin: class='org.scijava.plugins.scripting.javascript.JavaScriptScriptLanguage', name='JavaScript', priority=0.0, enabled=true, pluginType=ScriptLanguage
java.lang.IllegalArgumentException: No such script engine: javascript
	at org.scijava.script.AdaptedScriptLanguage.findFactory(AdaptedScriptLanguage.java:151)
	at org.scijava.script.AdaptedScriptLanguage.<init>(AdaptedScriptLanguage.java:73)
	at org.scijava.plugins.scripting.javascript.JavaScriptScriptLanguage.<init>(JavaScriptScriptLanguage.java:59)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
	at java.lang.Class.newInstance(Class.java:442)
	at org.scijava.plugin.PluginInfo.createInstance(PluginInfo.java:304)
	at org.scijava.plugin.DefaultPluginService.createInstance(DefaultPluginService.java:236)
	at org.scijava.plugin.DefaultPluginService.createInstances(DefaultPluginService.java:225)
	at org.scijava.plugin.DefaultPluginService.createInstancesOfType(DefaultPluginService.java:216)
	at org.scijava.plugin.AbstractSingletonService.initInstances(AbstractSingletonService.java:92)
	at org.scijava.plugin.AbstractSingletonService.getInstances(AbstractSingletonService.java:75)
	at org.scijava.script.DefaultScriptService.initScriptLanguageIndex(DefaultScriptService.java:340)
	at org.scijava.script.DefaultScriptService.scriptLanguageIndex(DefaultScriptService.java:305)
	at org.scijava.script.DefaultScriptService.getIndex(DefaultScriptService.java:120)
	at org.scijava.script.DefaultScriptService.canHandleFile(DefaultScriptService.java:241)
	at org.scijava.script.ScriptFinder.createInfos(ScriptFinder.java:166)
	at org.scijava.script.ScriptFinder.scanResources(ScriptFinder.java:134)
	at org.scijava.script.ScriptFinder.findScripts(ScriptFinder.java:110)
	at org.scijava.script.DefaultScriptService.initScripts(DefaultScriptService.java:381)
	at org.scijava.script.DefaultScriptService.scripts(DefaultScriptService.java:323)
	at org.scijava.script.DefaultScriptService.getScripts(DefaultScriptService.java:170)
	at net.imagej.legacy.LegacyService.getScriptsAndNonLegacyCommands(LegacyService.java:658)
	at net.imagej.legacy.IJ1Helper.addMenuItems(IJ1Helper.java:744)
	at net.imagej.legacy.LegacyService.initialize(LegacyService.java:518)
	at org.scijava.service.ServiceHelper.createServiceRecursively(ServiceHelper.java:353)
	at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:269)
	at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:231)
	at org.scijava.service.ServiceHelper.createServiceRecursively(ServiceHelper.java:340)
	at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:269)
	at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:231)
	at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:194)
	at org.scijava.service.ServiceHelper.loadServices(ServiceHelper.java:166)
	at org.scijava.Context.<init>(Context.java:278)
	at org.scijava.Context.<init>(Context.java:234)
	at org.scijava.Context.<init>(Context.java:174)
	at org.scijava.Context.<init>(Context.java:160)
	at net.imagej.ImageJ.<init>(ImageJ.java:76)
	at net.imagej.Main.launch(Main.java:61)
	at net.imagej.matlab.ImageJMATLAB.launch(ImageJMATLAB.java:151)
	at net.imagej.matlab.ImageJMATLAB.start(ImageJMATLAB.java:105)
	at net.imagej.matlab.ImageJMATLAB.start(ImageJMATLAB.java:92)
	at net.imagej.matlab.ImageJMATLAB.start(ImageJMATLAB.java:81)

After following the instructions in this post, and restarting matlab, I got a different set of errors:

>> ImageJ();
java.rmi.ConnectException: Connection refused to host:; nested exception is: 
	java.net.ConnectException: Connection refused
	at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
	at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
	at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
	at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)
	at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
	at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
	at net.imagej.legacy.$Proxy28.sendArgument(Unknown Source)
	at net.imagej.legacy.SingleInstance.sendArguments(SingleInstance.java:203)
	at net.imagej.legacy.SingleInstance.sendArguments(SingleInstance.java:168)
	at net.imagej.legacy.LegacyConsoleService.processArgs(LegacyConsoleService.java:73)
	at org.scijava.AbstractGateway.launch(AbstractGateway.java:95)
	at net.imagej.Main.launch(Main.java:62)
	at net.imagej.matlab.ImageJMATLAB.launch(ImageJMATLAB.java:151)
	at net.imagej.matlab.ImageJMATLAB.start(ImageJMATLAB.java:105)
	at net.imagej.matlab.ImageJMATLAB.start(ImageJMATLAB.java:92)
	at net.imagej.matlab.ImageJMATLAB.start(ImageJMATLAB.java:81)
Caused by: java.net.ConnectException: Connection refused
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at java.net.Socket.connect(Socket.java:538)
	at java.net.Socket.<init>(Socket.java:434)
	at java.net.Socket.<init>(Socket.java:211)
	at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
	at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
	at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
	... 15 more
[ERROR] Could not connect to existing ImageJ instance. If problem persists, please delete file: /tmp/ImageJ-ajw68-_0-7.stub

I deleted /tmp/ImageJ-ajw68-_0-7.stub, and tried again. This time, it started cleanly, but after the introductory text was printed, I got a warning:

log4j:WARN No appenders could be found for logger (loci.formats.ClassList).
log4j:WARN Please initialize the log4j system properly.

Second, I have not found a way to exit from the program:

>> IJM.exit
Error using exit
Scalar integer value required, but non-numeric value seen
>> IJM.exit(0)
Error using exit
Too many input arguments.

Running IJM.help does not show any method that would be relevant to exiting:

>> IJM.help

ans =

-- ImageJ MATLAB commands --

Usage: IJM.[command]
	help - prints a brief description of available commands
	getDataset - creates a MATLAB matrix from the active ImageJ image
	getDatasetAs(name) - creates a MATLAB matrix from the active ImageJ image, and assigns it to the specified variable name
	show(name) - takes the MATLAB matrix with the specified name and displays it as an image

However, it works using the MIJ object that is also created:

>> MIJ.exit
ImageJ instance ended cleanly

I could not find how to do these things correctly in the documentation, so, I’m going to stick with using Miji until these issues are cleared up or a description of what I want to do is documented.

TrackMate memory issue when run in MATLAB

Hi all,

I reported the same issue some time ago and created an issue to track it:


I have also been looking at the ImageJ-Matlab code lately particularly with an eye to making it Octave compatible. I wonder if the import statement in the code is really needed? IIUC it is compatible with neither older Matlab, nor Octave. It might be stabler to just load Java objects and methods with the old syntax?


Using @ctrueden’s handy ImageJ search page is always recommended. It was an oversight not to have the individual repository links… I added them. In this case, you were looking for ImageJ-MATLAB.

Also I just made a fix that I think will fix headlessness (it was calling a start method that doesn’t exist). Completely untested. Also @ctrueden would you be willing to upload this for me?

Resolved by @ctrueden (MATLAB needed to run with Java 8, and this is now clearly documented)

Hard to know what happened, if a separate instance of ImageJ 1.x was running or failed to shut down properly. This is in some way related to ImageJ 1.x’s single instance listener. Glad that the error message helped at least. :slight_smile:

You can basically ignore this warning, but I acknowledge it is extremely annoying. Off the top of my head I’m not sure it can be fixed because it could be due to a conflict with something usedby MATLAB. Once my aforementioned fix is uploaded it would be worth testing this with verbose=false to see if the log message is still printed.

Yeah I admit when I was working on ImageJ-MATLAB I was using it graphically, and the utility of an “exit” function didn’t occur to me since you can just close the GUI. Issued: https://github.com/imagej/imagej-matlab/issues/10


Sure. I will be cutting a ton of new releases within the next two weeks. If you want it done sooner than that, let me know, and I will try to prioritize it sooner.


I am using Java 8 everywhere and I’m using the Java-8 site.

Has this been pushed to the updater, or do I need to get the git repository to test it? Currently (after running Fiji updater),

>> version -java

ans =

Java 1.8.0_111-8u111-b14-2ubuntu0.16.04.2-b14 with Oracle Corporation OpenJDK 64-Bit Server VM mixed mode

>> ImageJ(false)
No method 'start' with matching signature found for class 'net.imagej.matlab.ImageJMATLAB'.

Error in ImageJ (line 45)


Not yet, sorry. I am super busy right now, but I am still planning to cut releases within the next few days.

In the meantime, you can download the latest build from the Maven repository. Grab the 0.7.2-SNAPSHOT version, which is latest as of this writing. Click the little “jar” link on the right to get it. Delete any old jars/imagej-matlab-*.jar files from your Fiji installation.


I noticed there was a major update, but I failed to see if it included ImageJ-Matlab (btw, is there a way to get version numbers or date-of-last-update information through the updater?).

I tested >> ImageJ(false) and it still doesn’t work. I’m assuming this is because it was not updated, but I wanted to make sure.


@ajw Thanks for the ping. I released a new version of ImageJ-MATLAB on January 17, but forgot to upload it to the ImageJ-MATLAB update site.

@hinerm I am insanely busy today; do you have time to quickly test it and then upload? http://maven.imagej.net/#nexus-search;gavimagej-matlab~0.7.2


Saw a bunch of updates when I launched Fiji today, but >> ImageJ(false) is still giving the same error. Have the changes been pushed?


They had not been pushed.

But now, thanks to your reminder, they have been.

I did not test, however. Please try it and reply back if there are any issues.


I installed the new updates using the Fiji updater, but still getting same error message. I was under the impression that the changes got pushed to the normal Fiji release, but perhaps I misunderstood.


The update is part of the MATLAB update site. Do you have the MATLAB update site enabled?


Sorry, I didn’t get a ping that you wrote back for some reason!

I have the ImageJ-MATLAB update site enabled, which I believe is why the command >> ImageJ() works.

ImageJ(false) still produces the same error.

Is there another MATLAB update site?


@ajw I double checked, and the newest imagej-matlab version 0.7.2 which includes @hinerm’s fix from December is definitely being served by the ImageJ-MATLAB update site.

So I guess it does not fix the issue…

No. The one and only update site for this is ImageJ-MATLAB.

I am sorry I do not have time to troubleshoot this. I am absolutely overwhelmed with other things right now. Hopefully @hinerm will be able to advise further.