theThe most easy way to do this in a script is to use the subprocesssubprocess
module and gdal_translategdal_translate
import subprocess
image_in = "path_input_image"
image_out = "path_output_image.tif"
subprocess.call(["gdal_translate.exe","-co", "TILED=YES", "-co", "COMPRESS=LZW" "-ot", "Byte", "-scale", image_in, image_out ])
iff you are in Linux, you don't need the ".exe" after gdal_translategdal_translate
, and if gdal is not installed, you might need to provide the full path to the application
alternatively, this can be done with OTBApplication
#!/usr/bin/python
# Import the otb applications package
import otbApplication
image_in = "path_input_image"
image_out = "path_output_image.tif"
# The following line creates an instance of the Rescale application
Rescale = otbApplication.Registry.CreateApplication("Rescale")
# The following lines set all the application parameters:
Rescale.SetParameterString("in",image_in )
Rescale.SetParameterString("out",image_out )
Rescale.SetParameterOutputImagePixelType("out", ImagePixelType_uint8)
Rescale.SetParameterFloat("outmin", 0)
Rescale.SetParameterFloat("outmax", 255)
# The following line execute the application
Rescale.ExecuteAndWriteOutput()