[gdal-dev] Extracting an 8bit raster image from a 16bit unsigned int HDF dataset

Frank Warmerdam warmerdam at pobox.com
Fri Feb 15 12:08:53 EST 2008


mattia wrote:
> HEllo,
> 
> I try the following:
> 
>  gdal_translate -ot Byte -b 1 -b 2 -b 3 
> HDF4_SDS:UNKNOWN:"AMOD021KM20070104035343.hdf":0 123.tif
> 
> where the subdataset is an SDS formed of 15 visible bands where each 
> pixel is a 16 bit unsigned integer..
> My output tiff image is a blank white one .. can anyone tell me where 
> the problem could be??
> 
> Is there a way of converting such 16bit images to 8 bit ones without loss??

Mattia,

Generally speaking you cannot convert 16bit to 8bit without loss.  Do you know
the data range of the data?  The simplest approach is to use GDAL autoscalling
to rescale the data to 8bit but that may not give the best visual results.

eg.

  gdal_translate -ot Byte -scale -b 1 -b 2 -b 3
     HDF4_SDS:UNKNOWN:"AMOD021KM20070104035343.hdf":0 123.tif

You can read about the -scale switch in the gdal_translate docs.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the gdal-dev mailing list