We're Hiring!

Can not read images from Omero

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.

Can not read images from Omero

Postby Charavay » Fri Jun 19, 2015 2:51 pm

Hi,

I'm developing a java application : it will display images from omero by using the BufferedImage class. The format of images can be jpeg, tiff, png..

I have developed the following code based on an example given on the Omero web site :

Code: Select all
RawPixelsStorePrx rawPixelsStorePrx = serviceFactoryPrx.createRawPixelsStore();
            rawPixelsStorePrx.setPixelsId(pixelsId, false);
            for (int z = 0; z < sizeZ; z++) {
                for (int t = 0; t < sizeT; t++) {
                    for (int c = 0; c < sizeC; c++) {
                        byte[] imageInBytes = rawPixelsStorePrx.getPlane(z, c, t);
                        // convert byte array back to BufferedImage
                        ByteArrayInputStream inputStream = new ByteArrayInputStream(imageInBytes);
                        BufferedImage bufferedImage;
                        try {
                            bufferedImage = ImageIO.read(inputStream);

                        } catch (IOException ex) {
                            // Can not read the image (image not found or not supported format)
                            bufferedImage = null;
                        }
                        ImageBean imageBean = new ImageBean("omero:iid=" + imageId, bufferedImage);
                        imageBeans.add(imageBean);

                    }
                }
            }
            rawPixelsStorePrx.close();


In this case, the returned bufferedImage is always null (I have tested with jpeg, tiff and png).

I have tried another code based on the Omero web site :
Code: Select all
RenderingEnginePrx proxy = serviceFactoryPrx.createRenderingEngine();
            proxy.lookupPixels(pixelsId);
            if (!(proxy.lookupRenderingDef(pixelsId))) {
                proxy.resetDefaultSettings(true);
                proxy.lookupRenderingDef(pixelsId);
            }
            proxy.load();
            // Now can interact with the rendering engine.
            proxy.setActive(0, Boolean.valueOf(false));
            // to render the image uncompressed
            PlaneDef pDef = new PlaneDef();
            pDef.z = 0;
            pDef.t = 0;
            pDef.slice = omero.romio.XY.value;
            //render the data uncompressed.
            int[] uncompressed = proxy.renderAsPackedInt(pDef);
            byte[] compressed = proxy.renderCompressed(pDef);

            //Create a buffered image
            ByteArrayInputStream stream = new ByteArrayInputStream(compressed);
            BufferedImage bufferedImage;
            try {
                bufferedImage = ImageIO.read(stream);

            } catch (IOException ex) {
                // Can not read the image (image not found or not supported format)
                bufferedImage = null;
            }
            ImageBean imageBean = new ImageBean("omero:iid=" + imageId, bufferedImage);
            imageBeans.add(imageBean);

            // Close
            proxy.close();


The returned bufferedImage is not null but the displayed image is not correct (black image for tiff, strange colors for png and jpeg).

I think I not correctly use the BufferedImage class (I'm new with the image display in java applications). Could you please help me ?

Thank you in advance

Céline
Charavay
 
Posts: 14
Joined: Fri Jun 19, 2015 1:49 pm

Re: Can not read images from Omero

Postby Dominik » Mon Jun 22, 2015 10:29 am

Hi Céline,

your second example looks fine to me, I also could run it without problems. The reason for the strange color might be, that you disable the first channel
Code: Select all
proxy.setActive(0, Boolean.valueOf(false));

What do the images look like when you remove this line of code?

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

Re: Can not read images from Omero

Postby Charavay » Mon Jun 22, 2015 4:03 pm

Hi Dominik,

Thank you for your answer : it works very well by removing the line you have indicated.

I have a question : if I want to retrieve a particular channel, is it an easy way to make it or is it necessary to disable the channels I don't want to render ?

Best regards

Céline
Charavay
 
Posts: 14
Joined: Fri Jun 19, 2015 1:49 pm

Re: Can not read images from Omero

Postby Dominik » Tue Jun 23, 2015 8:59 am

Yes, if you want a rendered image with just one particular channel you have to disable all other channels, the RenderingEngine does not offer a direct method for this purpose.

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

Re: Can not read images from Omero

Postby Charavay » Tue Jun 23, 2015 3:09 pm

Thank you for your answer Dominik.

Kind regards

Céline
Charavay
 
Posts: 14
Joined: Fri Jun 19, 2015 1:49 pm


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest