0

I'm working on a code that needs to read a 4-channel geotiff image, in this case a 16-bit image (data is actually 12-bit resolution, but is encoded in 16-bit).

My main objective is to read pixel values to use them later. From this question "How 16bits-RGBA image pixels are interlaced?" I tried to use TIFFReadEncodedStrip instead of TIFFRGBAImage like this:

buf = (unsigned char*)(_TIFFmalloc(TIFFStripSize(tif)));
TIFFReadEncodedStrip(tif,strip,buf,(tsize_t)-1);
uint32 *p0 = buf;
printf("strip %d = %d \n", strip, *p0);

and for the p0 value that I print, which is supposed to be the actual image data, I got this:

strip 0 = 20382000

Checking the tags in my image I have found:

Rows per strip: 1  
Samples per pixel: 4  
Bits per sample: 16 
Image orientation: 1 (bottom left)  
Size of buffer: 8 bytes

So my assumption is that the p0 value I'm getting from the buffer, are the four first pixels in the top left corner in the first channel of the image. What I don't understand is how do I have to interpret the values of the p0 strip I got.

Opening the image in matlab and checking the first pixel (top-left) in each channel I got 304, 311, 314 and 314, which doesn't seem to be anything on the p0 value I'm getting.

I don't know if it's because of the 12-bit resolution, or if I have to convert it to a type other than uint32, but I just can't make sense of that number.

Can somebody help to decipher this number and if it corresponds to the first four pixels in the bottom left corner?

1 Answers1

0

I got access to the actual pixel values in the image using this code:

TIFFReadEncodedStrip(tif,strip,buf, (tsize_t) -1);  
uint16_t *p16;
p16 = (uint16_t *) buf;
printf("Strip: %d\n", strip);
int i = 0;
for (i; i < 64; i++) {      // the strip buffer is *length* elements long
    printf("%d: %u\n", i+1, p16[i]);
}

The key was casting the buffer to uint16_t*. This shows the pixel values as something understandable for humans.