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:DATALandsat7"

# create scratch folder "temp" 
temp = "D:DATAtemp"

# 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)

 

follow us and share it on:

you may also like:

UAS analysis of fire and drought stress under controlled conditions

UAS analysis of fire and drought stress under controlled conditions

New update from the field work of our PhD researcher Luisa Pflumm in Kruger National Park! After weeks of fieldwork in the open savanna, Luisa's work now moves into a more controlled setting, a burn chamber experiment carried out together with our collaborators from...

Welcome, Prof. Dr. Stefan Dech!

Welcome, Prof. Dr. Stefan Dech!

Big news at the EORC: as of today, October 1st, 2026, Stefan Dech is officially a senior professor at the University of Würzburg, and he's staying right where he belongs, with us at the EORC. Stefan will keep working with us on a whole range of Earth Observation...

EO4CAM Meeting with LfU and StMUV at DLR

EO4CAM Meeting with LfU and StMUV at DLR

On 30 September 2026, representatives from the Bavarian State Ministry of the Environment and Consumer Protection (StMUV), the Bavarian Environment Agency (LfU), the EORC of the University Würzubrg (JMU), and the...

Field campaign for DFG Fire and Savanna project

Field campaign for DFG Fire and Savanna project

Our PhD candidate Luisa Pflumm is back in Kruger National Park for her third field campaign. Her PhD focuses on how savanna trees respond to combined fire and drought stress for which she is flying UAVs equipped with multispectral and LiDAR sensors. With this round of...

Successful MSc Defense by Henning Riecken

Successful MSc Defense by Henning Riecken

Congratulations to Henning Riecken, who successfully defended his MSc thesis on September 28, 2026: "Mapping and Structural Assessment of Woody Vegetation in Bavaria Using Digital Elevation Models and Multisource Geodata" Henning's thesis explores how newly available...

bzgl. Art. 50 Verordnung (EU) 2024/1689 (AI Act):

Überwiegend werden eigene originäre Texte und Bilder des EORC genutzt, jedoch sind einige Inhalte von blog post Texten teilweise mit Hilfe von KI überarbeitet worden und einige Bilder sind ganz mit KI erstellt, die jedoch deutlich keine photorealistische Darstellungen abbilden. Aussnahmen sind KI generierte fernerkundliche Datensätze, die explizit für Forschungszwecke mit KI erstellt wurden, hier wird aber durch den assoziierten Text der wissenschaftliche Grund der KI generierten Bilder erläutert.

Share This