- 2006.03.31 13:47 "Re: [Tiff] 16-bit TIFF to 8-bit BMP/TIF ???", by Edward Lam
- 2006.03.31 16:05 "RE: [Tiff] 16-bit TIFF to 8-bit BMP/TIF ???", by
2006.03.31 16:05 "RE: [Tiff] 16-bit TIFF to 8-bit BMP/TIF ???", by
> -----Original Message-----
> From: tiff-bounces@lists.maptools.org
> [mailto:tiff-bounces@lists.maptools.org]On Behalf Of Chris L.
I am in the process of writing a program using openCV that analyses 8 bit images. The problem I have is that images produced from a fluorescent camera are 16 bit unsigned greyscale TIFF images (industry standard).
The way I would like to do this is to get every pixels intensity value (16 bit) and Square root it to bring it into the range between 0 and 255.
It sounds like you'll want to do something like this:
- open original TIFF
- create new TIFF as 8-bit greyscale
- begin loop
- -- read one scanline worth from original (see TIFFReadEncodedStrip)
- -- normalize the scanline (run through each pair of octets, treating them as a 16-bit word, do your sqrt(), and store in another buffer) -- write one scanline to new file (see TIFFWriteEncodedStrip)
- end loop when all scanlines have been processed
- close new file
- close original file
You'll probably want to set these tags, at least, before writing your data:
TIFFTAG_PHOTOMETRIC
TIFFTAG_IMAGEWIDTH
TIFFTAG_IMAGELENGTH
TIFFTAG_SAMPLESPERPIXEL (probably 1)
TIFFTAG_BITSPERSAMPLE (probably 8)
TIFFTAG_ORIENTATION (ORIENTATION_TOPLEFT)
TIFFTAG_PLANARCONFIG (probably PLANARCONFIG_CONTIG)
TIFFTAG_ROWSPERSTRIP
TIFFTAG_COMPRESSION
Note, you don't have to write your directory stuff explicitly; it will be done automagically (at least for me, it worked out that way).