ImageJ-MATLAB question

fiji
imagej
matlab
imagej-matlab
composite-image
hyperstacks

#1

I’ve asked the same question in a PR, but I haven’t got any answer, so I’m stuck.

So, I repeat it here, hoping that this might attract more people. It’s a simple YES/NO question:

Do you guys agree that just adding Java class paths is equivalent of having a headless ImageJ instance? Or is it equivalent of Miji(false) ?

If YES, then I’ll get rid of ImageJ_javaaddpath.m and suggest to use ImageJ(false) instead.

If NO, then I’ll change the ImageJ.m , so that ImageJ(false) will end up an error as before, while keeping ImageJ_javaaddpath.m .

A bit more explanation:

In that branch (migrate-matlab-scripts), I suggested to amend ImageJ.m, the MATLAB function used to launch ImageJ instance from within MATLAB.

The problem is that currently ImageJ.m does not support headless mode. It was meant to be used like ImageJ(false) to launch ImageJ in headless mode, but it was never completed and in the master branch it issues an error.

A headless version of ImageJ may be useful if you need to access ImageJ commands from within parfor loops for parallel computing.Within parfor loop, you need to add ImageJ Java class for each MATLAB workers.

I realized that the first part of ImageJ.m is essentially to add Java class paths of Fiji to MATLAB.

The rest is really simple:

import net.imagej.matlab.*;
if open_imagej
    ImageJMATLAB.start(verbose);
else
    % initialize ImageJ with the headless flag
    ImageJMATLAB.start(verbose, '--headless'); % DOES NOT WORK
end

Miji.m also has very similar design, and the equivalent part is as below:

    if open_imagej
        cd ..;
        fprintf('\n\nUse MIJ.exit to end the session\n\n');
        mij = javaObject('MIJ');
        mij.start();
    else
        % initialize ImageJ with the NO_SHOW flag (== 2)
        ij.ImageJ([], 2);
    end

My question here is whether you think just adding Java class paths is equivalent of Miji(false) or not.


If YES, a very simple solution is to change ImageJ.m as below:

import net.imagej.matlab.*;
if open_imagej
    ImageJMATLAB.start(verbose);
else
    % initialize ImageJ with the headless flag
    % DO NOTHING HERE
end

Although I don’t really know what Miji.ms line ij.ImageJ([], 2); is doing.

The integer 2 is the value of ij.ImageJ.NO_SHOW.

If this line is necessary, the following is also an option. This will create an ij.ImageJ object.

import net.imagej.matlab.*;
if open_imagej
    ImageJMATLAB.start(verbose);
else
    % initialize ImageJ with the headless flag
    ij.ImageJ([], ij.ImageJ.NO_SHOW);
end
ans =
ij.ImageJ[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,title=ImageJ,resizable,normal]

But once you do this, next time you call ImageJ.m, it will cause a terrible error. So maybe this is not a good solution.

Plus, because it seems that you can run most of code without creating ij.ImageJ object, I wonder if this is necessary.


If the answer to the question is NO, then we should make a distinction between just adding Java class paths and running ImageJ in headless mode. Leave ImageJ(false) as it is (which does not work), and extract the first part of ImageJ.m as a separate function so that you call when you want to add ImageJ Java class paths without launching GUI. And the tentative name of that function is ImageJ_javaaddpath


Let me know your thoughts, so that I can make changes to this.