Commit 234b238d authored by Manuel Grizonnet's avatar Manuel Grizonnet

ENH: take multiplicator into account to create RGB color composition

parent 93cf8f39
......@@ -59,7 +59,7 @@ def polygonize(input_img,input_mask,output_vec):
"""Helper function to polygonize raster mask using gdal polygonize"""
call_subprocess(["gdal_polygonize.py",input_img,"-f","ESRI Shapefile","-mask",input_mask,output_vec])
def composition_RGB(input_img,output_img):
def composition_RGB(input_img,output_img, nSWIR, nRed, nGreen, multi):
"""Make a RGB composition to highlight the snow cover
input_img: multispectral tiff, output_img: false color
......@@ -67,9 +67,22 @@ def composition_RGB(input_img,output_img):
SWIR in in put images.
"""
#call_subprocess(["gdal_translate","-co","PHOTOMETRIC=RGB","-scale","0","300","-ot","Byte","-b",str(nSWIR),"-b",str(nRed),"-b",str(nGreen),input_img,output_img])
call_subprocess(["otbcli_Convert", "-in", input_img, "-out", output_img, "uint8", "-type", "linear"])
scale_factor=300*multi
call_subprocess(["gdal_translate","-co","PHOTOMETRIC=RGB","-scale","0",str(scale_factor),"-ot","Byte","-b",str(nSWIR),"-b",str(nRed),"-b",str(nGreen),input_img,output_img])
#Comment this part which use an alternative solution with OTB Convert application
# #create temporary file to add nodata value
# f = tempfile.NamedTemporaryFile(suffix='.tif')
# #Store nodata in a temporary file
# call_subprocess(["otbcli_ManageNoData", "-in", input_img, "-out", f.name, "int16", "-mode", "changevalue", "-mode.changevalue.newv", str(nodata)])
# #Convert image to RGB
# call_subprocess(["otbcli_Convert", "-in", f.name, "-out", output_img, "uint8", "-type", "linear"])
# f.close()
def burn_polygons_edges(input_img,input_vec):
"""Burn polygon borders onto an image with the following symbology:
......@@ -284,7 +297,7 @@ class snow_detector :
polygonize(op.join(self.path_tmp,"final_mask.tif"),op.join(self.path_tmp,"final_mask.tif"),op.join(self.path_tmp,"final_mask_vec.shp"))
#RGB composition
composition_RGB(self.img,op.join(self.path_tmp,"composition.tif"))
composition_RGB(self.img,op.join(self.path_tmp,"composition.tif"), self.nSWIR, self.nRed, self.nGreen, self.multi)
#Burn polygons edges on the composition
#TODO add pass1 snow polygon in yellow
......@@ -407,7 +420,7 @@ class snow_detector :
#Index of bands in R1 and R2 respectively
nGreen=2
nSWIR=5
nRed=3
nRed=3
nodata=-10000
if not os.path.isdir(self.img):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment