We're Hiring!

Matlab Tutorial

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Matlab Tutorial

Postby ramunno » Mon Oct 01, 2012 7:43 pm

Hello,
I have a long history in Matlab but I haven't had any luck successfully opening an image from the server, and the information on the website is not very clear. Does anyone have a step by step tutorial, or can point me to the right area of the API?

Thank You,
Damien
ramunno
 
Posts: 2
Joined: Mon Oct 01, 2012 7:31 pm

Re: Matlab Tutorial

Postby sbesson » Tue Oct 02, 2012 7:50 am

Dear Damien,

With OMERO.matlab-4.4.4-ice33-b3099 installed and after correct initialization of the variables, the code example below should:
1. initiate the toolbox and connect to the server
2. load the image imageID using the ContainerService
3. retrieve the first plane of the image using the RawPixelsStore service

Code: Select all
server = xxx;
username = xxx;
password = xxx;
imageID = xxx;

% Load the OMERO.matlab toolbox
loadOmero;

% Create a client and a session
client = omero.client(server);
session = client.createSession(username, password);
omeroKeepAlive(client);

% Create a list of image IDs to be retrieved
ids = java.util.ArrayList();
imageId = java.lang.Long(imageID);
ids.add(imageId);

% Load images by IDs using container service
proxy = session.getContainerService();
list = proxy.getImages('omero.model.Image', ids, omero.sys.ParametersI());
image = list.get(0);

% Create raw pixels store to read the planes
pixels = image.getPrimaryPixels();
store = session.createRawPixelsStore();
store.setPixelsId(pixels.getId().getValue(), false);

% Read the first plane and convert it into double matrix
plane = store.getPlane(0, 0, 0);
I = double(toMatrix(plane,pixels)');


Let me know if this works,
Sebastien
Sebastien
User avatar
sbesson
Team Member
 
Posts: 421
Joined: Tue Feb 28, 2012 7:20 pm

Re: Matlab Tutorial

Postby ramunno » Fri Oct 05, 2012 9:21 pm

Hello Sebastien,
Thank you for the help! I am sorry for the delay, my disk encryption at work had a problem and I had to reinstall my OS. I was able to open an image with your commented code. It is a lot more clear now, and now I have a more narrow set of methods I can look at in the API first. (So that I can switch planes, and find the image number, etc.. )

Thanks,
Damien
ramunno
 
Posts: 2
Joined: Mon Oct 01, 2012 7:31 pm

Re: Matlab Tutorial

Postby eberleia » Fri Mar 07, 2014 2:32 pm

Hi,

I tried to enter the following code in my MATLAB installation (installed on RedHat Linux), but get some error message on the line

list = proxy.getImages('omero.model.Image', ids, omero.sys.ParametersI());

The error message is:

Java exception occurred:
java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Long
at omero.sys.LongListHelper.write(LongListHelper.java:35)
...
at omero.api.IContainerPrxHelper.getImages(IContainerPrxHelper.java.1181)

Is there some change done in the meantime? Should I do it in some other manner?

By the way, the following calls from the documentation do not work:
projects = getProjects(session)
datasets = getDatasets(session)
images = getImages(session)

The error message is Ice.UnmarshalOutOfBoundsException.

Do you have any explanation why this does not work?

Thanks in advance,
Andreas
eberleia
 
Posts: 15
Joined: Mon Mar 03, 2014 1:45 pm

Re: Matlab Tutorial

Postby jmoore » Fri Mar 07, 2014 3:10 pm

How is 'ids' being set? The error message seems to be saying that there's a double as opposed to a long in there. All image IDs should be java.lang.Long instances.

Cheers,
~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Matlab Tutorial

Postby eberleia » Mon Mar 10, 2014 1:24 pm

Hi,

sorry, but I realized afterwards that we used version 4.4.10 on the server side and version 5 on the client side. After downloading the corrent version, everything worked as expected.

Thanks,
Andreas
eberleia
 
Posts: 15
Joined: Mon Mar 03, 2014 1:45 pm

Re: Matlab Tutorial

Postby jmoore » Tue Mar 11, 2014 8:22 am

Thanks for letting us know, Andreas.

Cheers,
~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 0 guests