We're Hiring!

BufferedImageReader - Merging channels

Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats
Please note:
Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats

If you are having trouble with image files, there is information about reporting bugs in the Bio-Formats documentation. Please send us the data and let us know what version of Bio-Formats you are using. For issues with your code, please provide a link to a public repository, ideally GitHub.

BufferedImageReader - Merging channels

Postby Charavay » Wed Jun 24, 2015 2:27 pm

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
Charavay
 
Posts: 14
Joined: Fri Jun 19, 2015 1:49 pm

Re: BufferedImageReader - Merging channels

Postby mlinkert » Wed Jun 24, 2015 4:29 pm

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
User avatar
mlinkert
Team Member
 
Posts: 353
Joined: Fri May 29, 2009 2:12 pm
Location: Southwest Wisconsin

Re: BufferedImageReader - Merging channels

Postby Charavay » Fri Jun 26, 2015 2:40 pm

Hi Melissa

Thank you for your answer. It works very well.

Best regards

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


Return to User Discussion [Legacy]

Who is online

Users browsing this forum: No registered users and 1 guest