Commit d17fafb22966854458935b38160cc603c2613ceb

Authored by Jordi Inglada
1 parent f3444786

ENH: superimpose the landsat image to the s2 image after meta-data shift

Showing 1 changed file with 16 additions and 8 deletions   Show diff stats
scripts/common/LandsatShift.py
... ... @@ -22,22 +22,27 @@ from osgeo.gdalconst import GA_Update
22 22 import sys
23 23 import argparse
24 24  
25   -def subsampleS2(s2ImageIn, s2ImageOut, l8ImageIn):
26   - """Subsample the Sentinel-2 image to the Landsat-8 resolution"""
  25 +def superimpose(inImage, referenceImage, outImage, gridStep=100):
  26 + """Superimpose one image on top of another one using the projection
  27 + information"""
27 28 rsApp = otb.Registry.CreateApplication("Superimpose")
28   - rsApp.SetParameterString("inr",l8ImageIn)
29   - rsApp.SetParameterString("inm",s2ImageIn)
30   - rsApp.SetParameterString("out",s2ImageOut)
31   - rsApp.SetParameterOutputImagePixelType("out", otb.ImagePixelType_uint16)
32   - rsApp.SetParameterFloat("lms",100)
  29 + rsApp.SetParameterString("inr",referenceImage)
  30 + rsApp.SetParameterString("inm",inImage)
  31 + rsApp.SetParameterString("out",outImage)
  32 + rsApp.SetParameterOutputImagePixelType("out", otb.ImagePixelType_int16)
  33 + rsApp.SetParameterFloat("lms",gridStep)
33 34 rsApp.ExecuteAndWriteOutput()
34 35  
  36 +def subsampleS2(s2ImageIn, s2ImageOut, l8ImageIn):
  37 + """Subsample the Sentinel-2 image to the Landsat-8 resolution"""
  38 + superimpose(s2ImageIn, l8ImageIn, s2ImageOut)
  39 +
35 40 def getLandsatRedBand(l8ImageIn, l8RedBandOut, channel=4):
36 41 """Extract the red band of the Landsat-8 image"""
37 42 extractApp = otb.Registry.CreateApplication("ExtractROI")
38 43 extractApp.SetParameterString("in",l8ImageIn)
39 44 extractApp.SetParameterString("out",l8RedBandOut)
40   - extractApp.SetParameterOutputImagePixelType("out", otb.ImagePixelType_uint16)
  45 + extractApp.SetParameterOutputImagePixelType("out", otb.ImagePixelType_int16)
41 46 extractApp.SetParameterStringList("cl",["Channel"+str(channel)])
42 47 extractApp.ExecuteAndWriteOutput()
43 48  
... ... @@ -137,6 +142,9 @@ def landsatShift(l8ImageIn, s2ImageIn, removeTemporaryFiles=True, \
137 142 print "dy (std) = ", str(dy)+"("+str(stdy)+")"
138 143 #A test on std could be included here
139 144 shiftImage(l8ImageIn, -dx, -dy)
  145 + shutil.copy2(l8ImageIn, "tmp_"+l8ImageIn)
  146 + superimpose("tmp_"+l8ImageIn, s2ImageIn, l8ImageIn)
  147 + os.remove("tmp_"+l8ImageIn)
140 148  
141 149  
142 150 if __name__ == "__main__":
... ...