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,