Upload image into omero server with matlab

Hi, I’m using a local omero server and work with omero matlab bindings. Creating projects, datasets, annotations and tables is well-documented and works fine. But how do I upload an image (ome tiff) into a dataset with omero matlab. I could not find any suggestions in the documentation or source.

regards
Micha

Hi @Miguelle,
I was only working with downloading images from omero, but there is an example of creating image:

have you checked it?
Ilya

Hi @Miguelle

This is an example code, that I have used for a single file. This is not in the documentation yet. This might be helpful

client = loadOmero(host, port);
session = client.createSession(user, password);
sessionKey = client.getSessionId();
% import image to omero
config = javaObject(‘ome.formats.importer.ImportConfig’);
config.debug.set(‘false’);
config.hostname.set(host);
config.sessionKey.set(sessionKey);
store = config.createStore();
javaList = java.util.ArrayList;
paths = javaArray(‘java.lang.String’, 0, 0);
paths(1,1) = java.lang.String(“PATH_TO_FILE”);
disp(paths(1));
reader = javaObject(‘ome.formats.importer.OMEROWrapper’, config);
reader.setMetadataOptions(javaObject(‘loci.formats.in.DefaultMetadataOptions’, loci.formats.in.MetadataLevel.ALL));
library = javaObject(‘ome.formats.importer.ImportLibrary’, store, reader);
library.addObserver(javaObject(‘ome.formats.importer.cli.LoggingImportMonitor’));
error_handler = javaObject(‘ome.formats.importer.cli.ErrorHandler’, config);
candidates = javaObject(‘ome.formats.importer.ImportCandidates’, reader, paths(1), error_handler);
success = library.importCandidates(config, candidates);
disp(success);
client.closeSession();
clear client;
clear session;

Cheers

Jmarie

1 Like

Hi Ilya,
thanks for the hint. I’ve modified the code snippet to upload a real image. So in general it works, but the way is not really satisfying. I have to load the ome.tiff,
then I must extract each plane and have to write it into a new image for upload. It is really a detour. And the metadata is lost.

Any idea how to move the metadata from the ome.tiff into the new image?

I wonder there is no simple way to upload an ome.tiff directly.

regards
Micha

@Miguelle

The code I mentioned using the Bio-Formats library directly should work for an ome-tiff?

Did you try it out?

Cheers
Jmarie

I’ve tried your code, but finally an exception is thrown at the line:

success = library.importCandidates(config, candidates);

Java exception occurred:
java.lang.IllegalArgumentException

at java.util.concurrent.ThreadPoolExecutor.<init>(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor.<init>(Unknown Source)

at java.util.concurrent.Executors.newFixedThreadPool(Unknown Source)

at ome.formats.importer.ImportLibrary.importCandidates(ImportLibrary.java:316)

Any suggestions how to debug and solve it?

Regards
Micha

At my first try the used ome.tiff seems to be inaccurate, another one works now!
Thanks.

One more question: Is there a possibility to link it to an existing dataset programmatically by the way?

Cheers
Micha

Hi Micha,
clearly additional steps do not make life easy, hopefully you will be able to adapt the Jean-Marie’s code.

@j.burel, how to define whether it is a new dataset or the image is updating an existing dataset?

Ilya

Solution to link the image to a dataset is:

config.target.set(['Dataset:',num2str(datasetId)]);

Thanks and a nice weekend
Micha

1 Like

Sorry @Miguelle for not replying earlier
Glad that you find the solution.

For @Ilya_Belevich, you will need to create the dataset first and get its ids before you can import into it.
then you use the line indicated above

@Miguelle and @j.burel - Thank you!

Ilya