2003.11.21 18:57 "[Tiff] Trouble reading color tiff image files", by Rutger T.

2003.11.21 19:36 "[Tiff] Trouble reading color tiff image files", by Frank Warmerdam

I am new to the list. I am very interested in using tiff files with some code that I am writing and am naturally using libtiff to do that. Unfortunately, I am having some trouble reading color tiff files. Therefore, as there was not much information regarding my particular problem on the web I hope that you (the experts) may help me. The solution is most likely very trivial for you guys. :)

While I have had no problems reading gray scale tiff files I have had some mixed success with reading color tiff images properly. Therefore, I went back to square one and am currently simlply trying to have my code output the RGB samples of the correctly read color image (which filename is "input.tif") to the screen. (I'm intentionally not printing all image pixels to the screen at the moment.) However, what my code currently does is output partially correct results. It seems to display the first few (~10) samples fine to the screen, but then starts skipping samples. Once I know that everything is read correctly into memory things should be golden.

Since I am not really sure where in my code I am messing up I have provided the entire "barebones code" of what I described above here (it's not long, but I thought the linked page would hold formatting better than pasting it into an email):


And here is a link to the image ("input.tif") that I am testing with:


So, at this point, all I am trying to do is read in the color image correctly and output the first several RGB samples (to verify) to the screen.

Do you guys have any ideas what may be causing my problems? What may be wrong with my code? Is it because of improper use of headers?

Since I'm stumped and have tried many things already, *any* suggestions/pointers would be greatly appreciated.


A tiffinfo reports:

TIFF Directory at offset 0x106
   Subfile Type: (0 = 0x0)
   Image Width: 8 Image Length: 8
   Resolution: 72, 72 pixels/inch
   Bits/Sample: 8
   Compression Scheme: None
   Photometric Interpretation: RGB color
   Date & Time: "2003:11:14 15:51:36"
   Samples/Pixel: 3
   Rows/Strip: 8
   Planar Configuration: single image plane
   Software: Adobe Photoshop 7.0

The key item here is "planar configuration = single image plane". That means the data is pixel interleaved (packed as RGBRGBRGB...)

You read a line like this:

        check_io = TIFFReadScanline(in_filep, &in_image[r*columns], r, 2);

But it doesn't really make sense to use a "sample" value of 2 in this case as for images in this configuration all the samples come together and you should be passing "0".

After doing a single TIFFReadScanline() you will have a buffer with 3 bytes per pixel, and the values are packed RGBRGB...

One big annoyance with libtiff is the extent to which the application needs to understand the different TIFF modes (color model, planar configuration, tiling/stripping, etc) in order to get a coherent image from the file. For some applications you would be better off working with a higher level image read/write library that provides a simpler abstraction (but perhaps uses libtiff underneath).

Good luck,

I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent