MIJ doesn't exit

I’m using the following code to call ImageJ from Matlab:

function img=MIJAlign(stack)
addpath('C:\Users\workstation\Documents\Fiji.app\scripts\');
Miji(false);
cd(folder);%OR whatever your matlab script directory is
MIJ.createImage(stack);
MIJ.run('StackReg','transformation=[Rigid Body]');
img=single(MIJ.getCurrentImage());
MIJ.run('Clear Results');
MIJ.exit();
end

The code runs fine, but ImageJ doesn’t close after exit is called, and it leaves a window open called “Import from Matlab”. Anybody got a fix?

Would you mind testing this using the currently supported ImageJ-MATLAB (IJM) interface, rather than the old no-longer-supported Miji? If you experience the same problem using IJM, we can investigate further.

I can confirm that neither variant of the Matlab interface properly closes, but mine hangs on a save changes dialog box. It’d be nice if the exit call would override it, but I can live with it as it is.

Edit: invoking MIJ.run('Close All') before MIJ.exit resolves my issue, at least when using ImageJ-MATLAB.

2 Likes