top bar

Difference between revisions of "Matlab Configuration"

Line 59: Line 59:
>> imshow(img2);
>> imshow(img2);

Revision as of 10:07, 6 May 2011

Using Micro-Manager from your Matlab environment.

The Micro-Manager Core Java API is contained in the file MMCoreJ.jar. Any Java program (including Matlab) that wants to use the Micro-Manager API needs to put MMCoreJ.jar in its ClassPath. When CMMCore Java object is first created in the calling program it will automatically attempt to load native library MMCoreJ_wrap. This library must be visible to the Java run-time. Default locations and exact names of libraries are platform dependent.

On Windows, the native library file is MMCoreJ_wrap.dll and it must reside either in the system path or in the current working directory of the program in order to be detected by the Java run-time.

MMCore can be used in Matlab through its Java interface. After setting up the Java environment as described above, MMCoreJ.jar must be added to Matlab Java class path and the directory for the MMCore dynamic libraries (including MMCoreJ_wrap) must be added to the system path.

The following recipe has worked in the past:

Matlab has an extensive Java support which makes things easy, just do the following:

1. Install Micro-Manager in a path without any spaces (for instance: C:\Micro-Manager1.2).

2. Add the path with the drivers (all the .dll files) to the windows PATH enviromental variable (Start->Settings->Control Panel->System->Advanced->Environment Variables, make a new 'User variable for Administrator named 'PATH' and set it to the location of Micro-Manager (for instance: C:/Program Files/Micro-Manager-1.3).

3. In Matlab command prompt

>> edit classpath.txt 

Add the location of the jar file you just installed (its in the Micro-Manager folder), include the .jar at the end, for instance:

C:/Program Files/Micro-Manager-1.3/ij.jar
C:/Program Files/Micro-Manager-1.3/plugins/Micro-Manager/MMCoreJ.jar
C:/Program Files/Micro-Manager-1.3/plugins/Micro-Manager/MMJ_.jar
C:/Program Files/Micro-Manager-1.3/plugins/Micro-Manager/bsh-2.0b4.jar
C:/Program Files/Micro-Manager-1.3/plugins/Micro-Manager/swingx-0.9.5.jar

4. In Matlab command prompt

>> edit librarypath.txt 

Add the location of the dll files, for instance:

C:\Program Files\Micro-Manager-1.3

5. Restart Matlab

6. create a java object of class MMCcore

>> import mmcorej.*;
>> mmc=CMMCore;
>> mmc.loadSystemConfiguration ('C:\Micro-Manager1.2\MMConfig_demo.cfg');

The Micro-Manager API is described here:

The following simple script will snap an image from an 8-bit camera and display it in matlab:

>> mmc.snapImage();

>> img=mmc.getImage();

>> width=mmc.getImageWidth();

>> height=mmc.getImageHeight();

>> img2=typecast(img,'uint8');

>> img2=reshape(img2,[height,width]);

>> imshow(img2);

© Micro-Manager : Vale Lab, UCSF 2006-2011 | All Rights Reserved | Contact