Extracting the central strip from LANDSAT 7 imagery

Extracting the central strip from LANDSAT 7 imagery

February 8, 2016

Here is a simple Python code to extract the central strip from Landsat 7 imagery (SLC-off),  that is not affected by the SLC failure. The algorithm shrinks the striping zones through a morphological filter (erosion) and creates a new shapefile AOI that extracts the desired raster extent without striping effects. The code is based on Python for ArcGIS (arcpy) – so you require a ArcGIS license.

General steps:

  1. Loop through all Landsat 7 data folders
  2. Stack bands for each image
  3. Create a mask
  4. Erode the mask by 20 pixels
  5. Convert the mask to polygon
  6. Create a minimum bounding box
  7. Clip the original raster through the bbox

 

import arcpy
from arcpy.sa import *

import sys,os

#  Environment settings (Activate Spatial Analyst, Overwrite Outputs allowed and TIFF compression is LZW)
arcpy.CheckOutExtension("spatial")
arcpy.env.overwriteOutput = True
arcpy.env.compression = 'LZW'

# this is your main directory with all unzipped Landsat datasets
 rootdir = "D:\\DATA\\Landsat7\\"

# create scratch folder "temp" 
temp = "D:\\DATA\\temp\\"

# loop through directory with all unzipped Landsat 7 folders
 for files in os.listdir(rootdir):   
    files = os.path.join(rootdir, files)   
    
    # for each loop the subdir "files" is now the current workspace 
    # (e.g. LE71520322015157-SC20160224113319) that contains the Landsat bands
    arcpy.env.workspace = files  
    rasters = arcpy.ListRasters("*", "TIF")  
    
    # create empty array
    stack_liste = []  
    # loop through all rasters in subdir
    for raster in rasters:   

        image = arcpy.Raster(raster) 
        name  = image.name 
        index = name.split("_")[0]  

        # fill up the array only with the actual spectral bands        
        sr = "_sr_band"  
        if sr in raster:   
            stack_liste.append(raster)             

    # now stack all bands within the array
    stack_name = files + "\\" + index + "_stack.tif"    
    arcpy.CompositeBands_management(stack_liste, stack_name)  

    # convert the image stack to a mask by logical operation with an absurd value that will result in an output "0"
    con = EqualTo(stack_name, 123456789)  

    # now shrink the raster mask with value "0" by 20 pixels
    shrink = temp + "shrink"  
    shrinking = Shrink(con, 20, 0) 
    shrinking.save(shrink)  

    zone = temp + "zone.shp" 
    bbox = temp + "bbox.shp"  

    # conver the shrunk mask to polygon and create a minimum bounding box
    arcpy.RasterToPolygon_conversion(shrink, zone, "NO_SIMPLIFY", "VALUE") 
    arcpy.MinimumBoundingGeometry_management(zone, bbox, "RECTANGLE_BY_WIDTH", "NONE")  

    # now use that bounding box as a mask to cut out the central nadir strip from the original stack
    # Final result 
    extract = files + "\\" + index + "_aoi.tif"  
    ExtractByMask = arcpy.sa.ExtractByMask(stack_name, bbox) 
    ExtractByMask.save(extract)

 

you may also like:

our research covered by television

our research covered by television

At the opening of the CAIDAS we also had the opportunity to present our research and development work to various media representatives. For example, we reported on our remote sensing work to ARD and Bayerischer Rundfunk as well as for Mainfranken TV - see e.g. here...

Our research introduced to the JMU president Pauli

Our research introduced to the JMU president Pauli

At the Center for Artificial Intelligence and Data Science (CAIDAS) opening last Friday on 18th of April 2024, we had the opportunity to present the research of our Earth Observation Research Cluster (EORC) and of the Earth Observation Center (EOC) of the German...

UAS mission of monastery Bronnbach

UAS mission of monastery Bronnbach

The potential of UAS data for mapping cultural heritage sites was discussed in the past months with colleagues associated with the UNESCO world heritage activities by our postdocs Dr. Mirjana Bevanda and Dr. Sarah Schönbrodt-Stitt. Based on these discussions further...

Internship Report on Tuesday, April 30 at 14:00

Internship Report on Tuesday, April 30 at 14:00

On Tuesday, April 30 Konstantin Müller will present his internship " GDELT News Analysis of the Noto Earthquake via ERNIE" at 14:00 in 01.B.03, John-Skilton-Str. 4a. : From the abstract: The analysis of socioeconomic data has gained increasing importance. The exchange...

Internship Report on Tuesday, April 23 at 12:00

Internship Report on Tuesday, April 23 at 12:00

On Tuesday, April 23rd Elly Schmid will present her internship at 12:00 in seminar room 3, John-Skilton-Str. 4a. : From the abstract: The internship was carried out as part of the HEATS-(Urban heat) Project of the Georisks team at the Earth Observation Center, which...

New building for the CAIDAS AI center opened

New building for the CAIDAS AI center opened

CAIDAS, the Center for Artificial Intelligence and Data Science ( https://www.caidas.uni-wuerzburg.de/ ), was officially opened on April 19, 2024 with prominent guests from politics and science.  Bavaria's Minister of Science Markus Blume cut the ribbon for the new...