AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2002.09.18 17:53 "Reading 16bits from a gray scale image", by Steven Luke
2002.09.18 18:49 "Re: Reading 16bits from a gray scale image", by Steven Luke
2002.09.18 19:05 "Re: Reading 16bits from a gray scale image", by Chris 'Xenon' Hanson
2002.09.19 00:40 "Re: Reading 16bits from a gray scale image", by Martí_Maria

2002.09.18 17:53 "Reading 16bits from a gray scale image", by Steven Luke

Hi,

I looked through the archives for the answer to this, and although the question came up a couple of times, I didn't find an answer that seemed to work (at least not for my images).

First let me start by asking the simplest question. How do I read 16bits of data from the image? If I use TIFFReadRGBAImage the raster has to be 32 bits per pixel. You can get the 8 bit color channels using the getr32 macros. How can I turn the 8bit or 32bit data into 16bits? I tried doing this:

[1]  c = raster[i];
[2]  r  = getr32(c);
[3]  g = getg32(c);
[4]  b = getb32(c);
[5]  a = geta32(c);
[6]  uint16 value = r;

[7] value <<= 8;
[8] value += g;
[9] unsigned char final = value >> 8;

What happens is only the brightest spots get shown. I tried the different color components in lines [6] and [8], and the only thing that made a difference was if r was inserted into [6] I saw the spots as above, anything else I got an empty image. Tried only shifting the pixels by 4 in line [9] since the data was actually acquired in 12 bits then stored as 16, but I got the same results.

Should I be using another method to read the data from the file? Like one that accepts a buffer such as TIFFReadScanline or TIFFReadEncodedStrip? Or should I just seek to the correct offset, fread in the data and work from there?

Thanks.

Steven J. Luke

------------------------
Kimmel Cancer Center
Bioimaging Facility
Thomas Jefferson University
Philadelphia, PA