File Exchange

image thumbnail

MIJ: Running ImageJ and Fiji within Matlab

version 1.5.0.0 (12.6 KB) by Sage
MIJ allows to exchange data between ImageJ and Matlab for image processing and image analysis

45 Downloads

Updated 26 Sep 2017

View License

MIJ offers the missing link between imaging software: ImageJ, Fiji and Matlab. MIJ is a Java package mij.jar that provides static methods to convert images (2D) and volumes (3D) in Matlab arrays. MIJ allows also to access to all built-in functions of ImageJ and to third-part plugins of ImageJ. Thanks to the Fiji team, MIJ is now super-easy to use with a Matlab script Miji.m which is integrated in Fiji. With MIJ, ImageJ acts as an image-processing library of Matlab.
Reference
Daniel Sage, Dimiter Prodanov, Jean-Yves Tinevez and Johannes Schindelin, "MIJ: Making Interoperability Between ImageJ and Matlab Possible", ImageJ User & Developer Conference, 24-26 October 2012, Luxembourg.
http://bigwww.epfl.ch/publications/sage1205.html
More Information
http://bigwww.epfl.ch/sage/soft/mij/

Installation
1) Put mij.jar into the java directory of Matlab (e.g for Window Machine 'C:\Program Files\MATLAB\R2009b\java\').
2) Copy also ij.jar (ImageJ) in the java directory of Matlab. Get this file from the ImageJ website: http://rsb.info.nih.gov/ij/
3) Extend the java classpath to mij.jar, e.g using the Matlab command: javaaddpath 'C:\Program Files\MATLAB\R2009b\java\mij.jar'.
4) Extend the java classpath to ij.jar, e.g using the Matlab command: javaaddpath 'C:\Program Files\MATLAB\R2009b\java\ij.jar'.
5) Start MIJ by running the Matlab command: MIJ.start; or MIJ.start("imagej-path");

Java Source Code
http://bigwww.epfl.ch/sage/soft/mij/MIJ.java

Cite As

Sage (2020). MIJ: Running ImageJ and Fiji within Matlab (https://www.mathworks.com/matlabcentral/fileexchange/47545-mij-running-imagej-and-fiji-within-matlab), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (65)

The instance of imageJ is not loading the plugins installed. If I run image using the 'system('imageJ.exe &') this does load with all the pugins but cannot be controlled by matlab.

Saila Shama

How do I access the plugins installed in Fiji through MIJ?

Daniel

This error message may be due to an old version of the Java Virtual Machine of Matlab.
>> MIJ.start giving me an error message: Undefined variable "MIJ" or class "MIJ.start".
MIJ was compiled in Java 1.6, Therefore the version JVM of Matlab should >= 1.6
To know your JVM version enter:
version -java

Have the same problem as Jonathan Weiss and Nicolas

Like Nicolas Harmand (9 Jan 2018), I am having issues with MIJ.start giving me an error message: Undefined variable "MIJ" or class "MIJ.start". I have successfully defined both new java paths and have my current folder set to Matlab's java folder, but it still does not work. Any pointers would be greatly appreciated!

raym

reply to Lei xu.
Miji.m load the jars including ij.jar in the current program folder, and have priority over your other jars.

Lei Xu

I wonder why I have different versions of ImageJ when I open it as a stand-alone application (1.51u) or if I launch it (1.48v) within MATLAB by calling Miji. I have the ij-1.51u.jar inside the jar folder within MATLAB and I have added the path to "classpath.txt" inside MATLAB's "/toolbox/local" directory but it is obvious that it is not launched when used inside MATLAB. For my understanding "mij.jar" should not interfere the version of ImageJ, or am I wrong? Has anybody any idea why I have this problem and how can I resolve it?

Since I switched from Matlab 2016a to 2017b it doesn't work anymore (MIJ.start or ImageJ gives me an error message).
Also I need to use the floodfill method for data visualization and I can't make it using MIJ... any hint ?

raym

Reply to Harry Lo:
Does this require a matlab in java 8,not 7?

raym

Reply to Marco Tjioe
18 Sep 2017
The website is not available now:
http://javadoc.imagej.net/Fiji/MIJ.html

Harry Lo

Reply to Yanqi Wu's post on 2 Oct 2017 and my post on 5 & 6 Dec 2017.
I have managed to do the image sequence and run the TrackMate in MATLAB using the ImageJ-MATLAB as shown in two crucial steps below.
1) Add the update site of ImageJ-MATLAB (i.e. http://sites.imagej.net/MATLAB/) in Fiji
- Open Fiji, then select Help>Update…>Manage Update Sites>ImageJ-MATLAB>Close>Apply Changes
2) Call ImageJ function instead of MIJI function as example below

