We're Hiring!

Color image read as gray level

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.

Color image read as gray level

Postby FiReTiTi » Tue Jan 26, 2016 9:24 am

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.
FiReTiTi
 
Posts: 26
Joined: Tue Feb 04, 2014 7:30 am
Location: Portland, OR, USA

Re: Color image read as gray level

Postby mlinkert » Wed Jan 27, 2016 6:09 pm

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

Re: Color image read as gray level

Postby FiReTiTi » Thu Jan 28, 2016 1:07 am

Hi, thank you very much for the information.
Knowing that, I have fixed my problem.
FiReTiTi
 
Posts: 26
Joined: Tue Feb 04, 2014 7:30 am
Location: Portland, OR, USA


Return to User Discussion [Legacy]

Who is online

Users browsing this forum: No registered users and 1 guest