1

I am trying to convert my uint8 png image to float datatype. First of all, I have tried many libraries that could transform datatypes but I just could not export it as the last datatype I converted for some reason. How can I keep the last datatype while exporting the image to my PC?

In Google Earth Engine, there is this function of image.float(). I could convert my image to float with that function however, when I check the image in QGIS, it is still uint8. Am I missing something?

1 Answer 1

2

There should be no problem if you convert the image into some format that supports float datatype. TIFF is such a format while png is not. As a proof of concept how it goes with gdal_translate.

Source image is of type "Byte", so Uint8:

Band 1 Block=4592x1 Type=Byte, ColorInterp=Red
Band 2 Block=4592x1 Type=Byte, ColorInterp=Green
Band 3 Block=4592x1 Type=Byte, ColorInterp=Blue

Convert into Float32 tiff

gdal_translate -of GTiff -ot Float32 input.png output.tif

Check the result with gdalinfo

gdalinfo output.tif
...
Band 1 Block=4592x1 Type=Float32, ColorInterp=Red
Band 2 Block=4592x1 Type=Float32, ColorInterp=Green
Band 3 Block=4592x1 Type=Float32, ColorInterp=Blue
1
  • Thanks for the clarification. I appreciate that. Commented Jun 4, 2023 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.