Page 1 of 1

Color image read as gray level

PostPosted: Tue Jan 26, 2016 9:24 am
by FiReTiTi
Hi,
I wanted to read a simple color image using bio-format. To do so, I used this simple code:
Code: Select all
ImagePlus[] images = BF.openImagePlus("...") ;

But the ImagePlus generated contains a ByteProcessor that can only code a 8-bit image. I checked, and indeed there is only 1 channel. The BufferedImage generated from the ByteProcessor is logically a TYPE_BYTE_GRAY.
I tried to open the same image with JAI and ImageIO, and everything works fine.
What is wrong?
Thanks for your help.

Re: Color image read as gray level

PostPosted: Wed Jan 27, 2016 6:09 pm
by mlinkert
Code: Select all
ImagePlus[] images = BF.openImagePlus("...") ;


But the ImagePlus generated contains a ByteProcessor that can only code a 8-bit image. I checked, and indeed there is only 1 channel. The BufferedImage generated from the ByteProcessor is logically a TYPE_BYTE_GRAY.


By default, that code will return each channel as a separate plane in the ImagePlus; images[0].getNChannels() gives the number of detected channels, which for something like an RGB JPEG image will be 3.

The way in which the channels are handled, and how files are opened in general, can be configured using the loci.plugins.in.ImporterOptions class in combination with the BF.openImagePlus(ImporterOptions) signature. If your end goal is an RGB BufferedImage, then this would be a place to start:

Code: Select all
ImporterOptions options = new ImporterOptions();
options.setId("/path/to/file");
options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE);
ImagePlus[] images = BF.openImagePlus(options);
CompositeImage ci = (CompositeImage) images[0];
Image img = ci.getImage();


If that doesn't work, then it would be helpful to know more about the file that you're trying to open (e.g. format and expected number of channels).

Re: Color image read as gray level

PostPosted: Thu Jan 28, 2016 1:07 am
by FiReTiTi
Hi, thank you very much for the information.
Knowing that, I have fixed my problem.