Google Earth Engine Tutorial: Beginners Guide 24 Landsat 8 Image Mosaicking
Credit: Youtube Channel “Terra Spatial, Learn how to create seamless mosaics from multiple Landsat 8 images for large area analysis.”
You can see all the tutorials from here: Techgeo Academy.
Google Earth Engine Tutorial: Beginners Guide to Landsat 8 Image Mosaicking
In this tutorial, you’ll learn how to create a Landsat 8 image mosaic using Google Earth Engine (GEE). Mosaicking allows you to combine multiple satellite images into a single, seamless image, which is useful for analyzing large areas or reducing cloud coverage. By the end of this guide, you’ll be able to load, filter, and mosaic Landsat 8 data programmatically.
Step 1: Install and Initialize Google Earth Engine API
First, ensure you have the Google Earth Engine Python API installed. Install it using pip:
pip install earthengine-api
Then, authenticate and initialize GEE in your script:
import ee
ee.Authenticate()
ee.Initialize()
Step 2: Load Landsat 8 Data
Use the ee.ImageCollection
function to load Landsat 8 surface reflectance data:
landsat8 = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
This dataset includes images from the Landsat 8 Operational Land Imager (OLI) and Thermal Infrared Sensor (TIRS).
Step 3: Filter the Image Collection
Filter images by date, region, and cloud cover. Replace the date range and geometry with your desired parameters:
region = ee.Geometry.Rectangle([minLong, minLat, maxLong, maxLat])
filtered = landsat8
.filterDate('2020-01-01', '2020-12-31')
.filter(ee.Filter.lt('CLOUD_COVER', 20))
.filterBounds(region)
Step 4: Create a Mosaic
Create a mosaic by selecting the first image or using a composite function. Hereβs an example to select the first valid image:
mosaic = filtered.sort('CLOUD_COVER').first()
Alternatively, use .mosaic()
to combine all images in the collection:
mosaic = filtered.mosaic()
Step 5: Visualize the Mosaic
Visualize the mosaic using the RGB bands. For Landsat 8, the common bands for RGB are SR_B.4, SR_B.3, SR_B.2 (Red, Green, Blue):
vis_params = {
'min': 0,
'max': 3000,
'bands': ['SR_B.4', 'SR_B.3', 'SR_B.2']
}
Map.addLayer(mosaic, vis_params, 'Landsat 8 Mosaic')
Step 6: Export the Mosaic (Optional)
To export the mosaic as a GeoTIFF, use Export.image.toDrive()
:
ee.Image(mosaic).select(['SR_B.4', 'SR_B.3', 'SR_B.2']).getDownloadUrl({
'scale': 30,
'region': region,
'format': 'GeoTIFF'
})
Frequently Asked Questions (FAQ)
What is the difference between .first()
and .mosaic()
?
.first()
selects the top image from the sorted collection, prioritizing the least cloud-covered one. .mosaic()
merges all images into a single composite, prioritizing the least cloud-covered pixels.
How do I handle cloud cover in my mosaic?
Use the .filter(ee.Filter.lt('CLOUD_COVER', 20))
to exclude images with more than 20% cloud cover. You can adjust the threshold based on your needs.
Can I mosaic images from multiple sensors or years?
Yes, but ensure all images are compatible in terms of resolution and band structure. For example, Landsat 7 and 8 have different sensor configurations, which might require additional processing.
Why is my mosaic still cloudy?
Even with cloud filtering, some clouds might remain. Use cloud masking tools like cloud_mask
or the qa_band
to further remove cloud pixels.
How do I improve the performance of large image collections?
Use .limit()
or .filterDate()
to reduce the number of images. Avoid processing too many dates or regions to keep the computation efficient.