[gdal-dev] how to convert UInt16 Tiff

Even Rouault even.rouault at mines-paris.org
Tue Apr 24 05:05:50 EDT 2012


Selon jr.morreale at enoreth.net:

> On Tue, 24 Apr 2012 09:38:44 +0200, Even Rouault wrote:
> >>
> >> thanks for the reply, I did try with NBITS=8 and 12 with osgeo4w's
> >> gdal
> >> and tamas' nightly build but the output results are incorrect
> >>
> >> Here is a sample file (93Mo) :
> >> http://dl.free.fr/iFT4hH3Yj
> >>
> >> I'll try to rebuild gdal on my linux box with the internal libs
> >
> > I haven't looked at your result image, but you cannot just specify
> > NBITS=8 or
> > 12, if the range of the values in the original file is full 16 bits.
> >
> > You need to rescale the values, otherwise they will get clamped to
> > [0, 255] or
> > [0, 4096].
> >
> > So you can look for the min/max reported by gdalinfo -mm
> > uncompressed_original.tif
> >
> > and then try :
> >
> > gdal_translate -co "COMPRESS=JPEG" uncompressed_original.tif
> > compressed.tif
> > -scale min max 0 255 -ot Byte
> >
> > or
> >
> > gdal_translate -co "COMPRESS=JPEG" uncompressed_original.tif
> > compressed.tif
> > -scale min max 0 4095 -co NBITS=12
>
> Thanks, I didn't knew that !
>
> The man says that you can omit the input min max scale so gdal computes
> it for each source, however I can't find how to write that correctly

Actually, the manual says :

-scale [src_min src_max [dst_min dst_max]]:
    Rescale the input pixels values from the range src_min to src_max to the
range dst_min to dst_max. If omitted the output range is 0 to 255. If omitted
the input range is automatically computed from the source data.

In other words, you can use it in 3 ways :
* -scale : in which case src_min and src_max are automatically computed from the
source data.  And dst_min and dst_max will be set to 0 and 255
* -scale src_min src_max : the user specified values for src_min and src_max are
used, and dst_min and dst_max will be set to 0 and 255
* -scale src_min src_max dst_min dst_max : all user specified values are used

There's no syntax to just specify dst_min and dst_max and let src_min and
src_max be computed.

In the case where you want to convert to 8 bits /byte, you could actually just
do : gdal_translate -co "COMPRESS=JPEG" uncompressed_original.tif compressed.tif
-ot Byte -scale

For the 12 bits case, you must specify the whole set of values for -scale.

>




More information about the gdal-dev mailing list