Google Earth Engine Tutorial: Beginners Guide 13 Neighborhood Reducer
Credit: Youtube Channel “Terra Spatial, Learn how to use neighborhood reducer functions for spatial analysis and image processing in Google Earth Engine.”
You can see all the tutorials from here: Techgeo Academy.
Google Earth Engine Tutorial: Beginners Guide 13 Neighborhood Reducer
The Google Earth Engine (GEE) Neighborhood Reducer is a powerful tool for performing spatial operations on images by considering the values of surrounding pixels. It allows you to apply a function, such as mean, median, or custom calculations, to each pixel’s neighborhood (a defined area around the pixel). This is particularly useful for tasks like smoothing, edge detection, or feature extraction.
Key Concepts of Neighborhood Reducer
In GEE, the neighborhoodReducer
function is part of the ee.Image
class. It requires a kernel, which specifies the shape and size of the neighborhood. Common kernels include circular, rectangular, and Gaussian shapes.
Example kernel definitions:
var kernel = ee.Kernel.circle({radius: 5, units: 'pixels'});
var kernel = ee.Kernel.rectangle({width: 3, height: 3});
How to Use Neighborhood Reducer
Step 1: Define your kernel. This sets the spatial extent and shape of the neighborhood.
Step 2: Apply the reducer to your image. For instance, using a mean reducer to calculate average values in each neighborhood.
var smoothedImage = image.reduce(ee.Reducer.mean(), kernel);
This creates a new image where each pixel value is the mean of its surrounding pixels, as defined by the kernel.
Practical Example
Consider an example using the Landsat 8 surface temperature dataset:
var dataset = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
var image = dataset.select('B10').first();
var kernel = ee.Kernel.circle({radius: 2, units: 'pixels'});
var smoothed = image.reduce(ee.Reducer.mean(), kernel);
Map.addLayer(smoothed, {min: 200, max: 300}, 'Smoothened Image');
This code smooths the image by averaging values within a circular neighborhood of 2 pixels radius.
Applications of Neighborhood Reducer
Some common use cases include:
- Smoothing noisy data
- Extracting edges or textures
- Calculating local statistics (e.g., average, variance)
- Creating local maxima or minima maps
Best Practices
1. Choose an appropriate kernel size based on your application’s scale. Too large may lose detail, too small may not smooth effectively.
2. Combine with other image operations (e.g., masked values) to ensure accuracy.
3. Use the geometry
parameter to restrict the reducer to specific areas.
4. Consider computational efficiency, as large kernels may increase processing time.
FAQ
What is a neighborhood reducer in Google Earth Engine?
A neighborhood reducer applies a specified calculation (e.g., mean, sum) to a defined spatial area around each pixel, enabling localized image processing.
How do I create a kernel for the neighborhood reducer?
Kernels are created using ee.Kernel
with parameters like radius
, width
, height
, and units
. For example, ee.Kernel.circle()
creates a circular kernel.
Can I use custom kernels for the neighborhood reducer?
Yes. Custom kernels can be defined using ee.Kernel
with a matrix, allowing precise control over the neighborhood shape and weight distribution.
How does the neighborhood reducer differ from other reducers?
Unlike global reducers (e.g., reduceRegion
), the neighborhood reducer operates locally, applying the function within a spatial window for each pixel individually.
What are the performance considerations for large kernels?
Large kernels increase processing time and memory usage. Itβs best to optimize kernel size and use geometry
to limit operations to relevant areas.
Can I apply multiple reducers in one operation?
Yes. Use ee.Reducer.combine()
to combine multiple reducers or create a custom reducer for complex operations.