Miji seems to be more robust that ImageJ in Matlab

Yo @imagejan
I played around with the MIJ and IJM objects and I think I prefer the MIJ (Miji) functions because they correct the axes and seem to have more functionality.

I’ve been having a lot of angst moving polar images back and forth. The axes flip, and R and Theta transpose. It’s easy to get confused.

here’s my sandbox code to explore the two interfaces.

I = peaks;
title('peaks from Matlab');
MIJ.run("Rotate 90 Degrees Right");
MIJ.run("Flip Horizontally");
MIJ.run("Scale...", "x=10 y=10 width=490 height=490 interpolation=Bilinear average create title=[IJM peaks in IJ]");

MIJ.run("Scale...", "x=10 y=10 width=490 height=490 interpolation=Bilinear average create title=[MIJ peaks in IJ]");

uiwait(msgbox('Close Matlab Windows??')); 
close All;

uiwait(msgbox('Close All ImageJ Windows??')); 
MIJ.run("Close All");

uiwait(msgbox('Open, Process and Select an ImageJ image to import to Matlab as Ip...then click OK')); 
title("IJM returned image");
colormap gray;
Mip = MIJ.getCurrentImage
colormap gray;
title("Mij returned image");

uiwait(msgbox('Close ImageJ?')); 

Do you see the benefit of the IJM (imagej-matlab project) functions? … Let me know your thoughts.


Miji is a simple wrapper for some commands of ij.
I usually combine MIJ with ij, since both can be javaaddpath to Matlab.

In fact ,if one want to use imageJ to process image without showing image, the ij is more detailed and feasible.

For an example:

MIJ.run... %you must show the image to front to run 
IJ.run(...%you must show the image to front to run 
IJ.runPlugin(imageplus,...%you can load imageplus from file without imageplus.show, then it is hidden ,but the plugin can be run.

The more detailed, you are more close to the core of imagej(skip the Macro layer), and the more you can acheive, and the more robust and GUI-burden-free to speed up and even paralling your tasks/threads…

I’m not at my matlab computer right now so I can’t try some of the stuff you mention (i.e.
IJ.runPlugin ) .

I’ve been looking for the syntax for running a FIJI plugin from Matlab. Do I need to identify the plugins folder (win10), and will
IJ.runPlugin run the macros too. I didn’t realize that there was an object ‘IJ’ available in Matlab…I’ve been using ‘MIJ.function’ and ‘IJM.function’. I don’t see ‘IJ’ available in the variables of Matlab as IJM and IMJ are. Is there a syntax list of functions available in Matlab prefaced by IJ. ??? Some simple code would be helpful.

My general use case is to 1 generate a matrix or image in Matlab, 2 open FIJI, 3 move the matrix or image to FIJI, 4 process the image in FIJI either From FIJI or Matlab, 5 return the matrix or image to Matlab for further processing. It would be nice to be able to run a FIJI macro (say from the startup macros, the plugins, or an ijm file in the FIJI editor) from Matlab. This would provide a real image processing component to Matlab.

I’m also interested in running Matlab from a FIJI.ijm macro, but I can’t figure out how to do that from the available user manuals.

Thanks for your feedback


if you can use mij, then ij must be loaded.

ips = IJ.openImage('C:....png')
IJ.save(ips, 'C:......tif')
riomanager = ij..

To run macro, you can record, then


I’m also interested in running Matlab from a FIJI.ijm macro, but I can’t figure out how to do that from the available user manuals.

I suggest not try this. Matlab coding is faster and should be used as glue , not the reverse.
The reverse calling is much more difficult.

I’ve verified that MIJ commands will run the menu macros and the plugins with setup dialogues and the utility macros. I’m having trouble selecting open FIJI images from within Matlab. I get an error message from Matlab that MIJ.selectWindow(id); is not a recognized function. It is documented here: http://bigwww.epfl.ch/sage/soft/mij/doc/MIJ.html#selectWindow(java.lang.String).I get the string id earlier in the code and it is correct when displayed in the Matlab command window…

I’ve also tried MIJ.run(“selectWindow(“leaf.jpg”)”); without success. I think that the sequential "s confuse it.

Hello Meldel
I’ve had good results moving images to and from IJ/FIJI, and I’ve been able to MIJ.run the menu commands, but not any macros I’ve written. Where do you place the IJ macros? in Scripts folder or Macros folder, and do you call them as MIJ.run(“mymacro.ijm”); or MIJ.run(“mymacro”); or do you need the path to the macro in the call???
Thanks for any help

I have never run macro using MIJ.
Infact you can re-write all the commands of the macro into MIJ commands.

You can try:
ij.IJ.runMacroFile(path to macro file)

yes I usually use what suggested by @mendel
to launch macro file
I set up a macro_path where I put all my macros and then for example

        strcat('image_path=',image_path,' saving_path=',saving_path,' R_median=',R_median,...
        ' R_variance=',R_variance,' thr_method=',thr_method,' fix_thr=',fix_thr);
macro_path = path/to/macros

args is a matlab string if you would like to pass some arguments to your macros