<!DOCTYPE html><html><head><title></title><style type="text/css">#qt p.qt-MsoNormal{margin-top:0cm;margin-right:0cm;margin-left:0cm;margin-bottom:0.0001pt;text-align:justify;font-size:10.5pt;font-family:DengXian;}
#qt a:link{color:blue;text-decoration-color:currentcolor;text-decoration-line:underline;text-decoration-style:solid;text-decoration-thickness:auto;}
#qt a:visited{color:rgb(149, 79, 114);text-decoration-color:currentcolor;text-decoration-line:underline;text-decoration-style:solid;text-decoration-thickness:auto;}
p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div style="font-family:Arial;">Hi Lucas,<br></div><div style="font-family:Arial;"><br></div><div style="font-family:Arial;">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.<br></div><div style="font-family:Arial;"><br></div><div style="font-family:Arial;">You might want to check out the -scale and -exponent parameters of gdal_translate.<br></div><div style="font-family:Arial;"><br></div><div style="font-family:Arial;">Laurentiu<br></div><div style="font-family:Arial;"><br></div><div>On Wed, Dec 4, 2024, at 04:46, shark shark via gdal-dev wrote:<br></div><blockquote type="cite" id="qt" style=""><div class="qt-WordSection1"><p class="qt-MsoNormal"><span lang="EN-US">Hi guys. Have a nice day.</span><br></p><p class="qt-MsoNormal"><span lang="EN-US"> </span><br></p><p class="qt-MsoNormal"><span lang="EN-US">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..</span><br></p><p class="qt-MsoNormal"><span lang="EN-US">I made a test:</span><br></p><p class="qt-MsoNormal" style="text-indent:21pt;"><span lang="EN-US">gdal_translate -ot Byte -of GTiff gray_u32.tif gray_u8.tif</span><br></p><p class="qt-MsoNormal"><span lang="EN-US">All the u32 value in every sample of my gray_u32.tif is 10050</span><br></p><p class="qt-MsoNormal"><span lang="EN-US">And All the value in result file is 255.</span><br></p><p class="qt-MsoNormal"><span lang="EN-US">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.</span><br></p><p class="qt-MsoNormal"><span lang="EN-US"> </span><br></p><p class="qt-MsoNormal"><span lang="EN-US">I hope this question is not too suptid or weired.</span><br></p><p class="qt-MsoNormal"><span lang="EN-US"> </span><br></p><p class="qt-MsoNormal"><span lang="EN-US">Best, Lucas</span><br></p><p class="qt-MsoNormal"><span class="font" style="font-family:SimSun;"><span class="size" style="font-size:12pt;"> </span></span><br></p></div><div>_______________________________________________<br></div><div>gdal-dev mailing list<br></div><div><a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br></div><div><a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br></div><div><br></div></blockquote><div style="font-family:Arial;"><br></div></body></html>