Cannot run ImageJ.m from MATLAB with Java 1.8

About two months ago, I was able to run ImageJ.m successfully on MATLAB R2017b. Now I cannot do the same on R2018a. I’ve seen this issue reported here, but because the JAVA version is already 1.8, the same solution would not work for me.

>> javaclasspath



>> version -java
ans =
    'Java 1.8.0_144-b01 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode'

>> ImageJ
Undefined variable "ImageJMATLAB" or class "ImageJMATLAB.start".
Error in ImageJ (line 42)
42          ImageJMATLAB.start();

When I look at the source code of ImageJ.m , I found an alarming comment.

%% Maybe open the ImageJ window
import net.imagej.matlab.*;
if open_imagej
    % initialize ImageJ with the headless flag

% Make sure that the scripts are found.
% Unfortunately, this causes a nasty bug with MATLAB: calling this
% static method modifies the static MATLAB java path, which is
% normally forbidden. The consequences of that are nasty: adding a
% class to the dynamic class path can be refused, because it would be
% falsy recorded in the static path. On top of that, the static
% path is fsck in a weird way, with file separator from Unix, causing a
% mess on Windows platform.
% So we give it up as now.
% %    imagej.User_Plugins.installScripts();

What does this mean? ImageJ.m won’t work now? Or am I doing something wrong?

For the record, the same was posted in this github issue already:

@kouichi-c-nakamura please disclose when cross-posting the same content to two different locations, to avoid people wasting their time by giving answers that have been given already, and to allow others interested in the issue to follow the entire discussion.

Well, spotted, thanks. I was meant to do.

Sorry, but ImageJ.m worked today.

>> addpath 'D:\\scripts'
>> ImageJ
ImageJ-MATLAB 0.7.2: MATLAB to ImageJ Interface
JVM> Version: 1.8.0_144
JVM> Total amount of memory: 389120 Kb
JVM> Amount of free memory: 128790 Kb

-- Welcome to ImageJ-MATLAB --
ImageJ-MATLAB consists of an extensible set of commands for passing information between ImageJ and MATLAB.
See the individual sections below for a list of available commands.

For more information and examples see:

--- MATLAB Command Plugins ---

-- 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

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

@kouichi-c-nakamura I notice you added a talk page to MATLAB Scripting on the wiki with some related(?) issues. Better would be to follow up here on the forum, either this topic or a new topic as appropriate.

Done. The discussion on wiki was removed.


Hi @kouichi-c-nakamura, I’m having exactly the same problem. Did It work just like this or did you modify something else?



Hi Tomas,

Actually I wasn’t sure. At least I didn’t try anything special for this issue on purpose.

Try updating Fiji, restarting MATLAB, restarting computer. All can I think of is that kind of things.

If you manage to pin down the solution, please report it here.