javaaddpath 'C:\Program Files\MATLAB\R2017b\java\jar\mij.jar'
javaaddpath 'C:\Program Files\MATLAB\R2017b\java\jar\ij-1.51n.jar'

%Miji
% - Miji function called ImageJ but not Fiji. TrackMate does not work under
% the ImageJ called by Miji in Matlab.

ImageJ % This is a function to call Fiji. After Fiji is called, MIJ.run()
% for importing the image sequence and executing the TrackMate
% work.

MIJ.run("Image Sequence...", "open=[C:\\Users\\<<proper path>>\\croppedImages0000.bmp] sort");

MIJ.run("TrackMate");

raym

reply to yanqiwu
You move all the jars deep inside subfolder of /jars up, then solved.

Harry Lo

Hello,
I encountered the same problem as Yanqi Wu mentioned on 2 Oct 2017 below about executing the TrackMate in Matlab using MIJI such as MIJ.run('TrackMate'). The Matlab command window showed “[WARNING] Class pool is empty: forgot to call Thread#setClassLoader?” The ImageJ showed exceptions as below:
ImageJ 1.51r; Java 1.8.0_121 [64-bit]; Windows 10 10.0; 78MB of 1859MB (4%)

java.lang.IllegalArgumentException: No compatible service: org.scijava.log.LogService
at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:243)
at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:194)
at org.scijava.service.ServiceHelper.loadServices(ServiceHelper.java:170)
at org.scijava.Context.<init>(Context.java:279)
at org.scijava.Context.<init>(Context.java:235)
at org.scijava.Context.<init>(Context.java:175)
at org.scijava.Context.<init>(Context.java:161)
at fiji.plugin.trackmate.providers.AbstractProvider.registerModules(AbstractProvider.java:38)
at fiji.plugin.trackmate.providers.AbstractProvider.<init>(AbstractProvider.java:25)
at fiji.plugin.trackmate.providers.SpotAnalyzerProvider.<init>(SpotAnalyzerProvider.java:14)
at fiji.plugin.trackmate.TrackMateRunner_.createSettings(TrackMateRunner_.java:556)
at fiji.plugin.trackmate.TrackMatePlugIn_.run(TrackMatePlugIn_.java:59)
at fiji.plugin.trackmate.TrackMateRunner_.run(TrackMateRunner_.java:546)
at ij.IJ.runUserPlugIn(IJ.java:221)
at ij.IJ.runPlugIn(IJ.java:185)
at ij.Executer.runCommand(Executer.java:137)
at ij.Executer.run(Executer.java:66)
at ij.IJ.run(IJ.java:301)
at ij.IJ.run(IJ.java:276)
at MIJ.run(MIJ.java:1198)
Would you please help?
Thanks in advance for your help!

Harry Lo

Hello,
I am new to ImageJ and Miji. I encounter a memory issue when I import an image sequence using MIJI in Matlab. There were only 99 images of all 269 images can be imported because it was out of memory. I have increased the Java heap space memory in Matlab on the 'Java Heap Memory Preferences'.
Then I tried to increase the memory of ImageJ which was called from Matlab using Miji. I tried to follow the instruction given in https://imagej.nih.gov/ij/docs/install/windows.html#memory to increase the memory. However, the ImageJ.cfg file cannot be found.
If I directly use the Fiji installed in the same computer (not via Matlab), all the 269 images can be imported properly to be the image sequence without the memory issue. But the out of memory problem occurs if the same images are imported through the ImageJ called from Matlab using Miji.
I am using Windows 10 64-bit, Matlab 2017b and Java 1.8.
How can I solve the out of memory problem?
Thanks in advance for your help!

