Lab 4 - Image Processing Techniques Using Google Earth Engine Pt. II
Lab 4 - Image Processing Techniques Using Google Earth Engine Pt. II
Lab 4 - Image Processing Techniques Using Google Earth Engine Pt. II
Pt. II:
Introduction
This lab covers two important topics in digital image analysis using GEE: image classification
and time-series analysis. The overall objective of image classification is to automatically
categorize all pixels in an image into land cover classes or themes. This lab covers how to
conduct supervised and unsupervised classifications, apply spectral mixture analysis, and
perform classification accuracy assessment. This lab also covers explores time series analysis.
Pre-lab requirement: i.e. you must complete this before lab starts
Objectives
This lab focuses on guiding you through several image processing techniques. At the end of this
lab you will be able to use GEE to perform the following tasks:
• Supervised Classification
• Classification Accuracy Assessment
• Unsupervised Classification
• Spectral Mixture Analysis
• Image Time Series Analysis
1
Supervised image classification and classification accuracy assessment
Supervised Classification
The overall objective of image classification procedures is to automatically categorize all pixels
in an image into land cover classes or themes. Supervised classification procedure involves three
basic components: (1) training, (2) classification, and (3) assessment. The analyst first identifies
a set of training data representing the spectral attributes of each land cover type of interest. The
analyst then selects the desired mathematical approach, i.e. the classifier, which will be used for
spectral pattern recognition. The selected classifier is trained on a limited set of pixels (training
data) and then used to categorize each pixel in the input image into the land cover classes.
Training and validation data can come from a variety of sources. You can use the geometry
drawing tools to collect training data interactively in Earth Engine. Alternatively, you can import
predefined training data from an Earth Engine table asset or a fusion table. The example below
aims to classify an image into vegetation and non-vegetation classes using a supervised
classification approach.
// Import all the available Landsat 5 images then filter by location and sort by cloud cover.
var L5filtered = ee.ImageCollection('LANDSAT/LT05/C01/T1_TOA')
.filterBounds(studysite) //filter to limit images to those over the study site
.sort('CLOUD_COVER'); //sort by cloud cover to obtain an ideal image for classification
2
// Select the first image (i.e. the scene with the least cloud cover) in the sorted collection above.
var input = ee.Image(L5filtered.first()) //first in sort on cloud cover is least cloudy
.clip(studysite); //clip the selected image scene to the study site
/* Use the training data to sample the classified image and create a new band called class that
contains the corresponding value for each reference point based on the classified image.
*/
var training = input.sampleRegions({
collection: training,
properties: ['class'],
scale: 30
});
/* Create and train a random forest classifier. A random forest classifier uses a combination of
decision tree classifiers where each is generated using a random vector sampled independently
from the input vector. Each tree casts a unit vote for the most popular class to classify an input
vector (Pal 2005). */
var classifier = ee.Classifier.randomForest(100) //set the number of trees in random forest to 100
.train(training, 'nd'); //'nd' is 0 for non-vegetation and 1 for vegetation cover types.
// Display classified image in the interactive map. Non-vegetation land cover has a pixel value of
0 and vegetation cover has a value of 1.
Map.addLayer(classified,{min:0,max:1},'classified image');
Classification accuracy assessment verifies the accuracy of the classified image with reference
data that is typically generated either through interpretation of imagery with higher spatial
resolution or ground data collection. It is essential to document the categorical accuracy of the
3
classification results before moving onto other endeavors and a classification is not complete
until its accuracy is assessed. This lab utilizes the most common means of expressing
classification accuracy preparation using a classification error matrix, also known as a confusion
matrix. This matrix compares, on a category-by-category basis, the relationship between
reference data and the corresponding classification results.
This exercise continues the code example from the supervised classification example above. The
accuracy assessment verifies the accuracy of the supervised classification using reference points
generated from a NAIP image that was collected around the same time as the Landsat 5 image to.
// Find and import a NAIP image taken around the same time when the input Landsat was taken.
var referenceimage = ee.ImageCollection('USDA/NAIP/DOQQ')
.filterBounds(studysite) //filter images by the previously defined study area
.filterDate('2011-01-01','2011-12-31'); //filter to match Landsat image date
// Produce 100 random sampling points for producing the reference points.
var referencep = ee.FeatureCollection.randomPoints(studysite,100,0);
/* Use the reference data to sample the classified image and obtain a new band called
classification that contains the corresponding value for each reference points based on the
classified image.
*/
var validated = classified.sampleRegions({
collection: reference,
properties: ['class'],
scale: 30
});
4
print('Validation error matrix: ', testAccuracy);
print('Validation overall accuracy: ', testAccuracy.accuracy()); //Display overall accuracy
//Note the accuracy is very low. What do you think contributes to this problem? How can you
improve the classification accuracy?
The ee.Clusterer package handles unsupervised classification (or clustering) in Earth Engine.
These algorithms are currently based on the algorithms with the same name in Weka, an open
source collection of machine learning algorithms. Clusterers are used the same manner as
classifiers in Earth Engine. The general workflow for clustering is:
The example below classifies a Landsat 5 image scene into 3 classes, which are then labeled
through visual interpretation.
5
// Display the input image as a CIR composite.
Map.addLayer(input, {bands: ['B4', 'B3', 'B2']}, 'input image');
/* Sample the image to construct a “training” sample of pixels to characterize the image.
Unsupervised classifiers do not need training data; however, processing time is decreased by
generating image statistics from a subset of pixels. Rather than sampling pixels, you can increase
the numPixels value to include all pixels in the scene but this will also increase script run time.*/
// Instantiate the unsupervised classifier and train it. Here we specify three classes.
var clusterer = ee.Clusterer.wekaKMeans(3).train(training);
// Display the classified image with random colors for each of the three classes
Map.addLayer(result.randomVisualizer(), {}, 'classified image');
//Visually interpret the classified image. What do you think the three classes should be?
/* Define spectral endmembers. Each number corresponds to the DN values (from 0–127) of the
seven Landsat image bands. You can obtain values of endmembers by going to the Inspector tab
and clicking on “pure” pixels of a selected land cover type. More endmembers can also be found
in the USGS or NASA JPL spectral libraries. */
var urban = [88, 42, 48, 38, 86, 115, 59];
6
var veg = [64, 30, 20, 118, 74, 138, 22];
var water = [63, 23, 16, 14, 6, 131, 4];
/*Display unmixed image. In the unmixed image, the red band shows the proportion of urban
cover, green shows vegetation and blue shows water based on the spectral endmember you
provided earlier. When viewed as an RGB image, the color shows the proportion of each cover
types e.g. cyan pixels are a mixture of water and vegetation, magenta pixels are a mixture of
urban and vegetative cover. */
Map.addLayer(fractions, {}, 'unmixed');
/*With only three endmembers, then is clearly some limitation to this unmixing e.g. based on the
color shown in the RGB image, what type of land cover are the bare fields west of Syracuse?
The example below shows an image time series analysis on the surface temperature of three
locations near Syracuse.
/* Create a time series chart showing surface temperature change for the three defined locations
based on three years of Landsat 8 images. */
var tempTimeSeries = ui.Chart.image.seriesByRegion(
temps, points, ee.Reducer.mean(), 'B11', 100, 'system:time_start', 'label')
7
.setChartType('ScatterChart') // Set the chart to be a scatter plot
.setOptions({ //Set options of the plot
title: 'Temperature over time for locations near City of Syracuse', //Set title
vAxis: {title: 'Temperature (Kelvin)'}, //Set x axis label
lineWidth: 1, // Set the width of the line
pointSize: 4, // Set the point size for each data point
series: {
0: {color: 'FF0000'}, // color for City of Syracuse downtown
1: {color: '00FF00'}, // color for Forest in Clark Reservation
2: {color: '0000FF'} // color for Water in Oneida Lake
}});
8
Assignment – Answer the Following Questions
Submit your code and text answers for this assignment by clicking on “Get Link” in the Code
Editor and sending the link generated to the TA (your link will look something like
https://code.earthengine.google.com/XXXXXXXX. Any written responses should be in comments with
each question separated by a line of forward slashes. For example:
///////////////////////////////////////////////////////////
//Q2. Text answer to Q2
Code to Q2
...
1. Select one Landsat 8 image scene within Onondaga County. Using the random forest
classification approach shown in this lab, classify the land cover into vegetation and non-
vegetation classes.
2. Compute the accuracy of the classification in the above task. What is the error matrix and
what is the overall accuracy?
3. Referring back to the unsupervised classification approach shown in this lab. What labels do
you think should be assigned to the three classified land cover classes?
4. Select one Landsat 8 image scene within Onondaga County. Find your own spectral
endmembers for urban, vegetation and water in this image, and perform a spectral mixture
analysis using the endmembers you created. How would you interpret the unmixed image?
5. Perform a time series analysis of the three Syracuse locations—Syracuse, Clark Reservation,
and Oneida Lake—using three years of Landsat 5 NDVI data. How does the NDVI change
over time at these three locations?
9
Appendix A - Glossary of Terms
Page numbers refer to Lillesand et al. (2015).
10
Appendix B – Useful Resources
General references
Lillesand, T. M., Kiefer, R. W., & Chipman, J. W. (2015). Remote Sensing and Image
Interpretation. 7th edition. John Wiley & Sons.
Pal, M. (2005). Random forest classifier for remote sensing classification. International
Journal of Remote Sensing, 26(1), 217–222.
ttps://doi.org/10.1080/01431160412331269698.
This work was produced by Ge (Jeff) Pu and Dr. Lindi Quackenbush at State University of New
York-College of Environmental Science and Forestry. Suggestions, questions and comments are
all welcome and can be directed to Jeff at gpu100@syr.edu.
11