Rendering images per channel
Posted: Tue Jun 30, 2015 2:27 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, ome.tiff ... If a file contains several channels, I want to display one image per channel and an image with all channels.
I have developed the following code based on an example given on the Omero web site :
With an ome.tiff file containg several channels, it works very well. But for a RGB tiff, the sizeC is equal to 3 and my application displays one image for the red channel, one for the green, one for the blue and one image with the three channels : in this case, I would like to display only one image with the three channels. How can I make it ?
Thank you in advance for your help
Céline
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, ome.tiff ... If a file contains several channels, I want to display one image per channel and an image with all channels.
I have developed the following code based on an example given on the Omero web site :
- Code: Select all
// Read image
// See documentation at https://www.openmicroscopy.org/site/support/omero5.1/developers/Java.html
// https://www.openmicroscopy.org/community/viewtopic.php?f=6&t=7839
// Beans containing the bufferedImages to display
List<ImageBean> imageBeans = new ArrayList<>();
BufferedImage bufferedImage;
List<Image> images = containerPrx.getImages(Image.class.getName(), Arrays.asList(imageId), new ParametersI());
if (images.size() == 0) {
// Can not find image
bufferedImage = null;
ImageBean imageBean = new ImageBean(imageId, bufferedImage);
imageBeans.add(imageBean);
} else {
Image image = images.get(0);
ImageData imageData = new ImageData(image);
PixelsData pixelsData = imageData.getDefaultPixels();
// Number of z sections
int sizeZ = pixelsData.getSizeZ();
// Number of timepoints
int sizeT = pixelsData.getSizeT();
// Number of channels
int sizeC = pixelsData.getSizeC();
// Retrieve pixels
long pixelsId = pixelsData.getId();
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.
// Render the image
PlaneDef pDef = new PlaneDef();
pDef.z = 0;
pDef.t = 0;
pDef.slice = omero.romio.XY.value;
// if the image contains several channels : create one bufferedimage for each channel
if (sizeC > 1) {
for (int channelToActivate = 0; channelToActivate < sizeC; channelToActivate++) {
for (int channel = 0; channel < sizeC; channel++) {
if (channel == channelToActivate) {
// Activate the channel
proxy.setActive(channel, Boolean.valueOf(true));
} else {
// Desactivate the channel
proxy.setActive(channel, Boolean.valueOf(false));
}
}
// render the data compressed
byte[] compressed = proxy.renderCompressed(pDef);
//Create a buffered image
ByteArrayInputStream stream = new ByteArrayInputStream(compressed);
try {
bufferedImage = ImageIO.read(stream);
ImageBean imageBean = new ImageBean(imageId, bufferedImage);
imageBeans.add(imageBean);
} catch (IOException ex) {
// Can not read the image (image not found or not supported format)
bufferedImage = null;
ImageBean imageBean = new ImageBean(omeroImageId, bufferedImage);
imageBeans.add(imageBean);
}
}
}
// create a bufferedimage for all channels
for (int channel = 0; channel < sizeC; channel++) {
// Activate the channel
proxy.setActive(channel, Boolean.valueOf(true));
}
//render the data uncompressed.
//int[] uncompressed = proxy.renderAsPackedInt(pDef);
//render the data compressed
byte[] compressed = proxy.renderCompressed(pDef);
//Create a buffered image
ByteArrayInputStream stream = new ByteArrayInputStream(compressed);
try {
bufferedImage = ImageIO.read(stream);
ImageBean imageBean = new ImageBean(imageId, bufferedImage);
imageBeans.add(imageBean);
} catch (IOException ex) {
// Can not read the image (image not found or not supported format)
bufferedImage = null;
ImageBean imageBean = new ImageBean(imageId, bufferedImage);
imageBeans.add(imageBean);
}
// Close
proxy.close();
With an ome.tiff file containg several channels, it works very well. But for a RGB tiff, the sizeC is equal to 3 and my application displays one image for the red channel, one for the green, one for the blue and one image with the three channels : in this case, I would like to display only one image with the three channels. How can I make it ?
Thank you in advance for your help
Céline