AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
September 2009

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2009.09.10 13:31 "Manually convert 16-bit grayscale image data to 8-bit grayscale in Borland c++", by Robert Zermeno
2009.09.10 13:51 "Re: Manually convert 16-bit grayscale image data to 8-bit grayscale in Borland c++", by Evgenia Gurova
2009.09.10 15:52 "Re: Manually convert 16-bit grayscale image data to 8-bit grayscale in Borland c++", by Bob Friesenhahn
2009.09.11 00:21 "Re: Manually convert 16-bit grayscale image data to 8-bit grayscale in Borland c++", by Robert Zermeno

2009.09.11 00:21 "Re: Manually convert 16-bit grayscale image data to 8-bit grayscale in Borland c++", by Robert Zermeno

>It could be a particularly dark or bright day. Due to this, software which
>deals with such >images often reads the data twice.  The first read is used
>to estimate the scaling >parameters to be applied during the second read. 
>User interaction may be necessary to >fine-tune the results
 
Can you elaborate a little more on the idea behind 2 reads ("used to
estimate the scaling parameters?")
I have to provide my own tiff reader/writer because the type of handheld
device the software will be placed on cannot use libtiff.  For some reason,
it cannot compile and work on the handheld (as claimed by my team lead). 
So, I am forced to re-invent the wheel, but with a different purpose.
 
I have all the different types of tiff images my firm will deal with written
out to read them except for 16-bit grayscale images.  I am aware of
Little/Big endian byte ordering and I account for this as well.


--- On Thu, 9/10/09, Bob Friesenhahn <bfriesen@simple.dallas.tx.us> wrote:


From: Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
Subject: Re: [Tiff] Manually convert 16-bit grayscale image data to 8-bit
grayscale in Borland c++
To: "Robert Zermeno" <refriguy68@yahoo.com>
Cc: tiff@lists.maptools.org
Date: Thursday, September 10, 2009, 8:52 AM


On Thu, 10 Sep 2009, Robert Zermeno wrote:

> How on earth may I be able to convert my 16-bit grayscale image data to
> 8-bit?  I have been able to take 2 bytes to a short value, then truncate
> it to a single byte like so:  

>  unsigned short value16 = *TmpBits++;
>                        value16 = value16 + (*TmpBits++ << 8)

Be sure to consider endian order since TIFF can be big or little endian.

> When I dislpay my data in Borland through a TImage object, I will recieve
> my image (meaning, you can make out my object I am looking at, but the
> gray values for each pixel is way off.  Sometimes too much white and some
> pixels are correct for black)  but the gray coloration is way off.  I have
> to do this because in Borland, to

Someone else here mentioned ImageMagick, but I will instead (naturally!)
suggest installing a "Q16" build of GraphicsMagick from
http://www.GraphicsMagick.org/ and you can use that to see if the results
look the same as with your Borland results.  If results look similar, then
add the -normalize option when converting the file and see if there is now a
recognizable image.

It is important to realize that Geotiff data may use the full range and
resolution of the 16 bits.  A simple conversion to 8 bit would loose all of
the data if it happened to only use the range of 0 to 255. Some sensors may
only produce a range of 0-4095 but the values are still stored in 16-bits. 
It could be a particularly dark or bright day. Due to this, software which
deals with such images often reads the data twice.  The first read is used
to estimate the scaling parameters to be applied during the second read. 
User interaction may be necessary to fine-tune the results.

Bob
--
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/