On 11-01-05 04:09 PM, Michael Buchoff wrote:
We are trying to convert a 16-bit img into an 8-bit tif. Unfortunately, the
colors appear VERY dark (not downconverted, but just plain dark). I suspect
that this has something to do with the histogram. The gdalinfo of the original
image can be found here <http://pastebin.com/cmVxRJyE>.

When I tell GDAL to convert straight from 16-bit to 8-bit with:

gdal_translate -ot Byte -of GTiff 28jan09_worldview_tucumcari_nm.img output.tif

I get what looks like the original image with clouds covering it… almost solid
white. (See the gdalinfo here <http://pastebin.com/ike52mMp>)

Michael,

Note that the above gdal_translate is just truncating all values
above 255 to 255 so it is not surprising that you got bad results.

When I scale around 16-bits:

gdal_translate -ot Byte -of GTiff *-scale 0 65535 0 255*
28jan09_worldview_tucumcari_nm.img output.tif

I get a solid black image. (See the gdalinfo here 
<http://pastebin.com/XpJL6AQY>)

Not surprising given that the data is all in the range
117 to 2047.

When I scale around the extents specified by the histogram:

gdal_translate -ot Byte -of GTiff *-scale 117 2047* 0 255
28jan09_worldview_tucumcari_nm.img output.tif

I get the dark image described above. (See the gdalinfo here
<http://pastebin.com/Ju4azd47>)

I suspect if we can get GDAL to process and remove the histogram, we will not
have these issues. Any help in doing this or further diagnosing the issue would
be greatly appreciated.

I don't believe the histogram is coming into it.  gdal_translate always
does a linear scaling.  I think you need to either fool around with the
scaling range to get a more pleasing result or consider moving to a
non-linear scaling - perhaps a histogram equalization stretch.  For
a non-linear scaling you will need to consider another tool than
gdal_translate.  I produced a histogram equalization and downscaler
from 16bit to 8bit as "gdal/apps/gdalenhance.cpp" but I didn't really
finish to a broadly useful level.  Nevertheless you might find it
of some use, or a good starting point if you want to write something
yourself.

Of course, other software like GRASS, and OSSIM no doubt have
non-linear scaling options available for your use case.  The
world is bigger than GDAL.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmer...@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to