Yanqi Wu

Hi,

I found it really helpful to automate imageJ process in Matlab. However, all the plugin run well in Matlab, EXCEPT TrackMate. No matter either open TrackMate under plugin menu or use MIJ.run('TrackMate'), a pop-up windows shows: java.lang.illegalargumentexception: no compatible service: org.scijava.log.logservice...
Meanwhile, the Matlab console shows: [WARNING] Class pool is empty: forgot to call Thread#setClassLoader?
Weirdly TrackMate works perfectly without MIJ, which means using FIJI ImageJ directly, and the error only occur when start ImageJ with MIJ. Any idea on it?

Sage

In the same way, it is possible to retrieve the values of the "Results" table by writing this command of the Matlab command window:
>> a = ij.plugin.filter.Analyzer.getResultsTable().getValue('Area',0); % area of the first row

Sage

Note that all the methods of the class IJ are accessible using ij.IJ.*.
To open a image: >> ij.IJ.open('/your_path/image.tif');
To have a beep: >> ij.IJ.beep();
To know the current memory: >> ij.IJ.currentMemory()

Daniel

Marco Tjioe

A very helpful website I find is:
http://javadoc.imagej.net/Fiji/MIJ.html

Here it addresses some of the questions we have. For example, why MIJ.getRoi() does not work but MIJ.getRoi(1) works? In fact, what works is MIJ.getRoi(0) or MIJ.getRoi(1). Why?

In the description, it says:
getRoi(int option)
option - CAL for using calibration or NOCAL for no calibration

I think this means that the options are chosen with integer (int), where getRoi(0) is for using calibration and getRoi(1) is for no calibration. Now what the calibrations mean I am not so sure myself...

To answer Farzaneh ziaee question of why the following does not work:
a=MIJ.getImage('electron image.tif');

You can try:
MIJ.run('Open...', 'path=['electron image.tif']');

Hope this helps :)

Marco Tjioe

Hi all,

Found the answer to my own question. I am trying to open only a few frames of a large file, then choose rectangular region and duplicate that region. The following code works:

Miji; % Start MIJ
text = 'open=[C:\Users\tjioe2\Desktop\TestFile\TestFile6.tif] color_mode=Default open_files specify_range view=Hyperstack stack_order=XYCZT t_begin=1 t_end=10 t_step=1'; % Open only first 10 frames of TestFile6.tif
MIJ.run('Bio-Formats', text); % Use Bio-Formats to open
MIJ.run('Enhance Contrast', 'saturated=0.35'); % Adjust brightness
MIJ.run('Properties...', 'channels=1 slices=1 frames=10 unit=pixel pixel_width=1.0000 pixel_height=1.0000 voxel_depth=1.0000'); % Change pixel values to 1 for width and height
roi = [0 33 33 0; 0 0 30 30]; % Come out with an roi region
MIJ.setRoi(roi,2); % Integer 2 is for rectangular selection. Select from 1 to 7 for Roi.LINE, Roi.RECTANGLE, Roi.POINT, Roi.OVAL, Roi.POLYLINE, Roi.POLYGON, Roi.ANGLE
MIJ.run('Duplicate...', 'duplicate range=1-5'); % Duplicate roi from frame 1 to 5
MIJ.closeAllWindows; % Close all MIJ windows
MIJ.exit; % Exit MIJ

Hope this helps anyone who is trying to use MIJ. It is really a very great tool for speeding up image processing. Even using it just to open and write tiff files speed up my processing already.

Thank you all :)

Thank you @Chen this is indeed what i was looking for

