Page 1 of 1

Can not read images from Omero

PostPosted: Fri Jun 19, 2015 2:51 pm
by Charavay
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

Re: Can not read images from Omero

PostPosted: Mon Jun 22, 2015 10:29 am
by Dominik
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

Re: Can not read images from Omero

PostPosted: Mon Jun 22, 2015 4:03 pm
by Charavay
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

Re: Can not read images from Omero

PostPosted: Tue Jun 23, 2015 8:59 am
by Dominik
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

Re: Can not read images from Omero

PostPosted: Tue Jun 23, 2015 3:09 pm
by Charavay
Thank you for your answer Dominik.

Kind regards

Céline