We're Hiring!

Read images from OMERO client

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.

Read images from OMERO client

Postby FiReTiTi » Thu Feb 06, 2014 9:04 am

Hi,

I have to use OMERO client from my java library to access/read images stored into OMERO.
For that, I used the provided examples
Code: Select all
client clien = new client("omero.ohsu.edu", 4064);
   ServiceFactoryPrx entry = clien.createSession("login", "passwd") ;
   System.out.println("Session opened.") ;
   // if you want to have the data transfer encrypted then you can use the entry variable otherwise use the following
   client unsecureClient = clien.createClient(false) ;
   ServiceFactoryPrx entryUnencrypted = unsecureClient.getSession() ;
   
   //Retrieve the user id.
   long userId = entryUnencrypted.getAdminService().getEventContext().userId ;
   long groupId = entryUnencrypted.getAdminService().getEventContext().groupId ;
   
   IContainerPrx proxy = entryUnencrypted.getContainerService() ;
   ParametersI param = new ParametersI() ;
   param.exp(omero.rtypes.rlong(userId)) ;
   param.leaves() ; //indicate to load the images
   RenderingEnginePrx renderproxy = entryUnencrypted.createRenderingEngine();
   System.out.println("\nLoading hierarchy...") ;
   List<IObject> projects = proxy.loadContainerHierarchy(Project.class.getName(), new ArrayList<Long>(13), param) ;
   //You can directly interact with the IObject or the Pojos object. Follow interaction with the Pojos.
   Iterator<IObject> projectiter = projects.iterator() ;
   
   while ( projectiter.hasNext() )
      {
      ProjectData project = new ProjectData( (Project) projectiter.next())  ;
      Set<DatasetData> datasets = project.getDatasets() ;
      Iterator<DatasetData> datasetiter = datasets.iterator() ;
      while ( datasetiter.hasNext() )
         {
         DatasetData dataset = datasetiter.next() ;
         Set<ImageData> images = dataset.getImages() ;
         Iterator<ImageData> imiter = images.iterator() ;
         while ( imiter.hasNext() )
            {
            ImageData imdata = imiter.next() ;
            PixelsData pixels = imdata.getDefaultPixels() ;
            long pixelsId = pixels.getId() ;
            renderproxy.lookupPixels(pixelsId) ;
            if ( !(renderproxy.lookupRenderingDef(pixelsId)) )
               {
               System.out.println("\t\t\t Reset and retry") ;
               renderproxy.resetDefaults();
               renderproxy.lookupRenderingDef(pixelsId);
               }
            renderproxy.load() ;
            // Now can interact with the rendering engine.
            renderproxy.setActive(0, false) ;
            // to render the image uncompressed
            PlaneDef pDef = new PlaneDef() ;
            pDef.z = 0 ;
            pDef.t = 0 ;
            pDef.slice = omero.romio.XY.value ;
            //int[] uncompressed = renderproxy.renderAsPackedInt(pDef) ;
            byte[] compressed = renderproxy.renderCompressed(pDef) ;
            //Create a buffered image
            ByteArrayInputStream stream = new ByteArrayInputStream(compressed) ;
            BufferedImage image = ImageIO.read(stream) ;
            }
         }
      }
   
   renderproxy.close() ;
   clien.closeSession() ;
   System.out.println("\tSession closed.") ;
   if ( unsecureClient != null )
      {
      unsecureClient.closeSession() ;
      System.out.println("Unsecure Client Session closed.") ;
      }


This code accesses to the images, but the reading doesn't work correctly, so the line "BufferedImage image = ImageIO.read(stream) ;" has an issue.
It uses javax.imageio to read images, but it does not work correctly. I did tests using one tiff image encoded into 16 bits and some png images encoded on 1 byte => all of them are not correctly read.

Questions: which reader can I use? And how?

It seems that ImageJ can be used, because in the interface, we can use "View with ImageJ" and that would be perfect because ImageJ can read all images types I need.
Question: I can use ImageJ from the OMERO client?

Thank you for your help.
Regards,
FiReTiTi
 
Posts: 26
Joined: Tue Feb 04, 2014 7:30 am
Location: Portland, OR, USA

Re: Read images from OMERO client

Postby jburel » Fri Feb 07, 2014 2:05 pm

Hi
OMERO uses Bioformats to read the data, similar to what you will do if you want to read any image in ImageJ

To access your image stored in OMERO, you could use the desktop client in headless mode. Follow a link to an example.
https://github.com/openmicroscopy/openm ... dless.java

or if you want to see an example of the rendering engine
https://github.com/openmicroscopy/openm ... les/viewer

FiReTiTi wrote:It seems that ImageJ can be used, because in the interface, we can use "View with ImageJ" and that would be perfect because ImageJ can read all images types I need.
Question: I can use ImageJ from the OMERO client?

You can use the desktop client as an imageJ plugin. If you use it that way, by default the image will be opened in ImageJ using BioFormats (you will need the bio-formats plugin).

Let me know if you need more examples.
Thanks

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: Read images from OMERO client

Postby FiReTiTi » Sat Feb 08, 2014 3:12 am

Hi,

thank you so much for your reply and the links.
I am going to take a serious look to all of that.

regards,
FiReTiTi
 
Posts: 26
Joined: Tue Feb 04, 2014 7:30 am
Location: Portland, OR, USA

Re: Read images from OMERO client

Postby FiReTiTi » Mon Feb 10, 2014 12:28 am

Hi,
I have some issues to do what I have to: I don't know which Bio-format methods call with Omero-client.
I think all I need is already done in the omero_ij.jar plugin.
But I can not find the source code of this plugin.

Can you tell me where I can find it?

Regards,
FiReTiTi
 
Posts: 26
Joined: Tue Feb 04, 2014 7:30 am
Location: Portland, OR, USA

Re: Read images from OMERO client

Postby jburel » Tue Feb 11, 2014 8:24 pm

see reply on viewtopic.php?f=6&t=7415

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee


Return to Developer Discussion

Who is online

Users browsing this forum: Google [Bot] and 1 guest