Chen

In case it's helpful for anyone, I just realised that in order to get ROI selection, one needs to use MIJ.getRoi(1), instead of MIJ.getRoi().

Chen

I've experienced the same issue as @Slimane Bazaou had. The MIJ.getRoi() class doesn't seem to work.

Hi there
I am having trouble importing a ROI coordinates or a selected point coordinates from IJ to Matlab.
I can create an image from matlab and show it in IJ. For instance using MIJ.createImage(randn(400));. But if i select a region in IJ I am not able to import the coordinates using MIJ.getRoi(); What am I doing wrong??
Thank you

Tom Jensen

Hello,

I'm finding MIJ very useful but I am having difficulty running some commands using MIJ.run(...).

For instance if I record in ImageJ the following command:

makeLine(234,92,281,62,300,81,338,69,376,62);

Then use MIJ.run('makeLine(234,92,281,62,300,81,338,69,376,62);')

I get the error in ImageJ of 'unrecognised command ...'. I imagine this is something basic which I am doing wrong but any help would be much appreciated.

Thanks, Tom

@ Daniel Todd:

For rigid body, I use

MIJ.run('StackReg ', 'transformation=[Rigid Body]');

Similarly you could do:
MIJ.run('StackReg ', 'transformation=[Translation]');

You can double check this by recording a macro in ImageJ.

Daniel Todd

Hello,

I am currently trying to use the StackReg plugin on Tiff stacks. My problem currently is changing the stackreg options. I am capable of calling stackreg, but with the 3 options in it being Translation, Rigid Body, Scaled Rotation, Affine. It defaults to rigid body but I would like to use the translation method. How do I go about calling this? Currently I am using as follows and it works for getting the Rigid Body default.

MIJ.run('StackReg', path);

Is there something I should add in to specify? Any help is appreciated!

I found a one line solution to my problem and thought I would post it here in case anyone has a similar issue:

MIJ.run('Image Sequence...', strcat('open=[', alldatSimj,'] number=[] file=(Ch', channelNumCell, '_00000', numRepsCell, ') sort'));

where alldatSimj; channelNumCell and numRepsCell are all variables defined in my Matlab script before calling MIJ.

Cheers,
Gabi

Hi, I am trying to open an image sequence in ImageJ from MATLAB using MIJ.

In imageJ I would normally do:
File-Import-Image Sequence - Choose image and then specify what subsequent files belong to the sequence in the 'file name contains' region.
If I record a macro trying to do this (say OpenImagesAsStack) it only works for the set of images used to record the macro. I want to be able to specify the file name arguments from within Matlab and feed them into ImageJ via MIJ.

I have tried the suggestion below to use
IJ=ij.IJ();
macro_path = 'C:\Users\ghabiba_weston\Downloads\ij150-win-java8\ImageJ\macros\OpenImagesAsStack.ijm';
IJ.runMacroFile(java.lang.String(macro_path),java.lang.String(imseq1));

where
imseq1 = strcat(alldatsSimj,' number=[] file=(Ch', channelNumCell, '_00000', numRepsCell, ') sort');

alldatSimj is a string
channelNumCell and numRepsCell are variables

Of course this doesn't work since it simply reads in the images used to record the macro and does not overwrite them with the specified arguments.

I have tried changing the macro to

run("Image Sequence...", "open=C"+imseq1+);
but this didn't work either.

I have also tried instead to do:

MIJ.run('Image Sequence...', 'open=' imseq); but to no avail.

Any clues on how and where to specify the arguments would be much appreciated!
Thanks

HI, I am using the version of this code that comes with Fiji, and I am trying to run a macro of the stitching function: MIJ.run('Grid/Collection stitching', 'type=[Unknown position] order=[All files in directory] directory=['blank'] confirm_files output_textfile_name=TileConfiguration.txt fusion_method=[Linear Blending] regression_threshold=0.30 max/avg_displacement_threshold=2.50 absolute_displacement_threshold=3.50 subpixel_accuracy computation_parameters=[Save memory (but be slower)] image_output=[Fuse and display] i2cropb.tiff i3cropb.tiff i4cropb.tiff i1cropb.tiff');

