[gdal-dev] How gdal_translate scale the value, like from a larger range to a smaller range?

Laurențiu Nicola lnicola at dend.ro
Tue Dec 3 19:41:45 PST 2024


Hi Lucas,

GDAL will keep the input values unchanged when possible, and saturate (use the maximum or minimum representable value) when not. So 10050 will be transformed to 255 when you're converting to Byte, and -40000 will be saved as -32768 for Int16. NaN nodata values will be converted to 0 with a warning.

You might want to check out the -scale and -exponent parameters of gdal_translate.

Laurentiu

On Wed, Dec 4, 2024, at 04:46, shark shark via gdal-dev wrote:
> Hi guys. Have a nice day.
>  
> I’m curious how gdal scales the values when converting from a larger range to a smaller range,like from u32 to u8, u16 to u8, f32 to u8 etc..
> I made a test:
> gdal_translate -ot Byte -of GTiff  gray_u32.tif gray_u8.tif
> All the u32 value in every sample of my gray_u32.tif is 10050
> And All the value in result file is 255.
> This seems to be a boundary case where the maximum and minimum values are both 10050 but I’m curious the behavior here and I didn’t find a doc about this.
>  
> I hope this question is not too suptid or weired.
>  
> Best, Lucas
>  
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20241204/5e701f44/attachment.htm>


More information about the gdal-dev mailing list