How To Convert Geotiff To Jpg In Python Or Java?
i have a geotiff images that have 3bands. band1,2 is a actual image values and band3 is a instance angle value. band1,2 is float32 data type under code is that i try before. but it
Solution 1:
You can use gdal.Translate
for this.
You can read the documentation here
from osgeo import gdal
options_list = [
'-ot Byte',
'-of JPEG',
'-b 1',
'-scale'
]
options_string = " ".join(options_list)
gdal.Translate(
'save_image_path.jpg',
'image_path.tif',
options=options_string
)
The above code simply create a jpg file with band 1 scaled into byte range. You could add more bands by adding, '-b 2'
etc. Also notice that scale automatically wraps the entire range into byte range. If you like something else you could use '-scale min_val max_val'
in order to specify the range you like, since often you have no need of either the lowest or highest values available.
Solution 2:
The above worked well for me except the JPEG resolution wasn't great. Swapping JPEG to PNG worked better.
Post a Comment for "How To Convert Geotiff To Jpg In Python Or Java?"