Problem reading RGB tiff

(This topic gas been transferred from the mailing list, at Brad’s suggestion)
I’ve been encountering strange results when reading a big 2D RGB tiff that was generated by running tiffsplit on a huge 3D LSM file (from a Zeiss microscope). tiffsplit also extracts the thumbnails for each slice. The LSM file is 50 GB, one 2D slice is 127 MB. tiffinfo gives this output:

TIFF Directory at offset 0x7c0b608 (130070024)
Subfile Type: (0 = 0x0)
Image Width: 4656 Image Length: 4656
Bits/Sample: 16
Compression Scheme: None
Photometric Interpretation: RGB color
Samples/Pixel: 3
Planar Configuration: separate image planes

I can view a 2D slice file with ImageJ, and the three channels all make sense.
I have code to open the slice image in two ways, ReadRGB reads it as Image and ReadVectorImage reads it as VectorImage.

ReadRGB gives the max R,G,B values as 16 16 16
ReadVectorImage says NumberOfComponentsPerPixel=4, and max RGB = 16 0 0
I’m not sure what is the correct way to read this file, or if either of my programs is error-free.

ReadRGB.cxx (2.6 KB)

ReadVectorImage.cxx (1.7 KB)

I’m happy to provide the 127 MB tiff file, if requested. What is the best mode?

Thanks, Gib

1 Like

Hi Gib,

Welcome to ITK’s Discourse community :-).

Since the NumberOfComponentsPerPixel == 4, itk::RGBAPixel instead of itk::RGBPixel is likely required.

Hope this helps,

Hi Matt,

Changing the PixelType to RGBAPixel gives the sames results as before with both programs.

Cheers, Gib

The file size is consistent with 3 channels of 16-bits, i.e. 48 bits per pixel. Irfanview says that there are 48 bits per pixel, but the display is all black.

Imagemagick’s convert can extract three tiffs, each 16 bpp and 1/3 of the size of the original file, with:

convert xaas.tif -channel RGB -separate out%d.tif


convert xaas.tif -channel RGBA -separate out%d.tif

gives the same three tiffs + a much smaller one, 2 bpp, all pixels 0.

After some peculiar install problems, I was able to build and install ITK 4.12.2. The effort was a waste of time, though, because the my two test programs still generate wrong results when reading my test RGB tiff. I’m willing to delve into the code (in my amateurish way), but I’d appreciate advice about where to look.

Does the problem also occur with 127MB slice, or only with the full 3D image? If so, share it and I could try to use your example programs and debug it.

Hi Gib,

One option is to share the image on Once you register for an account there, it has a limited amount of upload space associated with the account.


No, I don’t try to do anything with the 50 GB LSM file, I don’t have access to any machine that can load such a big file (even if the software understands LSM). I split the LSM file into 396 tiffs with tiffsplit, xaas.tif is one of the 127 MB tiff files. (By the way, I meant I could delve into the ITK library code, under the assumption that my code is OK - possibly a bad assumption.)

I am attaching it to this post, compressed as xaas.rar.

And thanks!

I don’t see the file that I uploaded. Could it be too big? It’s 57 MB. I see that Matt has just told me I can use I’ll do that now.

Yes, there is a limit on Discourse file upload size.

Matt, I’ve registered on, and created a collection (that seems to be the way to store data there), but how do I upload to it?

OK, I see that I needed to create a folder. xaas.rar is being uploaded to the collection called
RGB tiff test data

The file xaas.rar is now on the Kitware data site, in the collection “RGB tiff test data”.

Three of my posts above have been hidden. I got three emails like this:

This is an automated message from ITK to let you know that your post was hidden.
(URL of the post)
Your post was flagged as spam: the community feels it is an advertisement, something that is overly promotional in nature instead of being useful or relevant to the topic as expected.

Multiple community members flagged this post before it was hidden, so please consider how you might revise your post to reflect their feedback. You can edit your post after 10 minutes, and it will be automatically unhidden.