But whenever I try to run it I it an exception that says: "java.lang.UnsupportedClassVersionError: net/imglib2/type/numeric/RealType : Unsupported major.minor version 52.0" and: "This plugin requires Java 1.8 or later." Despite the fact that Java is up to date on my computer. DO you have any idea what may be causing this, or have a solution? Thank you.

I'm not sure when the path directory changed, but the installation instructions here are a bit off.
Here is a revised guide for R2015a, make note that you must simply change the directory to the one that applies to you.

Revised Installation:
1) Put mij.jar into the java directory of Matlab (e.g for Window Machine 'C:\Program Files\MATLAB\MATLAB Production Server\R2015a\java\jar').
2) Copy also ij.jar (ImageJ) in the java directory of Matlab. Get this file from the ImageJ website: http://rsb.info.nih.gov/ij/
3) Extend the java classpath to mij.jar, e.g using the Matlab command: javaaddpath 'C:\Program Files\MATLAB\MATLAB Production Server\R2015a\java\jar\mij.jar'.
4) Extend the java classpath to ij.jar, e.g using the Matlab command: javaaddpath 'C:\Program Files\MATLAB\MATLAB Production Server\R2015a\java\jar\ij.jar'.
5) Start MIJ by running the Matlab command: MIJ.start; or MIJ.start("imagej-path");

Hello I installed ImageJ and then copied mij.jar and ij.jar in java and added the path in Matlab and then started MIJ. Then it was confirmed that MIJ started in command window and when I wanted to get the image it gave me this error:

a=MIJ.getImage('electron image.tif');
Java exception occurred:
java.lang.NullPointerException

at MIJ.getListImages(MIJ.java:369)

at MIJ.getImage(MIJ.java:517)

Would you please help me what to do?
I appreciated in advance.

Farzaneh

Tom Jensen

Thanks, this is very useful and I am using it a lot now.

On PC (2015a) it works great, i'm having some small issues running it as well on MacOSX (2015a) as it is running a version of ImageJ without plugins and some other commands

John

Thanks for this file, I love it. I have a question in regards to evaluating imagej commands in Matlab. Some of the commands start with call instead of run. How do I evaluate such lines since MIJ.call doesn't work?

MIJ.run('Trainable Weka Segmentation', 'open=[D:\\Colocalization Images\\Actin-CD44\\2014-08-21-5.tif]');
call('trainableSegmentation.Weka_Segmentation.getResult');

I am using MIJ and am very happy with it. However, I have a serious problem of memory leakage.
I run an instance of ImageJ from Matlab using Mij.Start, run the commands I need, close all windows with Mij.CloseAllWindows and exit with Mij.exit. Before and after this process I use javaaddpath and javarmpath for the mij.jar and ij.jar.

All is fine except that the memory that matlab uses (via the windows task manager) accumulates about 300mb each instance. After 3 instances that I run I have to close matlab and open again in order to dump the memory leakage.

I tried 'clear java', 'clear all' and any other thing I found in other forums.
I also tried using jheapcl.m from http://www.mathworks.com/matlabcentral/fileexchange/36757-java-heap-cleaner with no success.

Any suggestions? Thanks!

I'm using MIJ to run Fiji inside of Matlab, but when I run the program I get this odd visual error where text files have a "shadow" of whatever image is behind it, which is usually the matlab interface. This makes it very difficult to read the pop ups, and it seems like they are important error messages. It doesn't affect the functionality of Miji commands, but it does make it very hard to use. I have Matlab R2015a, the latest version of Fiji (1.50b), and MIJ version 1.3.9. Any idea how to fix this problem? Thanks!

Marc

