Page 1 of 1

BufferedImageReader - Merging channels

PostPosted: Wed Jun 24, 2015 2:27 pm
by Charavay
Hi,

I develop a java application to render images : these images are from different formats. In the case where an image has several channels, I would like to create a bufferedImage corresponding to the merged channels. I have looked at the BioFormats documentation but I have found not hints.

Here you can find my code :
Code: Select all
BufferedImageReader bufferedImageReader = new BufferedImageReader(new ImageReader());
            BufferedImage bufferedImage;
            try {
                bufferedImageReader.setId(imagePath);
                // OpenImage(0) <=> open the image corresponding to the first channel, the first z and the first t
                bufferedImage = bufferedImageReader.openImage(0);
            } catch (FormatException ex) {
                // Can not read the image
                bufferedImage = null;
            } catch (IOException ex) {
                // Can not read the image
                bufferedImage = null;
            }


Thank you in advance for your help

Céline

Re: BufferedImageReader - Merging channels

PostPosted: Wed Jun 24, 2015 4:29 pm
by mlinkert
Hi Céline,

You might try using ChannelMerger as the base reader when constructing the BufferedImageReader.
See:

http://downloads.openmicroscopy.org/bio ... erger.html
http://www.openmicroscopy.org/site/supp ... ing-extras
https://github.com/openmicroscopy/biofo ... .java#L439

The first line of your code would then become:

Code: Select all
BufferedImageReader bufferedImageReader = new BufferedImageReader(new ChannelMerger());


and subsequent calls to bufferedImageReader.openImage should result in a single BufferedImage with all channels merged together.

If you want more control over how the channels are merged, then leave the BufferedImageReader construction as it was, and use http://downloads.openmicroscopy.org/bio-formats/5.1.2/api/loci/formats/gui/AWTImageTools.html#mergeChannels(java.awt.image.BufferedImage%5b%5d) to merge the individual channel images together - this would let you re-order or omit channels if needed.

Regards,
-Melissa

Re: BufferedImageReader - Merging channels

PostPosted: Fri Jun 26, 2015 2:40 pm
by Charavay
Hi Melissa

Thank you for your answer. It works very well.

Best regards

Céline