However, if the post is hidden by the community a second time, it will remain hidden until handled by staff.

Would one of the community members who flagged my post as spam please explain why.

1 Like

Hi Matt,

My posts to the ITK discourse site are being hidden, and I’m getting email messages saying they have been flagged by multiple members as spam. WTF?

Cheers, Gib

Hi @Gib,

Sorry for the confusing message.

The Discourse system user was automatically flagging the post because it contained multiple links to the same domain. I changed this setting so it does not flag the unless there are 10 or more links instead of the default of just 3. I also improved the Post Hidden email message you received to indicate that it could come from the system instead of community members, and to reach out if there was an error.

Sorry again for the confusion. Thanks for letting me know there was an issue.


1 Like

?Thanks for the clarification, Matt.

@Gib your collection is most likely private, as I can’t see it. Could you make it public, or put the file in your public collection?

?Sorry, Dzenan, I didn’t know there was a private/public distinction. There is no help info on that site. The file I uploaded doesn’t seem to be there at all now, anyway. I have uploaded it again to my public collection.

Thanks for your help

Although I uploaded to my public collection, I just checked and found that I still needed to set the file access to public (which I have now done). I don’t understand what a public collection is, if you still have to set the access.


Sorry to come in late.
There does appear to be a problem with the tiff reader - for some reason the component type gets set to unsigned_char - see the bottom of this dump:

ImageFileReader (0x2140d10)
RTTI typeinfo: itk::ImageFileReader<itk::Image<itk::RGBPixel, 2u>, itk::DefaultConvertPixelTraits<itk::RGBPixel > >
Reference Count: 2
Modified Time: 56
Debug: Off
Object Name:
FileName: (0x2147a40)
Primary: (0)
Indexed Inputs:
0: Primary (0)
No Required Input Names
NumberOfRequiredInputs: 0
Primary: (0x21476a0)
Indexed Outputs:
0: Primary (0x21476a0)
NumberOfRequiredOutputs: 1
Number Of Threads: 8
ReleaseDataFlag: Off
ReleaseDataBeforeUpdateFlag: Off
AbortGenerateData: Off
Progress: 1
RTTI typeinfo: itk::MultiThreader
Reference Count: 1
Modified Time: 40
Debug: Off
Object Name:
Thread Count: 8
Global Maximum Number Of Threads: 128
Global Default Number Of Threads: 8
TIFFImageIO (0x214cf20)
RTTI typeinfo: itk::TIFFImageIO
Reference Count: 1
Modified Time: 204
Debug: Off
Object Name:
AbortGenerateData: Off
Progress: 0
FileName: xaas.tif
FileType: TypeNotApplicable
ByteOrder: OrderNotApplicable
ImageIORegion (0x214cfb8)
Dimension: 2
Index: 0 0
Size: 4656 4656
Number of Components/Pixel: 4
Pixel Type: rgba
Component Type: unsigned_char
Dimensions: ( 4656 4656 )
Origin: ( 0 0 )
UseCompression: Off
UseStreamedReading: On
UseStreamedWriting: Off
ExpandRGBPalette: On
IsReadAsScalarPlusPalette: False
Compression: 1
JPEGQuality: 75
UserSpecifiedImageIO flag: 0
m_UseStreaming: 1

How did you generate this dump, Richard?
Do you have an idea about where this error is likely to be occurring? I’m willing to look at the code, if nobody with more expertise volunteers to do it.


I think I’ve tracked it down. This image has separate colour planes :


The CanRead method checks for PLANARCONFIG_CONTIG, and is thus returning a failed state, leading to all sorts of problems setting up pixel types etc. The original setting of unsigned short pixels gets set back to unsigned char, and the number of components is set to 4. The idea is to use TIFFReadRGBAImageOriented, but it is only set up to use UCHAR pixels

Not sure if there’s an easy way around this.

1 Like