Writing signed TIFF files using libTIFF

Mar 3, 2010 at 11:18am
Hello everyone!

I am having a problem using the libTIFF library, maybe some can help me with that.

In my program I read in a bunch of data and do some mathematical stuff with it. I end up with that:
 
int16_t dataArray[rows*columns] = ...
with rows = columns = 1024

After a few corrections of the data the smallest value of dataArray is something about -1500, the maximum value about ~10000. Is it possible to save that data as an TIFF image using the libTIFF library (16bit, grayscale)?

I tried it in the following way, but the problem is, that after reading the images with an image-manipulation program (e.g. imageJ), all the negative values are set to ~65500.

What I did was:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
TIFF *tif = TIFFOpen("Image.tif","w");
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, rows);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, columns);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_SEPARATE);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(tif, TIFFTAG_XRESOLUTION, imageXres);
TIFFSetField(tif, TIFFTAG_YRESOLUTION, imageYres);
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, res_unit);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, 0);
for (i = 0; i < rows; i++){
  TIFFWriteScanline(tif, &dataArray[i * columns], i, 0);
}
TIFFClose(tif);


Have you got any suggestions?

Of course I googled for a while but all I found was that TIFF can
- handle gray scale images
- handle 16 bit color depth per pixel
but what about the "-"? The Adobe TIFF 6.0 specification is a bit confusing...

As far as I know other programming languages like IDL allow writing tiff files with negative values. How to implement that in Cpp?

Thanks a lot!
Mar 3, 2010 at 1:50pm
Have you considered normalizing the data so that all the values are >= 0? I think that there are tags you can use to store custom information such as whatever value was used to normalize the data.
Mar 3, 2010 at 2:19pm

Have you considered normalizing the data
Normalizing the data is my current workaround... I seek the lowest value and add it as an "offset" to the data. That works well, but that is not the way I want the data stored.

I am wondering, why libtiff accept negative values if only positive once are displayed correctly.
Topic archived. No new replies allowed.