Page 1 of 1

Ome.tiff file - can't display with colors

PostPosted: Mon Jun 29, 2015 10:42 am
by Charavay
Hi,

I try to display the different channels contained in an ome.tiff file in a java application with bio-formats.

This file contains 4 channels. When I open it under ImageJ, the image is colorized ; idem if I split the image according to the different channels (see : ftp://ftp.cea.fr/incoming/y2k01/Bio-Formats).

But with my java application, these images are not colorized. Here is my code :
Code: Select all
            BufferedImageReader bufferedImageReader = new BufferedImageReader(new ImageReader());
            BufferedImage bufferedImage = null;
            try {
                bufferedImageReader.setId(imagePath);
                // imageCount (number of images) = effectiveSizeC x sizeT x sizeZ
                int numberOfChannelsPerImage = bufferedImageReader.getEffectiveSizeC();
                if (numberOfChannelsPerImage > 1) {
                    for (int channelNumber = 0; channelNumber < numberOfChannelsPerImage; channelNumber++) {
                        // Index of the image corresponding to z = 0, t = 0 and c = channelNumber
                        int indexImage = bufferedImageReader.getIndex(0, channelNumber, 0);
                        // OpenImage(0) <=> open the image corresponding to the first channel, the first z and the first t
                        bufferedImage = bufferedImageReader.openImage(indexImage);
                    }
                } else {
                    bufferedImage = bufferedImageReader.openImage(0);
                }
            } catch (FormatException ex) {
                // Can not read the image
                bufferedImage = null;
            } catch (IOException ex) {
                // Can not read the image
                bufferedImage = null;
            }


Does someone has an idea ?

Thank you in advance for your help

Céline

Re: Ome.tiff file - can't display with colors

PostPosted: Tue Jun 30, 2015 10:46 am
by rleigh
Looking at these images, they have RGB PhotometricInterpretation and 4 channels (RGB with 1 associated alpha channel):

Code: Select all
% tiffinfo Image.tiff                                   
TIFF Directory at offset 0x26e8b4 (2549940)
  Image Width: 1402 Image Length: 1102
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: LZW
  Photometric Interpretation: RGB color
  Extra Samples: 1<assoc-alpha>
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 4
  Rows/Strip: 23
  Planar Configuration: single image plane
  ICC Profile: <present>, 3144 bytes
  Predictor: horizontal differencing 2 (0x2)
% tiffinfo SplitChannels.tiff                           
TIFF Directory at offset 0x1929b8 (1649080)
  Image Width: 1763 Image Length: 1266
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: LZW
  Photometric Interpretation: RGB color
  Extra Samples: 1<assoc-alpha>
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 4
  Rows/Strip: 18
  Planar Configuration: single image plane
  ICC Profile: <present>, 3144 bytes
  Predictor: horizontal differencing 2 (0x2)


Code: Select all
% ~/code/bioformats-test/tools/showinf -nopix Image.tiff       
Checking file format [Tagged Image File Format]
Initializing reader
TiffDelegateReader initializing Image.tiff
Reading IFDs
Populating metadata
Checking comment style
Populating OME metadata
Initialization took 0.077s

Reading core metadata
filename = Image.tiff
Series count = 1
Series #0 :
        Image count = 1
        RGB = true (4)
        Interleaved = false
        Indexed = false (false color)
        Width = 1402
        Height = 1102
        SizeZ = 1
        SizeT = 1
        SizeC = 4 (effectively 1)
        Thumbnail size = 128 x 100
        Endianness = motorola (big)
        Dimension order = XYCZT (certain)
        Pixel type = uint8
        Valid bits per pixel = 8
        Metadata complete = true
        Thumbnail series = false
        -----
        Plane #0 <=> Z 0, C 0, T 0


Reading global metadata
BitsPerSample: 8
Compression: LZW
ExtraSamples: 1
ImageLength: 1102
ImageWidth: 1402
MetaDataPhotometricInterpretation: RGB
MetaMorph: no
NumberOfChannels: 4
Orientation: 1st row - top; 1st column - left
PhotometricInterpretation: RGB
PlanarConfiguration: Chunky
Predictor: Horizontal differencing
SampleFormat: unsigned integer
SamplesPerPixel: 4

% ~/code/bioformats-test/tools/showinf -nopix SplitChannels.tiff
Checking file format [Tagged Image File Format]
Initializing reader
TiffDelegateReader initializing SplitChannels.tiff
Reading IFDs
Populating metadata
Checking comment style
Populating OME metadata
Initialization took 0.057s

Reading core metadata
filename = SplitChannels.tiff
Series count = 1
Series #0 :
        Image count = 1
        RGB = true (4)
        Interleaved = false
        Indexed = false (false color)
        Width = 1763
        Height = 1266
        SizeZ = 1
        SizeT = 1
        SizeC = 4 (effectively 1)
        Thumbnail size = 128 x 91
        Endianness = motorola (big)
        Dimension order = XYCZT (certain)
        Pixel type = uint8
        Valid bits per pixel = 8
        Metadata complete = true
        Thumbnail series = false
        -----
        Plane #0 <=> Z 0, C 0, T 0


Reading global metadata
BitsPerSample: 8
Compression: LZW
ExtraSamples: 1
ImageLength: 1266
ImageWidth: 1763
MetaDataPhotometricInterpretation: RGB
MetaMorph: no
NumberOfChannels: 4
Orientation: 1st row - top; 1st column - left
PhotometricInterpretation: RGB
PlanarConfiguration: Chunky
Predictor: Horizontal differencing
SampleFormat: unsigned integer
SamplesPerPixel: 4


In terms of the Bio-Formats API, these aren't independent channels (getEffectiveSizeC()), they are RGB subchannels (getRGBChannelCount()). How you choose to interpret and display this data is up to you.

Looking at your code, you're using a BufferedImage for displaying the data. I'm not totally familiar with this component, but one thing is clear: your data is not simple RGB or RGBA data from what I can tell. The 4th subchannel is not alpha; it's a fourth subchannel. I think you might need to look at customising ColorModel (http://docs.oracle.com/javase/7/docs/ap ... Model.html) for your BufferedImage to combine the four subchannels as you see fit i.e. to combine the colours for all four channels to give you a single pixel value. i.e. decide what the colours should be for C1-C4, and then set R=r1+r2+r3+r4, G=g1+g2+g3+g4 and B=b1+b2+b3+b4 (for example).

I hope that's some help. I can't see any problems with either your image data or how bioformats is interpreting and handling the data; it looks like it's down to how you want to visualise the data.

Kind regards,
Roger Leigh

Re: Ome.tiff file - can't display with colors

PostPosted: Tue Jun 30, 2015 2:00 pm
by Charavay
Roger,

Thank you for your help.

Best regards

Céline