Actually, I was incorrect. This did not fix the problem. While all the correct folders that are associated with macros, pluggins, etc are linked to the matlab instance of imagej, there is an inability to use some of the pluggins. I mean that after I start the imagej instance from within matlab, I can open on the pluggins menu and see all the various pluggins however when I want to use the "Stitching>grid/ collection stitching" pluggin I get the error "plugin or class not found: "Stitching_Grid" (java.lang.classnotfoundexceptrion: stitching_Grid). But oddly, other pluggins seem to work. When I open an instance of imagej outside of matlab, the pluggin is working just fine. Any ideas? Thanks!

Marc

here is the answer to the question I asked below. Works fine now!

Hello,

Thanks you for your interest to MIJ.

You could start ImageJ with:
MIJ.start('path_to_plugins');

from: Daniel Sage via email.

Marc

Hello. Just wanted to say I really find MIJ useful and will likely be using it a lot for now on. However, I do have one issue that I am having problems with. The instance of imagej that is opened within matlab does not have all the plugins that I have available to me when i just open imagej. Upon initialization of MIJ, I see that some of the associated folders that are required for access to all the plugins are not set. See the copy and past from the matlab prompt below after running "MIJ.start".

More Info: http://bigwww.epfl.ch/sage/soft/mij/
Help: MIJ.help
JVM> 1.3.9
JVM> Version: 1.6.0_17
JVM> Total amount of memory: 189760 Kb
JVM> Amount of free memory: 95014 Kb
ImageJ> Version:1.49v
ImageJ> Memory:115MB of 469MB (24%)
ImageJ> Directory plugins: Not specified
ImageJ> Directory macros: Not specified
ImageJ> Directory luts: C:\Users\MP\Documents\MATLAB\luts\
ImageJ> Directory image: Not specified
ImageJ> Directory imagej: C:\Users\MP\Documents\MATLAB\
ImageJ> Directory startup: C:\Users\MP\Documents\MATLAB\
ImageJ> Directory home: C:\Users\MP\
--------------------------------------------------------------
Status> ImageJ is running.
--------------------------------------------------------------

I tried using "MIJ.setupExt" as the description of this class that you have on your website of the various associated classes seems to be what I need to use however I get the error:

"No method 'setupExt' with matching signature found for class 'MIJ'."

and when I use "MIJ.help", the "MIJ.setupExt" is not listed in the resulting displayed help file. Can you help me out as I need to call the "Grid/Collection stitching" plugin in the current script I am putting together.

Thanks for any help you can provide!

Marc

Frank

More Info to my question: when I load a stack with only a few layers, it can work well; when I load a stack with 120 layers, it cracked. Then I add the Matlab-General - Java Heap Memory to 2.4G. Now it work well! Thank you. I do not need help now. Thank you anyway.

Frank

Hi, I am using MIJ-1.3.9 with Matlab R2015a. All set well because some functions work well. But when I transfer image stack data between Matlab and Fiji, I always get stuck. Every time I need force quit Matlab to end up. For example, there is a 3D data in Matlab: Im(512 512 30). I use MIJ.createImage(Im). I expect this will ask Fiji to draw an image stack, but I get stuck here. Please help with this. Thank you very much.

arnold

Hi,

I'm having problem with getRoi().
Even though I have multiple ROIs in the ROI Manager of IJ opened, I can only import one (getRoi(1)), all others return nothing.

How can I work with the ROI list? Is there a way to programmatically load/save an ImageJ ROI file?

Also, when I use "getResultsTable", it doesn't transfer the 'label' column. "getListColumns" however lists the 'label' Column as the first one. Seems to be a bug to me which might render that function useless, as the labels might be invaluable in order to continue analysis on the data!

Hi
How is it possible to launch a macro from Matlab command line please ?
I follow instructions to install MIJ. It seems to work.
I try to launch a macro installed in my ImageJ\Macros directory.
I use the following command line :
>>MIJ.run('CellsMigration.ijm')
I receive this error message :
>><Error: java.io.FileNotFoundException: http://wsr.imagej.net/download/Examples/Macro/CellsMigration.ijm>

