This practice is focused on change detection methodologies. At the end of this class, you will be able to assess changes using these techniques (Indices-Based Change Detection and Spectral Change).
To perform change detection methodologies, we need to select images before and after the incident to measure the change. To compare 2 images, it is important that everything is normalized, otherwise, you can find changes that are not real changes.
For that we usually have to ask some questions:
Were the images taken by the same sensor type?
Did the images have the same preprocessing? (value of the pixel)
Did the images have the same spatial resolution?
The Area of Interest was the same for both images?
Did the landcover classes have the same definition before and after the incident?
Did the pixels align?
In this practice we are going to use two different types of change detection: Indices Based Change Detection, and Spectral Change
To start the practice we need to select a single image from before and after the incident, then we can apply the change detection methods.
Back in January 2019, a disaster occurred in Brumadinho Brazil; where a dam suffered a catastrophic failure, releasing a large amount of water killing many people. To better understand the situation, you can check this website: https://en.wikipedia.org/wiki/Brumadinho_dam_disaster
In this practice, we are going to use Sentinel-2 MSI: MultiSpectral Instrument, Level-2A. Please check the data here: https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR. This is the surface reflectance product offered by ESA.
> On a blank Code Editor search for "Brumadinho" at the Search Bar and choose the following place
> Draw a rectangle as the following image using the Geometry Tools
> Change the variable name from geometry to AOI on the imports panel
> type sentinel 2 in the Search Box > select Sentinel-2 MSI: MultiSpectral Instrument, Level-2A > click import > change the variable name to s2collection
The Brumadinho dam disaster occurred on 25 January 2019. You can search the images using the USGS Explorer (https://earthexplorer.usgs.gov/).
> Add the following code on your Code Editor
For this practice, we chose for before ('2019-01-06','2019-01-08') and after ('2019-02-01','2019-02-03')
You will be able to see the before and after images
> Click on Layers Panel and check/ uncheck after
Image After
Image Before
You can see the brown part in the center of the image. This is where the disaster happened
Now you are ready to analyze the change!
We are going to NDVI to asses the change.
Next, we need to create NDVI for both images, before and after
Note: The band order in Sentinel 2 is different from Landsat 8, so instead of band 4 for NIR, Sentinel 2 has it on band 8.
Be careful with the bands, each satellite has a different order. For more information, you can check Google Earth Engine Data Catalog.
> Add the code below from line 19 to calculate NDVI for images before and after
> Add the code below from line 29 to display the NDVI in the Map Window
You will be able to see NDVI before and NDVI after
NDVI After
NDVI Before
Let’s stack the layers to create an image with NDVI before into the red channel, NDVI after into the green channel, and again the NDVI before in the blue channel.
So, if NDVI after the value is higher, you should see green, if the NDVI before the value is higher you should see pink, if the values are the same, you should see white (or gray)
> Add the code below on line 32
We created the variable change, where we stacked together NDVI before, NDVI after, and NDVI before (in this order). Now we need to add what we just created in the Map Window
> Add the code below on line 35
You will be able to see the following figure, where the dam collapse can be identified in pink
For the Spectral Change analysis we are going to stack the images from before and after the dam collapse, and classify it using a unsupervised classification.
If you want to try, you can use the supervised classification done on Practice 2
> In a new Code Editor > draw an AOI similar to the previous practice
> Add the code below from line 1
The way to add the image collection was done differently this time. You can use the ee.ImageCollection() and insert the collection name inside the parenthesis
You can find the Image Collection name on Google Earth Engine Data Catalog in the figure below (https://developers.google.com/earth-engine/datasets/catalog/COPERNICUS_S2_SR#description)
> Add the following code on line 20
> Display the change in the Map Window on line 23
Now, the change layer has 16 bands (before: 8 bands, after: 8 bands)
You will be able to see the following image
Now that you have the 16 band image, you can understand the changes happening in each pixel
In the above figure you can see that at NO CHANGE PIXEL the bars from before and after are similar, while for CHANGE PIXEL the bars after a lower than before
In this practice, we are going to use the unsupervised classification, but if you can also perform the supervised classification from now on
> Add the following code from line 25
You will be able to see the following image
Good! now you can download the data and analyze it in your GIS software and define the classes (reclass)
Code for the Indices-Based Change Detection
var bands = ['B2','B3','B4','B5','B6','B7','B8','B8A'];
var before = s2collection
.filterDate('2019-01-06','2019-01-08')
.filterBounds(AOI)
.select(bands)
.median()
.clip(AOI);
var after = s2collection
.filterDate('2019-02-01','2019-02-03')
.filterBounds(AOI)
.select(bands)
.median()
.clip(AOI);
Map.addLayer(before,{bands: ['B4','B3','B2'], min:300, max:2200}, 'before');
Map.addLayer(after,{bands: ['B4','B3','B2'], min:300, max:2200}, 'after');
//NDVI Before
var nir_b = before.select('B8');
var red_b = before.select('B4');
var ndvi_b = nir_b.subtract(red_b).divide(nir_b.add(red_b));
//NDVI After
var nir_a = after.select('B8');
var red_a = after.select('B4');
var ndvi_a = nir_a.subtract(red_a).divide(nir_a.add(red_a));
Map.addLayer(ndvi_b,{min: -1, max: 1, gamma: 2},'ndvi_before');
Map.addLayer(ndvi_a,{min: -1, max: 1, gamma: 2},'ndvi_after');
//Layer Stacking
var change = ndvi_b.addBands(ndvi_a).addBands(ndvi_b);
Map.addLayer(change, {}, 'change');
Code for the Spectral Change
var bands = ['B2','B3', 'B4','B5','B6','B7','B8','B8A'];
var before = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2019-01-06','2019-01-08')
.filterBounds(AOI)
.select(bands)
.median()
.clip(AOI);
var after = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2019-02-01','2019-02-03')
.filterBounds(AOI)
.select(bands)
.median()
.clip(AOI);
Map.addLayer(before,{bands: ['B4', 'B3', 'B2'], min: 300, max: 2200, gamma: 2},'before');
Map.addLayer(after ,{bands: ['B4', 'B3', 'B2'], min: 300, max: 2200, gamma: 2},'after');
// Layer Stacking (before and after)
var change = before.addBands(after);
Map.addLayer(change ,{bands: ['B8', 'B8_1', 'B8'], min: 0, max: 4000, gamma: 2},'change');
// Make the training dataset
var training = change.sample({
region: AOI,
scale: 10,
numPixels: 5000
});
// Define the number of clusters (classes) and train it
var clusterer = ee.Clusterer.wekaKMeans(15).train(training); //15 means number of class
// Cluster the input using the trained clusterer.
var result = change.cluster(clusterer);
// Display the clusters (classes) with random colors
Map.addLayer(result.randomVisualizer(), {}, 'clusters');