Endrov in Matlab

From Endrov

Contents

Installing Endrov in Matlab

In Matlab, open File -> Set Path. Here, add your endrov directory/endrov/bindingMatlab

The first command in your script should be

evmInit

This will load all the java libraries into Matlab. Calling the command twice will not have any further effect.

Getting help

Matlab has very tight integration of Java. You can call any command from Matlab e.g.

f=javax.swing.JFrame
f.setSize(100,100)
f.setVisible(true)

You can get help about some of the Endrov-specific Matlab commands by typing

help evm

and similarly you can get help for each command by changing the argument.

Caveats

Matlab assumes that the Java libraries are not modified. In such case the original version used by Matlab will persist in memory. The easiest way around this is restarting Matlab; there are supposed to be tricks using class loaders to do force-reloading of libraries but Endrov does not provide this.

JNI currently does not work with Matlab/Endrov. (can probably be fixed if needed, let us know)

A first example

Matlab is a bit of a pain when it comes to accessing static methods. I find it easy to just create an instance for the purpose, such as:

evdata=endrov.data.EvData

Now to load an image/datafile you can do

dat=evdata.loadFile('myfile.png')

Now when you have an object, remember that you can use TAB-completion to find what properties are available e.g.

dat.<TAB>

will show that you can type

dat.metaObjects

to get a list of all loaded objects. The output can look like this:

ans = 
  {im=endrov.imageset.Imageset@2c3f0860}

showing that there is an object "im" of type Imageset. The Javadoc and the Java code are the best sources for further documentation what all the functions do. To get the object you could use the get-method on metaObjects but it is more convenient to use getChild:

chdic=dat.getChild('im').getChild('DIC')

To pull out stack corresponding to the first frame do (see also the Matlab method evmGetEvStack)

stack=chdic.getStack(chdic.getFirstFrame)

The first plane can be pulled out of the stack like this:

plane=stack.getInt(0);

which can be manipulated like in Java but for Matlab there is the convenient function getArrayDouble2D which returns the data as a matrix:

arr=plane.getPixels().getArrayDouble2D();

Now it is possible to do the image processing in Matlab using the common functions. Displaying can be done using for example

imshow(arr./max(max(arr)))

where the image is normalized for optimal display.

Getting a Matlab image data into Endrov

This will give you a pixels object:

evp=endrov.typeImageset.EvPixels;
mypixels=evp.createFromDouble2D([1,2,3;4,5,6]);

If you need an EvImagePlane you can do

myimage=endrov.typeImageset.EvImagePlane(mypixels);


There are several ways of getting a stack. If you have your EvPixels you can do

stack=endrov.typeImageset.EvStack;
stack.putInt(0,myimage);

but you can otherwise allocate an entire stack first, and then fill it:

stack=endrov.typeImageset.EvStack;
w=50;
h=50;
d=50;
s=stack.allocate(w, h, d, endrov.typeImageset.EvPixelsType.INT);

you can then access individual planes (getInt) and fill in the content.