We're Hiring!

16 bit tiff files

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.

16 bit tiff files

Postby zeevs » Thu Jan 07, 2016 6:58 am

We are developing a new FRET-based screen, that needs significant development of proprietary image processing tools. We are developing these tools with Java / imageJ and have begun to implement the OMERO database.
My question is as follows. We need fast access to the 16bit pixel buffer of the images. We have not found a good way so far to get such buffers through the OMERO to the Java image processing routines we develop (we use the py4j.GatewayServer to connect python scripts to the Java image processing tools).
Another approach we considered was to retrieve the original file path string to the Java routine and use ImageJ to open the TIFF file, however again we have failed to find a way to get the absolute path of an image to the Java through the OMERO.
Any suggestions would be welcomed.
Zeev
zeevs
 
Posts: 3
Joined: Wed Jan 06, 2016 8:18 pm

Re: 16 bit tiff files

Postby jmoore » Fri Jan 08, 2016 11:43 am

Hi Zeev,

zeevs wrote:My question is as follows. We need fast access to the 16bit pixel buffer of the images. We have not found a good way so far to get such buffers through the OMERO to the Java image processing routines we develop (we use the py4j.GatewayServer to connect python scripts to the Java image processing tools).


Can you tell us a little more about the data? How large is it in the various dimensions? Time-lapse? You're trying to get a fast buffer to a single 2D plane? Several in succession?

Another approach we considered was to retrieve the original file path string to the Java routine and use ImageJ to open the TIFF file, however again we have failed to find a way to get the absolute path of an image to the Java through the OMERO.


Will this process be running server-side and/or can you mount the server data directories locally?

Cheers,
~Josh.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: 16 bit tiff files

Postby zeevs » Sat Jan 09, 2016 6:03 pm

Hi Josh
Thanks for your reply.
each image is about 10Megs. We are gearing towards millions of images on the cloud. Right now we are developing the architecture for image analysis locally. Hope this helps
Zeev
zeevs
 
Posts: 3
Joined: Wed Jan 06, 2016 8:18 pm

Re: 16 bit tiff files

Postby Dominik » Tue Jan 12, 2016 10:44 am

Hi Zeev,

I can give you an example for how to access the pixels data using Java, that's quite simple using the Java Gateway. I also add an example for how to get the full path of the image files. This is unfortunately not so straightforward, as you already noticed. There's not a simple Gateway method for this, yet, so you'd have to use an HQL query.

Here's the example. I hope this is of any help for you.

Code: Select all
        final long imageID = 1;

        LoginCredentials lc = new LoginCredentials("root", "omero", "localhost");

        Gateway gw = new Gateway(new SimpleLogger());
        ExperimenterData user = gw.connect(lc);
        SecurityContext ctx = new SecurityContext(user.getGroupId());

        // Access to pixel data:
        BrowseFacility browse = gw.getFacility(BrowseFacility.class);
        ImageData img = browse.getImage(ctx, imageID);

        RawDataFacility rdf = gw.getFacility(RawDataFacility.class);
        Plane2D plane = rdf
                .getPlane(ctx, img.getDefaultPixels(), 0, 0, 0, true);

        double pixel = plane.getPixelValue(0, 0);
        System.out.println("Pixel value of image ID=" + imageID
                + " at z=0, t=0, channel=0, x=0, y=0: " + pixel);

        // Get the image file paths:
        IQueryPrx queryService = gw.getQueryService(ctx);
        ParametersI param = new ParametersI();

        String filesetQuery = "select fs from Fileset as fs "
                + "join fetch fs.images as image "
                + "left outer join fetch fs.usedFiles as usedFile "
                + "join fetch usedFile.originalFile as f "
                + "join fetch f.hasher " + "where image.id = :imageId";
        param.add("imageId", omero.rtypes.rlong(imageID));

        List<?> filesets = queryService.findAllByQuery(filesetQuery, param);
        Iterator<?> i = filesets.iterator();
        Fileset set;
        List<FilesetEntry> entries;
        Iterator<FilesetEntry> j;
        System.out.println("Image files:");
        while (i.hasNext()) {
            set = (Fileset) i.next();
            entries = set.copyUsedFiles();
            j = entries.iterator();
            while (j.hasNext()) {
                FilesetEntry fs = j.next();
                OriginalFile file = fs.getOriginalFile();
                System.out.println(file.getPath().getValue()
                        + file.getName().getValue());
            }
        }

        gw.disconnect();


If you want to write a Java client for accessing your OMERO server, I'd recommend you take a look at the "minimal-omero-client" example: https://github.com/ome/minimal-omero-client Respectively the documentation with some more examples: https://www.openmicroscopy.org/site/sup ... /Java.html

Regards,
Dominik
User avatar
Dominik
Team Member
 
Posts: 149
Joined: Mon Feb 10, 2014 11:26 am

Re: 16 bit tiff files

Postby zeevs » Wed Jan 20, 2016 6:27 pm

Hi Dominik
Thanks for your detailed response.
You show how to get the value of "a pixel", but we need the entire pixel buffer as a short[] buffer.

What we did was to get the buffer as a byte[] buffer, and then convert it to short in the following way:

int size = byteBuf.length;
short[] shortBuf = new short[size / 2];
ByteBuffer.wrap(byteBuf).order(ByteOrder.BIG_ENDIAN).asShortBuffer().get(shortBuf);

This is quite awkward and we would appreciate learning a cleaner method. I'm sure the Fiji Omero plugin does it in a cleaner way, but I haven't been able to decipher it yet.

Zeev
zeevs
 
Posts: 3
Joined: Wed Jan 06, 2016 8:18 pm

Re: 16 bit tiff files

Postby Dominik » Thu Jan 21, 2016 2:37 pm

Hi Zeev,

with respect to the byte conversion, there's a method in bioformats, see https://github.com/openmicroscopy/biofo ... .java#L544
Is this of any help for you?

With the Java Gateway you can request the Plane2D as in previous mentioned example. It holds the raw byte array, but you can't access it directly as it's a private field at the moment. I'll add this as RFE to the gateway work, it would certainly be useful to have access to the byte buffer directly and not just to single pixel values.

Regards,
Dominik
User avatar
Dominik
Team Member
 
Posts: 149
Joined: Mon Feb 10, 2014 11:26 am


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 0 guests