Page 1 of 4

Uploading from MATLAB

PostPosted: Wed Feb 22, 2012 8:34 pm
by dballvt
I realize there are several discussions on this topic already, but I can't seem to make sense of them. I'd like to upload images to our database directly from MATLAB. Our OMERO database is v4.3.4.

I understand that the first step is to get the ImportLibrary. From one of the discussions, I found that it should be in the Linux client downloads. So I downloaded the 4.3.3 clients, and found the jar file OmeroImporter.jar. Is that the correct file to use?

I added this to the java path in MATLAB, and typed: import ome.formats.importer.ImportConfig;

I starter a client by using:
>> loadOmero;
>>c = omero.client(ServerName);
>> s = c.createSession(Uname,pwd);
>> g = s.createGateway();

but when I type: config = ImportConfig();

I get the following error:

??? Java exception occurred:
java.lang.NullPointerException
at java.util.prefs.AbstractPreferences.node(AbstractPreferences.java:817)
at java.util.prefs.AbstractPreferences.node(AbstractPreferences.java:800)
at java.util.prefs.Preferences.userNodeForPackage(Preferences.java:358)
at ome.formats.importer.ImportConfig.prefs(ImportConfig.java:140)
at ome.formats.importer.ImportConfig.<init>(ImportConfig.java:168)
at ome.formats.importer.ImportConfig.<init>(ImportConfig.java:154)

Is there something else that I need to import, or do I need to run something else first?

Any help would be greatly appreciated!

Re: Uploading from MATLAB

PostPosted: Thu Feb 23, 2012 7:45 am
by jmoore
This is very odd. From the OMERO point of view, you've done everything correctly, but searching briefly shows that other Matlab users are having this same problem:


Are you on Mac? What JVM are you using? The only suggestion that I see is to add the necessary classes to the static path rather than the dynamic path. Could you try that and let us know if it works?

Thanks,
~Josh

Re: Uploading from MATLAB

PostPosted: Fri Feb 24, 2012 7:25 pm
by dballvt
Yes it is a Mac. JVM version: 1.6.0_29-b11-402-11D50b.

I added that file to the static path, restarted matlab, and I get the same message.

Re: Uploading from MATLAB

PostPosted: Fri Feb 24, 2012 10:53 pm
by dballvt
I just tried to do this on Windows, which is running R2010a with JVM version: 1.6.0_12-b04

and I get the following error there:

??? Java exception occurred:
java.lang.NoClassDefFoundError: org/ini4j/IniFile

at ome.formats.importer.ImportConfig.<init>(ImportConfig.java:168)

at ome.formats.importer.ImportConfig.<init>(ImportConfig.java:154)

Caused by: java.lang.ClassNotFoundException: org.ini4j.IniFile

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at
com.mathworks.jmi.CustomURLClassLoader.findClass(ClassLoaderManager.java:754)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

... 2 more

I'm able to create an OMERO session on both Mac & Windows, but I can't seem to use the importer jar.

Re: Uploading from MATLAB

PostPosted: Sat Feb 25, 2012 8:22 pm
by jmoore
The Windows exception is expected, which I should have stated before. If you intend to use the importer you should include all of the jars from OMERO_DIST/lib/client on your classpath. Otherwise, you will continually run into NoClassDefFound errors. On the Mac, perhaps adding all of them to the static path will similarly help. If not, my first suspicion would be that a jar is getting adding somehow before the static classpath, but that'd certainly take some digging to find out.

Cheers,
~Josh

Re: Uploading from MATLAB

PostPosted: Sun Feb 26, 2012 7:03 pm
by dballvt
I don't see the exact directory OMERO_DIST/lib/client (I'm assuming OMERO_DIST would actually be OMERO.clients-Beta4.3.3.linux), but there is a OMERO.clients-Beta4.3.3.linux/libs folder that contains a bunch of jar files. Is that the folder you mean?

I tried adding all of these to the static path and still get the same errors (on Mac).

Re: Uploading from MATLAB

PostPosted: Tue Feb 28, 2012 8:32 pm
by sbesson
I was able to reproduce the exception both under Mac and Linux. It looks like Matlab is shadowing the java.util.prefs.Preferences.userRoot() method

Can you try the following:
1) get the ini4j jar archive (under lib/repository in https://github.com/openmicroscopy/openmicroscopy)

2) at Matlab startup, set the PreferencesFactory to use the MacOSX ones and add the ini4j to the java path
Code: Select all
java.lang.System.setProperty('java.util.prefs.PreferencesFactory','java.util.prefs.MacOSXPreferencesFactory');
javaaddpath('path_to_lib/ini4j-0.3.2.jar');


3) try ImportConfig once again using the Omero toolbox
Code: Select all
loadOmero
import ome.formats.importer.ImportConfig
ImportConfig()


Let us know if this works.

Re: Uploading from MATLAB

PostPosted: Fri Mar 02, 2012 4:52 pm
by dballvt
Yes, that allows me to create an ImportConfig object. Thank you!

Now, I'm trying to follow the code posted here:
https://gist.github.com/1710116

I can get up to
>> config.targetClass.set(Dataset.class.getName());

when I get an error saying:
Attempt to reference field of non-structure array

Re: Uploading from MATLAB

PostPosted: Fri Mar 02, 2012 7:01 pm
by jmoore
This is a change between Matlab versions. Previously (2007 and before), it was possible previously to access the ".class" of the imported classes. Now, it's necessary to use the full string for the class instead:
Code: Select all
config.targetClass.set('omero.model.Dataset')

Cheers,
~Josh

Re: Uploading from MATLAB

PostPosted: Fri Mar 02, 2012 9:32 pm
by dballvt
OK, I think I'm getting very close. To test, I imported a single tiff image, and I get the following messages in MATLAB that seem to me to indicate success:
[INFO] ImportLibrary - File format: Tagged Image File Format
[INFO] ImportLibrary - Base reader: loci.formats.in.TiffDelegateReader
[INFO] ImportLibrary - Metadata only import? false
[INFO] ImportLibrary - Archiving enabled? false
[INFO] ImportLibrary - Container metadata only import? false
[INFO] ImportLibrary - Reader is not of HCS domain, use metafile: true
[INFO] LoggingImportMonitor - IMPORT_DONE
Imported pixels:
1003

I checked on the server filesystem, and there is a file called 1003 in the pixels folder. However, the new image doesn't show up in the OMERO.insight GUI. When importing, I changed the dataset ID to the only dataset that we currently have in the database, so I don't understand why it doesn't show up. Does it have something to do with the fact that there is no metadata associated with it, yet?

Thanks for all of your help!!