Page 1 of 1

Using OME data formats in a C# imaging app

PostPosted: Sun Nov 07, 2010 3:49 pm
by KrisJa
Hi guys,

Over the last 2 years I have been busy developing a confocal imaging application in C#. This has worked out pretty well until now, it supports a wide array of hardware through a unified interface etc...

The only thing that is a bit primitive is the data model (or the lack thereof). Right now I just store a bunch of doubles that compose my image as a binary file that can be read cross platform... No metadata is stored and it is left to the operator to record all experimental parameters by hand. Since we are now moving from normal confocal to STED and a bunch of other experiment types which require multi channel support I need something better.

Because I had no clue on how to create a "proper" data format that would be future proof and extensible I went looking online and eventually stumbled upon OME.

I would very much like to implement the OME data model now but I am a bit unsure on how to go about things.:

I started by using the Microsoft SDK "xsd.exe" tool together with the ome/OMERO/ROI/SA/SPW/BinaryFile schemas to generate a class according to these schemas. I guess I could now use this class in an actual program to fill it with data and to read/write it to disk.

A few things that have me worried though are how to exactly work with this approach while measuring. As I understand the image data is converted to Base64 encoding and compressed in the OME xml but won't this incur a performance hit in my application (e.g. when recording multiple channels at once etc...)

Basically it is very difficult to write software that handles data efficiently and fast enough and I don't really know how to do it properly. It's really the weak spot in my application (the lower level HW interaction code is actually quite fancy, as is the UI, the thing can render huge arrays of data very fast but all downstream data handling sucks...)

Does anybody have experience with these topics? Are there any good open source image acquisition tools that I could use to get inspired (anything written in Java, C++ will do) and that could be used to come to grips with some good concepts?

I think I should ideally move to a situation where I have an app that can acquire data directly to the OME format and then the lab could use all the other OMERO tools for storage/data processing etc...

Any advice would be welcome...

Best regards,

Kris

Re: Using OME data formats in a C# imaging app

PostPosted: Thu Nov 11, 2010 3:50 pm
by mlinkert
Hi Kris,

A few things that have me worried though are how to exactly work with this approach while measuring. As I understand the image data is converted to Base64 encoding and compressed in the OME xml but won't this incur a performance hit in my application (e.g. when recording multiple channels at once etc...)


You can store the pixel data in the OME-XML, but there is another option that might be better suited to your needs. The OME-TIFF format allows you to store pixel data in one or more TIFF files, with the OME-XML metadata stored in one of the TIFF tags.

Does anybody have experience with these topics? Are there any good open source image acquisition tools that I could use to get inspired (anything written in Java, C++ will do) and that could be used to come to grips with some good concepts?

I think I should ideally move to a situation where I have an app that can acquire data directly to the OME format and then the lab could use all the other OMERO tools for storage/data processing etc...


I can't speak to acquisition software, but we do currently have a Java library that can (among other things) read and write OME-XML and OME-TIFF. We are currently investigating the possibility of generating C# wrappers for this library; since the API is unlikely to change much between Java and C#, you might want to have a look at some of the developer documentation and example code:

http://loci.wisc.edu/bio-formats/bio-formats-java-library

Regards,
-Melissa

Re: Using OME data formats in a C# imaging app

PostPosted: Thu Nov 11, 2010 6:59 pm
by KrisJa
Hi Melissa,

Thanks for the reply already.