Thanks.

Sage

Yes, the Matlab's matrix values are the pixel values of an images in ImageJ.
The pixel position (0,0) of ImageJ corresponds the row 1 and column 1 of a Matlab's matrix. No data are lost in the conversion between Matlab and ImageJ

I'm trying to use MIJ to determine pixel intensity in a given region of an image. For the command MIJ.getCurrentImage or MIJ.getImage, are the numerical values in the returned matrix the grey level/pixel intensity? And do the matrix indices exactly match the ImageJ pixel location, or is there an offset of 1 due to MATLAB's matrix indexing?
Thanks for any help!

Hello,
would it be possible to extend MIJ to be compatible with uint16 data type to use it with 16 bit light microscopy datasets?

For example, the following code does not work:
I2 = uint16(randi(65000,[256, 256, 3]));
MIJ.createColor('test_uint16', I2, 1);

Thank you!

Dear S Mohammadian,
try to look at my comment of 06/nov/2014.
I resolved the memory problem that way.
Maybe it works also for you.
Have a nice day,
Emanuele

Dear Mr. Sage,
Hi All,
As a matter of fact, I am trying to use your nice Matlab code to run ImageJ inside Matlab. It works properly, but has a problem with memory. Even though, I have set 8GB of ram to it, but after some time it gives me an error about memory. The strange part is that it says Available Memory was 328MB which is well below what I chose.
Could you tell me what I should do.
Thanks in advance for your help

Esteban

Hi all, thanks for the great programm!!
My problem is the following. I run MicroManager to get a live video from a camera microscope. The video displays in a ImageJ window, titled "Snap/Live Window (100%)". If I try to record a macros, the only message that it displays is:

selectWindow("Snap/Live Window");

Anyone knows how to capture every frame from the movie that it is displaying? In other words, can I recors a variable with a frame from the movie?

I try several things: the most obvious,the command MIJ.selectWindow seems that doesn't work (only write this in the Matlab script is enough?); the sames happens with MIJ.getCurrentImage.

Anyone knows the command line in Matlab to get acces to the frames of the real-time movie?

Thanks in advance for your help!!!

P.D:Unfortunately, only micromanager have the drivers of the camera, so I cannot use the image adquisition toolbox this time :(

@Wendy

I don't know if it works but you can try to initialize and start Miji, using Miji in the Matlab command line (see some post below) after have installed a version of Fiji on your PC.
I think that is the easy solution to launch a Fiji instance with all of your plugin and command installed.

I hope it works,
Have a nice day
Emanuele

Wendy

Hi,

I installed Miji in the way it was recommended. Now I want to run a macro. In this macro a plugin is used. The beginning of the macro works properly and it opens the image, but every time it reaches the plugin matlab gives the error: Unrecognized command: "Colour Deconvolution".

My matlab code:
javaaddpath 'C:\Program Files\MATLAB\R2014a\java\ij.jar';
javaaddpath 'C:\Program Files\MATLAB\R2014a\java\mij.jar';
MIJ.start;
IJ=ij.IJ();
macro_path='G:\M3\Matlab\CD';
IJ.runMacroFile(java.lang.String(macro_path));

My macro code:
allslidespath = "G:\\M3\\Matlab\\Corrected_Images\\";
flist = getFileList(allslidespath);
lengthflist = lengthOf(flist);

for (f=0; f<(lengthflist); f++) {
if (endsWith(flist[f], ".tif")) {
slidepath = allslidespath + flist[f];
open(slidepath);

run("Colour Deconvolution", "vectors=[H DAB]");
selectWindow(flist[f] + "-(Colour_1)");
saveAs("Tiff", slidepath + "-(H).tif");
selectWindow(flist[f] + "-(Colour_2)");
saveAs("Tiff", slidepath + "-(DAB).tif");
selectWindow(flist[f] + "-(Colour_3)");
saveAs("Tiff", slidepath + "-(Re).tif");
}
}

How can I solve this problem?
Thanks

@Alaa

Hi,
i setup Miji in this way.
1) install the latest version of Fiji(http://fiji.sc/Downloads)
2) install and copy the latest mij.jar in the jar matlab folder(i.e. '/Applications/MATLAB_R2012a.app/java/jar/mij.jar')

