Skip to main content

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()

the most easy way to do this in a script is to use the subprocess module and gdal_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 ]

if you are in Linux, you don't need the ".exe" after gdal_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()

The most easy way to do this in a script is to use the subprocess module and gdal_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 ])

f you are in Linux, you don't need the ".exe" after gdal_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()
added 838 characters in body
Source Link
radouxju
  • 49.9k
  • 2
  • 71
  • 144

the most easy way to do this in a script is to use the subprocess module and gdal_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 ]

if you are in Linux, you don't need the ".exe" after gdal_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()

the most easy way to do this in a script is to use the subprocess module and gdal_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 ]

if you are in Linux, you don't need the ".exe" after gdal_translate, and if gdal is not installed, you might need to provide the full path to the application

the most easy way to do this in a script is to use the subprocess module and gdal_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 ]

if you are in Linux, you don't need the ".exe" after gdal_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()
Source Link
radouxju
  • 49.9k
  • 2
  • 71
  • 144

the most easy way to do this in a script is to use the subprocess module and gdal_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 ]

if you are in Linux, you don't need the ".exe" after gdal_translate, and if gdal is not installed, you might need to provide the full path to the application