Gap filling exercise with raw (DN) images

From Open Foris Wiki

Jump to: navigation, search

Here is an exercise on the gapfilling process employing raw imagery

Goals:

*Practise extracting bands with gdal_translate [1]

*Practise using gdalinfo [2] to check metadata of the imagery

*Practise stacking images with gdal_merge.py [3]

*Create a mask using your own shapefile, practising the generic tool gdal_rasterize [4] and tool gdal_calc

*Practise use of tool oft-gapfill to fill the clouds and shadows with data from another image

In this exercise we assume that:

  • The images are ready-made composites and have exactly the same number of rows and columns
  • The images and the shapefile are in the same projection
  • There are clouds/shadows only in the anchor image. The filler may have missing lines with value 0
  • You know how to create a shapefile in Qgis and digitize polygons

To go through this exercise, please follow the following steps:

  1. Take 2 Landsat images from same path/row. The aim is to have one good image (so called anchor) with as few problematic areas as possible and then another which is from same season (as close a date as possible) and has clouds in different locations (so called filler).
  2. See the metadata of the images with gdalinfo:
     gdalinfo anchor.img 
     gdalinfo filler.img 
  3. Extract the bands from these images:
     gdal_translate -of HFA -b 1 anchor.img a1.img 
     gdal_translate -of HFA -b 2 anchor.img a2.img 
    etc for all 7 bands.
  4. Then continue with the filler:
     gdal_translate -of HFA -b 1 filler.img f1.img 
    and repeat for all 7 bands
  5. Create a 14-band stack of your images with gdal_merge.py:
gdal_merge.py -of HFA -separate -o 14band_composite.img a1.img a2.img a3.img a4.img a5.img a6.img a7.img f1.img f2.img f3.img f4.img f5.img f6.img f7.img 
.

Note that there is a newer version of gdal_merge.py which is able to stack multiband images, but for safety's sake we did this in the long way.

  1. Manually digitize the clouds and shadows with Qgis into a new shapefile. Give value 1 for the polygons.
  2. Create a mask for your image pair:
    • Create an empty image of the filler image with value 2 on good areas and 3 on bad areas (0), to burn your shapes on: gdal_calc -ot Byte filler.img mask.img
      1
      #1 0 ! #6 0 ! * 3 2 ?
    • Burn your shapes into the empty image:
      gdal_rasterize -a cloud_fieldname -l shapefile shapefile.shp mask.img 
  3. Use program oft-gapfill to fill the gaps in the anchor with the filler, when possible:
     oft-gapfill -la 1 -nolocal -sd 5 -um mask.img 14band_composite.img filled.img 
    Note! It is wise to test with different parameter values, i.e. -la 2

A follow up: filling ETM gaps with TM

Exercise:

cd /home/...
  • Stack image of anchor and filler
oft-stack -o stack.tif landsat_t2.tif landsat_t1.tif
  • Manually digitize the clouds and shadows with QGIS into a new shapefile. Give value 1 for the polygons. In the exercise we can call it clouds.shp
Digitized shapefile called clouds.shp
  • Create a mask for your image pair:
1. Create an empty image of the filler image with value 2 on good areas and 3 on bad areas (0), to burn your shapes on:
 
oft-calc -ot Byte filler.img mask.img
1
#1 0 ! #6 0 ! * 3 2 ?
2. Burn your shapes into the empty image: gdal_rasterize -a cloud_fieldname -l shapefile shapefile.shp mask.img
 
 gdal_rasterize -a value -l clouds clouds.shp mask.img
 
  • Use program oft-gapfill to fill the gaps in the anchor with the filler; output: filled.tif
oft-gapfill -la 1 -nolocal -sd 5 -um mask.img stack.tif filled.tif
  • Take a look at your results in QGIS
This is a differnet example of Landsat image gap-filling of clouds.



Back to Open Foris Toolkit Main Page

Back to Tools & Exercises



Personal tools