Actually, I was also considering the TIFF alternative for my application. I'm currently looking into it problem is that I don't have sufficient experience in this field. I use a lot of proprietary image acquisistion software on a daily basis and it always amazes me how it always seems to run quite fast, even quite ancient software on old platforms (Win95 even...). A lot probably has to do with the fact that this software is likely written in C and reads/writes to memory blocks directly in some way as opposed to working in a managed environment. .NET bitmap support/pixel access is dead slow and I just finished writing my own unsafe code for that. Actually there is some very specific confocal imaging software out there already (http://www.imspector.de/) but it seems to me the project is somewhat dead. I tried contacting the authors but no luck there... Other than that there aren; t really that many good examples.

On the aspect of the Java libraries, I already installed a copy of NetBeans and will start studying the source soon. In that respect I was wondering: if the spec will not change a lot in the future, would it be an option to create a full on port of bio-formats to C#? I have some experience writing C# wrappers for native libraries (for instance for PI piezo controller drivers) but wrappers for Java seem to be quite the nasty affair...

On the other hand, java and C# are quite close syntax wise so I am tempted to give it a try, would you be interested in the results?

Cheers,

Kris

Re: Using OME data formats in a C# imaging app

PostPosted: Thu Nov 11, 2010 11:11 pm
by mlinkert
Hi Kris,

Actually there is some very specific confocal imaging software out there already (http://www.imspector.de/) but it seems to me the project is somewhat dead. I tried contacting the authors but no luck there... Other than that there aren; t really that many good examples.


The only open-source one that I can think of would be Micro-Manager. I don't have much experience with Micro-Manager, though, so that may or may not be what you are looking for.

On the aspect of the Java libraries, I already installed a copy of NetBeans and will start studying the source soon. In that respect I was wondering: if the spec will not change a lot in the future, would it be an option to create a full on port of bio-formats to C#?


In short, no. Writing and maintaining wrappers is far easier than maintaining two libraries that do the same thing. Not only would there be a substantial overhead for porting all of the code to C#, any bugs that are found would have to be fixed and tested twice. C# wrappers, on the other hand, can likely be autogenerated with minimal programming effort. We are already generating C++ wrappers, so we expect to be able to do something very similar for C#.

On the other hand, java and C# are quite close syntax wise so I am tempted to give it a try, would you be interested in the results?


We would certainly be interested in any results you might come up with. As I mentioned, we will likely try to autogenerate as much as possible, but if you have any suggestions or ideas we would be happy to hear them.

Regards,
-Melissa

Re: Using OME data formats in a C# imaging app

PostPosted: Fri Jan 07, 2011 4:16 am
by derekhop
Kris,

if either you or Melissa can clue me in to how to generate C# classes for ome.xsd using xsd.exe I would be profoundly grateful. I've been beating my head against it all day. My last attempt was to download the files and try to list them all in the command line:

xsd /classes ome.xsd BinaryFile.xsd SPW.xsd SA.xsd ROI.xsd xml.xsd

which gives me the wonderfully vague error

"Object reference not set to an instance of an object"

any help would be appreciated.

Derek Hopkins
Pacific Northwest National Lab

Re: Using OME data formats in a C# imaging app

PostPosted: Fri Jan 07, 2011 8:37 am
by KrisJa
It was a while ago so I ll look it up and get back to you later today...

Re: Using OME data formats in a C# imaging app

PostPosted: Fri Jan 07, 2011 7:34 pm
by derekhop
Kris,

thanks ever so. If I can get this going I will be using OME-TIFF. I've built a c# wrapper for TiffLib that I use to store multi-frame .tif files. Since I'm already manipulating tif tags, hopefully it will be trivial to embed the metadata.

Derek

Re: Using OME data formats in a C# imaging app

PostPosted: Tue Jan 11, 2011 10:40 pm
by KrisJa
Hello Derek,

It is not entirely clear to me when you are getting the error... did you generate the class file properly?

You need to run:

xsd /c /edb ome.xsd ...

I did not save the command I ran exactly but it is important to have all the xsd references in the correct order for xsd.exe to run properly. You will need:

BinaryFile
Ome
OMERO (did you get this one?)
ROI
SA
SPW

After some juggling about with the order of these, I get a C# code file.

Using this:

Code: Select all
FileStream stream = new FileStream("somefile.xml", FileMode.Open);
XmlSerializer formatter = new XmlSerializer(typeof(OME));
OME ome = (OME)formatter.Deserialize(stream);


This may or may not work. There might be some problems with some of the xml elements as xsd.exe doesn't seem to be making some mistakes at times.

If you could send over some example code I'd be happy to help out if need be.

Also, what kind of app are you working on? Confocal imaging, ...? I'm working on a C# WPF application, something along the lines of http://www.imspector.de/ but more modern (I only heard second hand accounts of the greatness of imspector :)

I eventually plan to bring it online over at codeplex but at the moment I am a bit too busy to properly finish it. I have a modular GUI, everything is modular, a hardware model with plugin support but no time yet to properly finish file handling etc...

Re: Using OME data formats in a C# imaging app

PostPosted: Tue Nov 08, 2016 10:07 am
by mtbc
Did anybody manage to settle on a good solution for working with OME-TIFFs or Bio-Formats from C# that they can share with the community? We'd be happy to point others to your work when they ask about C#.

Cheers,
Mark