Page Contents


Feature List

Previous topic

Guidelines for writing OMERO.scripts

Next topic

OMERO.scripts advanced topics

This Page


This documentation is for OMERO 5.2. This version is now in maintenance mode and will only be updated in the event of critical bugs or security concerns. OMERO 5.3 is expected in the first quarter of 2017.

MATLAB and Python

MATLAB functionality can be mixed into Python scripts via the Python package Mlabwrap.

Installing Mlabwrap

To install MlabWrap follow the installation guide and make sure that the paths are set for the environment variables:


Example MATLAB scripts

Below are some sample scripts showing MATLAB being launched from OMERO.scripts. MATLAB functions can also call the OMERO Java language bindings interface to access the server from the MATLAB functions.

Calling a simple MATLAB function

import omero, omero.scripts as script
# import mlabwrap to launch matlab.
from mlabwrap import matlab;
client = script.client("", "Get matrix of random numbers drawn from a uniform distribution",
                        script.Long("x").inout(), script.Long("y").inout())

x = client.getInput("x").val
y  = client.getInput("y").val

# call the matlab rand function via mlabwrap will automatically launch matlab
# if it is not already running on the system and call the rand method.
val = matlab.rand(x,y);
print val

Using the OMERO interface inside MATLAB

This example shows the MATLAB script being called, passed to the client object and accessing the same client instance as the script.

import omero, omero.scripts as script
# import mlabwrap to launch matlab.
from mlabwrap import matlab;
client = script.client("", "Call the matlab projection code",
                        script.String("iceConfig").in(), script.String("user").in(),
                        script.Long("pixelsId").inout(), script.String("method").inout()

iceConfig = client.getInput("pixelsId").val
user = client.getInput("pixelsId").val
password = client.getInput("pixelsId").val
method  = client.getInput("method").val
stack = client.getInput("stack").val;

image = matlab.performProjection(iceConfig, username, password, pixelsId, stack, method);

The MATLAB projection method

function performProjection(iceConfig, username, password, pixelsId, zSection, method)

omerojavaService = createOmeroJavaService(iceConfig, username, password);
pixels = getPixels(omerojavaService, pixelsId);
stack = getPlaneStack(omerojavaService, pixelsId, zSection);
projectedImage = ProjectionOnStack(stack, method);
function [resultImage] = ProjectionOnStack(imageStack,type)

[zSections, X, Y] = size(imageStack);

if(strcmp(type,'mean') || strcmp(type, 'sum'))
    resultImage = squeeze(sum(imageStack));
        resultImage = resultImage./zSections;
    resultImage = squeeze(max(imageStack,[],1));