Supervised Classification Using GEE and Google Colab
Supervised Classification Using GEE and Google Colab
SOORIYAARACHCHI NS
PL 3508 – ADVANCED GIS AND REMOTE SENSING FOR PLANNING
DEPARTMENT OF TOWN AND COUNTRY PLANNING
UNIVERISTY OF MORATUWA
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
1 CONTENTS
1 INTRODUCTION ............................................................................................................................... 2
2 STUDY AREA SELECTION ............................................................................................................. 2
3 COLLECTING GROUND TRUTH DATA ...................................................................................... 4
4 CLASSIFICATION ........................................................................................................................... 10
4.1 Step 1 .......................................................................................................................................... 10
4.2 Step 2 - Define the study area boundary ................................................................................. 10
4.3 Step 3 - Create training data samples ...................................................................................... 10
4.4 Step 4 – Merge trained data and export the classified dataset .............................................. 12
4.5 Step 5 – Importing and Initializing Earth Engine .................................................................. 13
4.6 Step 6 – Define the study area .................................................................................................. 13
4.7 Step 7 – Load and Preprocess Landsat Data........................................................................... 13
4.8 Step 8 - Load and Prepare Training Data ............................................................................... 14
4.9 Step 9 - Train the Classifier and Classify the Image .............................................................. 15
4.10 Step 10 - Clip and Visualize the Classified Image................................................................... 15
4.11 Step 11 - Clip with Polygon Shapefile and Export.................................................................. 16
4.12 Step 12 - Export Classified Image ............................................................................................ 17
4.13 Map layout of final output ........................................................................................................ 18
5 ACCURACY ASSESSMENT ........................................................................................................... 19
5.1 Step 1 – Add land use class to each point according to the classified result ......................... 20
5.2 Step 2 - Loading the Data in Google Colab and import relevant libraries ........................... 20
5.3 Step 3 - Load the CSV File........................................................................................................ 21
5.4 Step 4 - Extract Columns .......................................................................................................... 21
5.5 Define Class Labels ................................................................................................................... 21
5.6 Calculate Confusion Matrix and Create DataFrame for Confusion Matrix ........................ 21
5.7 Calculating Accuracy Metrics .................................................................................................. 22
5.8 Printing the Results ................................................................................................................... 22
5.9 Accuracy Metrics Results from the Google Colab.................................................................. 23
5.10 Accuracy Results from Excel.................................................................................................... 23
6 INTERPRETATION OF THE RESULTS...................................................................................... 25
7 LIMITATIONS TO IMPROVE ACCURACY............................................................................... 25
8 GOOGLE COLAB CODES ............................................................................................................. 26
1
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
1 INTRODUCTION
Supervised classification is a widely used technique in remote sensing that involves categorizing
pixels in satellite imagery into predefined classes based on training data. This technique is essential
for various applications such as land cover mapping, urban planning, and environmental
monitoring. The main objective of this assignment is to apply supervised classification to a selected
study area using Google Earth Engine (GEE) and Google Colab, leveraging their powerful
computational capabilities and extensive data repositories.
In this assignment, the focus is on classifying land cover types within a selected area in my
hometown. The classification process involves several key steps, including data collection,
preprocessing, training data selection, model training, classification, and accuracy assessment.
2
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
As you can see in the above figures, it was difficult to get a more accurate classification for a
smaller area. Therefore, I preferred a larger study area first.
The larger study area provided a more diverse and representative sample of different land cover
types, leading to improved training and classification accuracy. By encompassing a variety of land
covers within a larger area, the classifier could better differentiate between classes, ultimately
yielding more reliable and precise results.
This is the study area which I selected to do the supervised classification.
3
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
• Create a QGIS project, add a Base map and create a point layer with suitable fields to
collect ground truth data.
o Id
o Place Name
o Land use class of that place
o Photo
o Date of the when data is collected
4
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
5
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
• Add the created QGIS project with the points layer to the QField Cloud using the
QFieldSync plugin.
6
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
• Open the Qfield, find the relevant project and add data to the fields.
7
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
Here, I added around 60 points representing all land use classes I identified in the study area.
8
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
9
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
4 CLASSIFICATION
The classification was done using Google Earth Engine and Google Colab.
4.1 Step 1
• Create a Google Earth Engine project
10
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
• Then added points to the geometry layer according to built-up areas shown in the satellite
base map.
• As these figures, layers were created and points were added for all land use classes which
are identified
11
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
• Around 200 points were added to each land use class but bare soil is very rare than other
land use classes.
• Therefore, the training points for that class were reduced.
• The Below figure shows the result after adding points to all land use classes.
4.4 Step 4 – Merge trained data and export the classified dataset
• After running these codes in the above figure, Classified_dataset was added to the Asset
of the Google Earth Engine project.
• Then, the path of that dataset can be copied and added to the Google Colab project.
12
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
• Imports the Earth Engine library, which is essential for accessing and manipulating
geospatial data.
• Authenticates the Earth Engine account, allowing access to the project and data.
• Specifies the project ID for your Earth Engine project
• Initializes the Earth Engine library with the specified project ID
13
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
14
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
15
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
16
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
17
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
18
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
5 ACCURACY ASSESSMENT
After completing the supervised classification, it is crucial to evaluate the accuracy of the
classification results. Accuracy assessment helps determine how well the classified image matches
the actual land cover on the ground. This process involves comparing the classified results with
ground truth data that was not used during the training phase. The following steps outline the key
components of the accuracy assessment:
Confusion Matrix
• The ratio of correctly classified instances to the total number of instances. It is calculated
as the sum of the diagonal elements of the confusion matrix divided by the total number of
instances.
Producer's Accuracy
• Indicates the accuracy of individual classes, representing the probability that a pixel in a
given class was classified correctly.
• It is calculated by dividing the number of correctly classified pixels for a class by the total
number of actual pixels in that class (row total).
User's Accuracy
• Represents the reliability of the classified map from the user's perspective.
• It is calculated by dividing the number of correctly classified pixels for a class by the total
number of pixels classified in that class (column total).
Kappa Coefficient
• A statistical measure that accounts for the agreement occurring by chance.
• It is calculated using the confusion matrix and provides a more robust assessment of
classification accuracy.
19
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
5.1 Step 1 – Add land use class to each point according to the classified result
• First I added a land use class for each point manually and then got that class by running the
sample raster points tool.
• The both were same so I used the result from the sample raster points for further.
• Then exported that points layer as a comma delimited separated (CSV) file.
5.2 Step 2 - Loading the Data in Google Colab and import relevant libraries
• Import the Accuracy_csv_new csv file to the content of the Google Colab project.
20
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
• The Sklearn library provides tools for building and evaluating machine learning models,
including metrics for classification.
5.6 Calculate Confusion Matrix and Create DataFrame for Confusion Matrix
• Computes the confusion matrix, a table that describes the performance of the classification
model by comparing the actual and classified labels.
• Then converts the confusion matrix into a DataFrame for better readability.
21
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
22
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
• User Accuracy
User Accuracy = (Total number of correctly classified pixels in each category / Total number of pixels in that category)*100
User Accuracy
Builtup Areas 82.35294118
Waterbodies 86.66666667
Vegetation 68.75
Bare Soil 50
23
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
• Producer Accuracy
Producer Accuracy = (Total number of correctly classified pixels in each category / Total number of pixels in that category)*100
Producer Accuracy
Builtup Areas 82.35294118
Waterbodies 72.22222222
Vegetation 64.70588235
Bare Soil 83.33333333
• Kappa Coefficient
Kappa Coefficient =((TS×TCS)-∑(Column Total×Row Total))/(TS^2-∑(Column TotalxRow Total))×100
TS = Total samples
TCS = Total corected samples or the Sum of the diaganal values
Kappa Coefficient
TS×TCS 2494
∑(Column Total×Ro 891
TS^2 3364
• Overall Accuracy
Overall Accuracy = (Total number of correctly classified pixels / Total number of pixels)* 100
• As you can see in both results from Google Colab and Excel, both values are same.
24
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
• I got the Kappa coefficient value of 64.82 and it is a substantial level of agreement between
the ground truth data and classified data.
• Waterbodies and built-up areas have relatively high producer and user accuracies,
indicating reliable classification for these classes.
• Vegetation has moderate producer and user accuracies, suggesting some confusion with
other classes, particularly Bare Soil.
• Bare Soil has the lowest user accuracy, indicating significant misclassification, primarily
as Vegetation.
25
212365B – SOORIYAARACHCHI NS
SUPERVISED CLASSIFICATION
26