Read and interpret 16 bit strip data with geo tiff

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Read and interpret 16 bit strip data with geo tiff

fbrubeck
Hi everyone,

I am new to geotiff and C programming, and I´m having a hard time with both of them.

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. 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 I suppose 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)  
Planar configuration: 2
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 bottom 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 four pixels (bottom-left) in each channel I got 291, 428, 444 and 1473, 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 please give me some pointers on how to handle the image data to store it and manipulate it, and to decipher this number and if it corresponds to the first four pixels in the bottom left corner?


Best wishes,

Felipe.


_______________________________________________
Tiff mailing list: [hidden email]
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read and interpret 16 bit strip data with geo tiff

Bob Friesenhahn
On Fri, 9 Jun 2017, Felipe Brubeck wrote:

>
> Opening the image in matlab and checking the first four pixels
> (bottom-left) in each channel I got 291, 428, 444 and 1473, 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 please give me some pointers on how to handle the image data
> to store it and manipulate it, and to decipher this number and if it
> corresponds to the first four pixels in the bottom left corner?

The data will be 16-bit sample values in native byte order in RGB
order which means that it will depend on the type of CPU you are
using.

One way to access the data is to cast it (the unsigned char *) to a
'uint16_t *' and then access it as an array of 16-bit values.

   uint16_t * p16;

   p16 = (uint16_t *) buff;

   printf("%u\n", p16[0] >> 4);
   printf("%u\n", p16[1] >> 4);
   printf("%u\n", p16[2] >> 4);

Bob
--
Bob Friesenhahn
[hidden email], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
_______________________________________________
Tiff mailing list: [hidden email]
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read and interpret 16 bit strip data with geo tiff

fbrubeck
Hi Bob,

I appreciate your help. I tried your approach, but when I print it, it shows "19" for the four values of p16[x].
For what I have read, this data might be an address, an index or the pixel value, but still I don't know how to make sense of it.
I will appreciate if somebody can help me with this.
If it helps, it's SPOT 6 data.

Best wishes,
Felipe.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read and interpret 16 bit strip data with geo tiff

Bob Friesenhahn
On Fri, 9 Jun 2017, fbrubeck wrote:

> Hi Bob,
>
> I appreciate your help. I tried your approach, but when I print it, it shows
> "19" for the four values of p16[x].
> For what I have read, this data might be an address, an index or the pixel
> value, but still I don't know how to make sense of it.
> I will appreciate if somebody can help me with this.
> If it helps, it's SPOT 6 data.

Try using

    printf("%u\n", p16[0] );
    printf("%u\n", p16[1] );
    printf("%u\n", p16[2] );

instead.  This would print the original stored values.

If the image is quite dark, then the values may be small.

Bob
--
Bob Friesenhahn
[hidden email], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
_______________________________________________
Tiff mailing list: [hidden email]
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
Loading...