# Problem reading RGB tiff

**URL:** https://discourse.itk.org/t/problem-reading-rgb-tiff/514
**Category:** Uncategorized
**Created:** [December 14, 2017, 10:09pm UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514 "2017-12-14T22:09:01Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Gib](https://discourse.itk.org/user_avatar/discourse.itk.org/gib/32/4124_2.png) [@Gib](https://discourse.itk.org/u/Gib)
#### Post date: [December 14, 2017, 10:09pm UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/1 "2017-12-14T22:09:01Z")

</div>

(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](https://discourse.itk.org/uploads/default/original/1X/2507f1608091c6bb4465b4c3f99fb95d231bac85.cxx) (2.6 KB)

[ReadVectorImage.cxx](https://discourse.itk.org/uploads/default/original/1X/084ddd11f8ef8638b7e66a53cd89a3404847f07e.cxx) (1.7 KB)

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

Thanks, Gib

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [December 14, 2017, 11:12pm UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/2 "2017-12-14T23:12:55Z")

</div>

Hi Gib,

Welcome to ITK’s Discourse community :-).

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

Hope this helps,  
Matt

---

<div class="post-metadata">

### Author: ![Gib](https://discourse.itk.org/user_avatar/discourse.itk.org/gib/32/4124_2.png) [@Gib](https://discourse.itk.org/u/Gib)
#### Post date: [December 14, 2017, 11:33pm UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/3 "2017-12-14T23:33:30Z")

</div>

Hi Matt,

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

Cheers, Gib

---

<div class="post-metadata">

### Author: ![Gib](https://discourse.itk.org/user_avatar/discourse.itk.org/gib/32/4124_2.png) [@Gib](https://discourse.itk.org/u/Gib)
#### Post date: [December 14, 2017, 11:43pm UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/4 "2017-12-14T23:43:51Z")

</div>

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

but

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

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

---

<div class="post-metadata">

### Author: ![Gib](https://discourse.itk.org/user_avatar/discourse.itk.org/gib/32/4124_2.png) [@Gib](https://discourse.itk.org/u/Gib)
#### Post date: [December 15, 2017, 10:30pm UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/5 "2017-12-15T22:30:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 15, 2017, 11:56pm UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/6 "2017-12-15T23:56:33Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [December 16, 2017, 12:10am UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/7 "2017-12-16T00:10:37Z")

</div>

Hi Gib,

One option is to share the image on [data.kitware.com](https://data.kitware.com). Once you register for an account there, it has a limited amount of upload space associated with the account.

HTH,  
Matt

---

<div class="post-metadata">

### Author: ![Gib](https://discourse.itk.org/user_avatar/discourse.itk.org/gib/32/4124_2.png) [@Gib](https://discourse.itk.org/u/Gib)
#### Post date: [December 16, 2017, 12:12am UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/8 "2017-12-16T00:12:06Z")

</div>

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 [data.kitware.com](http://data.kitware.com). I’ll do that now.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [December 16, 2017, 12:12am UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/9 "2017-12-16T00:12:59Z")

</div>

> [@Gib](#):
>
> I don’t see the file that I uploaded. Could it be too big?

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

---

<div class="post-metadata">

### Author: ![Gib](https://discourse.itk.org/user_avatar/discourse.itk.org/gib/32/4124_2.png) [@Gib](https://discourse.itk.org/u/Gib)
#### Post date: [December 16, 2017, 12:22am UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/10 "2017-12-16T00:22:08Z")

</div>

Matt, I’ve registered on [data.kitware.com](http://data.kitware.com), 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

---

<div class="post-metadata">

### Author: ![Gib](https://discourse.itk.org/user_avatar/discourse.itk.org/gib/32/4124_2.png) [@Gib](https://discourse.itk.org/u/Gib)
#### Post date: [December 16, 2017, 12:55am UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/11 "2017-12-16T00:55:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Gib](https://discourse.itk.org/user_avatar/discourse.itk.org/gib/32/4124_2.png) [@Gib](https://discourse.itk.org/u/Gib)
#### Post date: [December 16, 2017, 12:59am UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/12 "2017-12-16T00:59:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Gib](https://discourse.itk.org/user_avatar/discourse.itk.org/gib/32/4124_2.png) [@Gib](https://discourse.itk.org/u/Gib)
#### Post date: [December 16, 2017, 1:02am UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/13 "2017-12-16T01:02:37Z")

</div>

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

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [December 16, 2017, 4:37pm UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/14 "2017-12-16T16:37:19Z")

</div>

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.

Matt

---

<div class="post-metadata">

### Author: ![Gib](https://discourse.itk.org/user_avatar/discourse.itk.org/gib/32/4124_2.png) [@Gib](https://discourse.itk.org/u/Gib)
#### Post date: [December 16, 2017, 7:21pm UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/15 "2017-12-16T19:21:57Z")

</div>

?Thanks for the clarification, Matt.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 17, 2017, 4:08pm UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/16 "2017-12-17T16:08:33Z")

</div>

@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](https://data.kitware.com/#user/5a34654b8d777f5e872f5dfc/folder/5a34654b8d777f5e872f5dfd)?

---

<div class="post-metadata">

### Author: ![Gib](https://discourse.itk.org/user_avatar/discourse.itk.org/gib/32/4124_2.png) [@Gib](https://discourse.itk.org/u/Gib)
#### Post date: [December 17, 2017, 6:56pm UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/17 "2017-12-17T18:56:11Z")

</div>

?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.

Gib

---

<div class="post-metadata">

### Author: ![richard.beare](https://discourse.itk.org/letter_avatar_proxy/v4/letter/r/ed655f/32.png) [@richard.beare](https://discourse.itk.org/u/richard.beare)
#### Post date: [December 18, 2017, 1:41am UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/18 "2017-12-18T01:41:47Z")

</div>

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:  
Observers:  
none  
Inputs:  
FileName: (0x2147a40)  
Primary: (0)  
Indexed Inputs:  
0: Primary (0)  
No Required Input Names  
NumberOfRequiredInputs: 0  
Outputs:  
Primary: (0x21476a0)  
Indexed Outputs:  
0: Primary (0x21476a0)  
NumberOfRequiredOutputs: 1  
Number Of Threads: 8  
ReleaseDataFlag: Off  
ReleaseDataBeforeUpdateFlag: Off  
AbortGenerateData: Off  
Progress: 1  
Multithreader:  
RTTI typeinfo: itk::MultiThreader  
Reference Count: 1  
Modified Time: 40  
Debug: Off  
Object Name:  
Observers:  
none  
Thread Count: 8  
Global Maximum Number Of Threads: 128  
Global Default Number Of Threads: 8  
ImageIO:  
TIFFImageIO (0x214cf20)  
RTTI typeinfo: itk::TIFFImageIO  
Reference Count: 1  
Modified Time: 204  
Debug: Off  
Object Name:  
Observers:  
none  
AbortGenerateData: Off  
Progress: 0  
FileName: xaas.tif  
FileType: TypeNotApplicable  
ByteOrder: OrderNotApplicable  
IORegion:  
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

---

<div class="post-metadata">

### Author: ![Gib](https://discourse.itk.org/user_avatar/discourse.itk.org/gib/32/4124_2.png) [@Gib](https://discourse.itk.org/u/Gib)
#### Post date: [December 18, 2017, 2:47am UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/19 "2017-12-18T02:47:52Z")

</div>

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.

Gib

---

<div class="post-metadata">

### Author: ![richard.beare](https://discourse.itk.org/letter_avatar_proxy/v4/letter/r/ed655f/32.png) [@richard.beare](https://discourse.itk.org/u/richard.beare)
#### Post date: [December 18, 2017, 2:57am UTC](https://discourse.itk.org/t/problem-reading-rgb-tiff/514/20 "2017-12-18T02:57:41Z")

</div>

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

TIFFTAG\_PLANARCONFIG = PLANARCONFIG\_SEPARATE

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.

[Next page](https://discourse.itk.org/t/problem-reading-rgb-tiff/514.md?page=2)