3) I add mij e fiji to the matlab path writing on matlab command window:

javaaddpath('/Applications/MATLAB_R2012a.app/java/jar/mij.jar');
&this is a java add path!

addpath('/Applications/Fiji.app/scripts');

4) Run Miji using:
Miji
or Miji(false)
if you wan't the Fiji gui

Hoping to be helpful,
have a nice week
Emanuele

@Emanuele Martini (me)

to launch a macro with arguments I found this way, I don't know if this is the better method, but it works :D

I found a solution:
after having setting-up Miji,
you can construct an IJ instance in matlab
IJ=ij.IJ();

macro_path=...
'/Users/emartini/Documents/emanueleM/WH_exp/GUI_test/WH_Miji_macro_RoiExtraction.txt';

args=...
strcat('image_path=',image_path,' saving_path=',saving_path,' R_median=',R_median,' R_variance=',R_variance);
you don't have to use the ijm syntax "+variable+"

IJ.runMacroFile(java.lang.String(macro_path),java.lang.String(args));
remember to use java string.
And it works ;)

Have a nice week,
Emauele Martini

Alaa

Hello every one, I'm trying to call the Imagej plugin from matlab but usually I get error the matlab doesn't recognize the mij.jar

how can I solve this problem???
thanks

Hi Daniel,
How can I launch a macro using Miji?
I have a macro that works in FIJI that get some parameters as a string;
like that:
runMacro("WH_imagej_AUTO_ema_MEDIAN_macro","image_path="+image_path+" saving_path="+saving_path+" R_median="+R_median+" R_variance="+R_variance)

in ijm language I have to use runMacro, but I don't find an analogue in MIJI.
I try with that:
MIJ.run(macro_path,strcat('image_path=',image_path,' saving_path=',saving_path,' R_median=',R_median,' R_variance=',R_variance));

with:
image_path='/Users/emartini/Documents/emanueleM/WH_exp/Cecilia_Savorani/old/6nov2014/YAP WT CTR/WT CTR s2.tif'
saving_path='/Users/emartini/Documents/emanueleM/WH_exp/Cecilia_Savorani/old/6nov2014/PROCESSED'
R_median='NO'
R_variance='3'
macro_path='/Applications/Fiji.app/plugins/Scripts/WH_imageJ_AUTO_ema_MEDIAN_macro.txt';

But the FIJI instance says to me: "unrecognized command"...

Is there a way to do that?
Thank you,
Emanuele Martini

Very good tool, i'm starting to use it in these days and it works very nice.

If someone has problem to setup the Imagej Memory (the instance that matlab cretes with Miji) I found this solution that has the advantage to be user-specific.
I started from the suggestions in this post: http://www.mathworks.it/matlabcentral/answers/92813-how-do-i-increase-the-heap-space-for-the-java-vm-in-matlab-6-0-r12-and-later-versions

and I put a java.opts file in my matlab startup directory (use pwd in matlab before doing anything to find it), with a line: -Xmx512m
and that set imagej memory to 512 MB, for example.

Thank you Daniel,
and best regards
Emanuele Martini

CY Y

Very important and useful tool! This is a beautiful marriage between two powerful platform for image processing and analysis!

Sage

Question: I wanted to know how do I run commands like "setTool". the macro for this on Imagej is: setTool("point");
how do I run this from matlab?

Answer: enter the following command on Matlab >>ij.IJ.setTool('point');

Updates

1.5.0.0

Add link to source code

1.5.0.0

Update

1.5.0.0

Update link

1.5.0.0

Update reference

1.5.0.0

Title change

1.4.0.0

Title correction

1.3.0.0

Description update

1.2.0.0

Description update

1.1.0.0

Description update

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux