fixed image paths

This commit is contained in:
Ollie Ballinger
2023-04-17 11:46:07 +01:00
parent 7ccf85e48e
commit 9eb020dab7
29 changed files with 1611 additions and 1734 deletions

View File

@@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Remote Sensing for OSINT - 5&nbsp; Interpreting Images</title>
<title>Remote Sensing for OSINT - Interpreting Images</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
@@ -199,20 +199,17 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./index.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Overview</span></span></a>
<a href="./index.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Overview</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./A2_Remote_Sensing.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Remote Sensing</span></span></a>
<a href="./A2_Remote_Sensing.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Remote Sensing</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./A3_Data_Acquisition.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Data Acquisition</span></span></a>
<a href="./A3_Data_Acquisition.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Data Acquisition</span></a>
</div>
</li>
</ul>
@@ -228,26 +225,22 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
<ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./B1_Getting_Started.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Getting Started</span></span></a>
<a href="./B1_Getting_Started.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Getting Started</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./B2_Interpreting_Images.html" class="sidebar-item-text sidebar-link active">
<span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Interpreting Images</span></span></a>
<a href="./B2_Interpreting_Images.html" class="sidebar-item-text sidebar-link active"><span class="chapter-title">Interpreting Images</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./B3_Image_Series.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Image Series</span></span></a>
<a href="./B3_Image_Series.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Image Series</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./B4_Vectors_Tables.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Vectors and Tables</span></span></a>
<a href="./B4_Vectors_Tables.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Vectors and Tables</span></a>
</div>
</li>
</ul>
@@ -263,32 +256,27 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./C1_Lights.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">War at Night</span></span></a>
<a href="./C1_Lights.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">War at Night</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./C2_Refineries.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Refinery Identification</span></span></a>
<a href="./C2_Refineries.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Refinery Identification</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./C3_Blast.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Blast Damage Assessment</span></span></a>
<a href="./C3_Blast.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Blast Damage Assessment</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./C4_Ships.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Ship Detection</span></span></a>
<a href="./C4_Ships.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Ship Detection</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./C5_Object_Detection.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Object Detection</span></span></a>
<a href="./C5_Object_Detection.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Object Detection</span></a>
</div>
</li>
</ul>
@@ -303,24 +291,24 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#image-manipulation-bands-arithmetic-thresholds-and-masks" id="toc-image-manipulation-bands-arithmetic-thresholds-and-masks" class="nav-link active" data-scroll-target="#image-manipulation-bands-arithmetic-thresholds-and-masks"><span class="header-section-number">5.1</span> Image Manipulation: Bands, Arithmetic, Thresholds, and Masks</a>
<li><a href="#image-manipulation-bands-arithmetic-thresholds-and-masks" id="toc-image-manipulation-bands-arithmetic-thresholds-and-masks" class="nav-link active" data-scroll-target="#image-manipulation-bands-arithmetic-thresholds-and-masks">Image Manipulation: Bands, Arithmetic, Thresholds, and Masks</a>
<ul class="collapse">
<li><a href="#band-arithmetic-in-earth-engine" id="toc-band-arithmetic-in-earth-engine" class="nav-link" data-scroll-target="#band-arithmetic-in-earth-engine"><span class="header-section-number">5.1.1</span> Band Arithmetic in Earth Engine</a></li>
<li><a href="#thresholding-masking-and-remapping-images" id="toc-thresholding-masking-and-remapping-images" class="nav-link" data-scroll-target="#thresholding-masking-and-remapping-images"><span class="header-section-number">5.1.2</span> Thresholding, Masking, and Remapping Images</a></li>
<li><a href="#band-arithmetic-in-earth-engine" id="toc-band-arithmetic-in-earth-engine" class="nav-link" data-scroll-target="#band-arithmetic-in-earth-engine">Band Arithmetic in Earth Engine</a></li>
<li><a href="#thresholding-masking-and-remapping-images" id="toc-thresholding-masking-and-remapping-images" class="nav-link" data-scroll-target="#thresholding-masking-and-remapping-images">Thresholding, Masking, and Remapping Images</a></li>
<li><a href="#conclusion" id="toc-conclusion" class="nav-link" data-scroll-target="#conclusion">Conclusion</a></li>
<li><a href="#references" id="toc-references" class="nav-link" data-scroll-target="#references">References</a></li>
</ul></li>
<li><a href="#interpreting-an-image-classification" id="toc-interpreting-an-image-classification" class="nav-link" data-scroll-target="#interpreting-an-image-classification"><span class="header-section-number">5.2</span> Interpreting an Image: Classification</a>
<li><a href="#interpreting-an-image-classification" id="toc-interpreting-an-image-classification" class="nav-link" data-scroll-target="#interpreting-an-image-classification">Interpreting an Image: Classification</a>
<ul class="collapse">
<li><a href="#supervised-classification" id="toc-supervised-classification" class="nav-link" data-scroll-target="#supervised-classification"><span class="header-section-number">5.2.1</span> Supervised Classification</a></li>
<li><a href="#unsupervised-classification" id="toc-unsupervised-classification" class="nav-link" data-scroll-target="#unsupervised-classification"><span class="header-section-number">5.2.2</span> Unsupervised Classification</a></li>
<li><a href="#supervised-classification" id="toc-supervised-classification" class="nav-link" data-scroll-target="#supervised-classification">Supervised Classification</a></li>
<li><a href="#unsupervised-classification" id="toc-unsupervised-classification" class="nav-link" data-scroll-target="#unsupervised-classification">Unsupervised Classification</a></li>
<li><a href="#conclusion-1" id="toc-conclusion-1" class="nav-link" data-scroll-target="#conclusion-1">Conclusion</a></li>
<li><a href="#references-1" id="toc-references-1" class="nav-link" data-scroll-target="#references-1">References</a></li>
</ul></li>
<li><a href="#accuracy-assessment-quantifying-classification-quality" id="toc-accuracy-assessment-quantifying-classification-quality" class="nav-link" data-scroll-target="#accuracy-assessment-quantifying-classification-quality"><span class="header-section-number">5.3</span> Accuracy Assessment: Quantifying Classification Quality</a>
<li><a href="#accuracy-assessment-quantifying-classification-quality" id="toc-accuracy-assessment-quantifying-classification-quality" class="nav-link" data-scroll-target="#accuracy-assessment-quantifying-classification-quality">Accuracy Assessment: Quantifying Classification Quality</a>
<ul class="collapse">
<li><a href="#quantifying-classification-accuracy-through-a-confusion-matrix" id="toc-quantifying-classification-accuracy-through-a-confusion-matrix" class="nav-link" data-scroll-target="#quantifying-classification-accuracy-through-a-confusion-matrix"><span class="header-section-number">5.3.1</span> Quantifying Classification Accuracy Through a Confusion Matrix</a></li>
<li><a href="#hyperparameter-tuning" id="toc-hyperparameter-tuning" class="nav-link" data-scroll-target="#hyperparameter-tuning"><span class="header-section-number">5.3.2</span> Hyperparameter tuning</a></li>
<li><a href="#quantifying-classification-accuracy-through-a-confusion-matrix" id="toc-quantifying-classification-accuracy-through-a-confusion-matrix" class="nav-link" data-scroll-target="#quantifying-classification-accuracy-through-a-confusion-matrix">Quantifying Classification Accuracy Through a Confusion Matrix</a></li>
<li><a href="#hyperparameter-tuning" id="toc-hyperparameter-tuning" class="nav-link" data-scroll-target="#hyperparameter-tuning">Hyperparameter tuning</a></li>
<li><a href="#conclusion-2" id="toc-conclusion-2" class="nav-link" data-scroll-target="#conclusion-2">Conclusion</a></li>
</ul></li>
</ul>
@@ -331,7 +319,7 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Interpreting Images</span></h1>
<h1 class="title"><span class="chapter-title">Interpreting Images</span></h1>
</div>
@@ -347,8 +335,8 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
</header>
<p>Now that you know how images are viewed and what kinds of images exist in Earth Engine, how do we manipulate them? To gain the skills of interpreting images, youll work with bands, combining values to form indices and masking unwanted pixels. Then, youll learn some of the techniques available in Earth Engine for classifying images and interpreting the results.</p>
<section id="image-manipulation-bands-arithmetic-thresholds-and-masks" class="level2" data-number="5.1">
<h2 data-number="5.1" class="anchored" data-anchor-id="image-manipulation-bands-arithmetic-thresholds-and-masks"><span class="header-section-number">5.1</span> Image Manipulation: Bands, Arithmetic, Thresholds, and Masks</h2>
<section id="image-manipulation-bands-arithmetic-thresholds-and-masks" class="level2">
<h2 class="anchored" data-anchor-id="image-manipulation-bands-arithmetic-thresholds-and-masks">Image Manipulation: Bands, Arithmetic, Thresholds, and Masks</h2>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
@@ -387,29 +375,29 @@ Chapter Information
<p>Spectral indices are based on the fact that different objects and land covers on the Earths surface reflect different amounts of light from the Sun at different wavelengths. In the visible part of the spectrum, for example, a healthy green plant reflects a large amount of green light while absorbing blue and red light — which is why it appears green to our eyes. Light also arrives from the Sun at wavelengths outside what the human eye can see, and there are large differences in reflectances between living and nonliving land covers, and between different types of vegetation, both in the visible and outside the visible wavelengths. We visualized this earlier, in Chaps. F1.1 and F1.3 when we mapped color-infrared images (Fig. F2.0.1).</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image39.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image39.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.0.1 Mapped color-IR images from multiple satellite sensors that we mapped in Chap. F1.3. The near infrared spectrum is mapped as red, showing where there are high amounts of healthy vegetation.</figcaption><p></p>
</figure>
</div>
<p>If we graph the amount of light (reflectance) at different wavelengths that an object or land cover reflects, we can visualize this more easily (Fig. F2.0.2). For example, look at the reflectance curves for soil and water in the graph below. Soil and water both have relatively low reflectance at wavelengths around 300 nm (ultraviolet and violet light). Conversely, at wavelengths above 700 nm (red and infrared light) soil has relatively high reflectance, while water has very low reflectance. Vegetation, meanwhile, generally reflects large amounts of near infrared light, relative to other land covers.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image32.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image32.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.0.2 A graph of the amount of reflectance for different objects on the Earths surface at different wavelengths in the visible and infrared portions of the electromagnetic spectrum. 1 micrometer (µm) = 1,000 nanometers (nm).</figcaption><p></p>
</figure>
</div>
<p>Spectral indices use math to express how objects reflect light across multiple portions of the spectrum as a single number. Indices combine multiple bands, often with simple operations of subtraction and division, to create a single value across an image that is intended to help to distinguish particular land uses or land covers of interest. Using Fig. F2.0.2, you can imagine which wavelengths might be the most informative for distinguishing among a variety of land covers. We will explore a variety of calculations made from combinations of bands in the following sections.</p>
<p>Indices derived from satellite imagery are used as the basis of many remote-sensing analyses. Indices have been used in thousands of applications, from detecting anthropogenic deforestation to examining crop health. For example, the growth of economically important crops such as wheat and cotton can be monitored throughout the growing season: Bare soil reflects more red wavelengths, whereas growing crops reflect more of the near-infrared (NIR) wavelengths. Thus, calculating a ratio of these two bands can help monitor how well crops are growing (Jackson and Huete 1991).</p>
</section>
<section id="band-arithmetic-in-earth-engine" class="level3" data-number="5.1.1">
<h3 data-number="5.1.1" class="anchored" data-anchor-id="band-arithmetic-in-earth-engine"><span class="header-section-number">5.1.1</span> Band Arithmetic in Earth Engine</h3>
<section id="band-arithmetic-in-earth-engine" class="level3">
<h3 class="anchored" data-anchor-id="band-arithmetic-in-earth-engine">Band Arithmetic in Earth Engine</h3>
<p>If you have not already done so, be sure to add the books code repository to the Code Editor by entering <a href="https://www.google.com/url?q=https://code.earthengine.google.com/?accept_repo%3Dprojects/gee-edu/book&amp;sa=D&amp;source=editors&amp;ust=1671458829783542&amp;usg=AOvVaw2f8xfEZP6c0zP_Ke8jL26U"></a><a href="https://www.google.com/url?q=https://code.earthengine.google.com/?accept_repo%3Dprojects/gee-edu/book&amp;sa=D&amp;source=editors&amp;ust=1671458829783919&amp;usg=AOvVaw2i09J44MzpMZkjV_JLEnNR">https://code.earthengine.google.com/?accept_repo=projects/gee-edu/book</a> into your browser. The books scripts will then be available in the script manager panel. If you have trouble finding the repo, you can visit <a href="https://www.google.com/url?q=https://docs.google.com/presentation/d/1Kt6wGNoesYm__Cu3k3bnlbbyPN6m9SF4hQHK-pIDHfc/edit%23slide%3Did.g18a7b4b055d_0_624&amp;sa=D&amp;source=editors&amp;ust=1671458829784270&amp;usg=AOvVaw1Kr82KG60ZeFLYC8cOZ67A">this link</a> for help.</p>
<p>Many indices can be calculated using band arithmetic in Earth Engine. Band arithmetic is the process of adding, subtracting, multiplying, or dividing two or more bands from an image. Here well first do this manually, and then show you some more efficient ways to perform band arithmetic in Earth Engine.</p>
<section id="arithmetic-calculation-of-ndvi" class="level4" data-number="5.1.1.1">
<h4 data-number="5.1.1.1" class="anchored" data-anchor-id="arithmetic-calculation-of-ndvi"><span class="header-section-number">5.1.1.1</span> Arithmetic Calculation of NDVI</h4>
<section id="arithmetic-calculation-of-ndvi" class="level4">
<h4 class="anchored" data-anchor-id="arithmetic-calculation-of-ndvi">Arithmetic Calculation of NDVI</h4>
<p>The red and near-infrared bands provide a lot of information about vegetation due to vegetations high reflectance in these wavelengths. Take a look at Fig. F2.0.2 and note, in particular, that vegetation curves (graphed in green) have relatively high reflectance in the NIR range (approximately 750900 nm). Also note that vegetation has low reflectance in the red range (approximately 630690 nm), where sunlight is absorbed by chlorophyll. This suggests that if the red and near-infrared bands could be combined, they would provide substantial information about vegetation.</p>
<p>Soon after the launch of Landsat 1 in 1972, analysts worked to devise a robust single value that would convey the health of vegetation along a scale of 1 to 1. This yielded the NDVI, using the formula:</p>
<p><img src="../images/F2/image1.png" class="img-fluid"> (F2.0.1)</p>
<p><img src="images/F2/image1.png" class="img-fluid"> (F2.0.1)</p>
<p>where NIR and red refer to the brightness of each of those two bands. As seen in Chaps. F1.1 and F1.2, this brightness might be conveyed in units of reflectance, radiance, or digital number (DN); the NDVI is intended to give nearly equivalent values across platforms that use these wavelengths. The general form of this equation is called a “normalized difference”—the numerator is the “difference” and the denominator “normalizes” the value. Outputs for NDVI vary between 1 and 1. High amounts of green vegetation have values around 0.80.9. Absence of green leaves gives values near 0, and water gives values near 1.</p>
<p>To compute the NDVI, we will introduce Earth Engines implementation of band arithmetic. Cloud-based band arithmetic is one of the most powerful aspects of Earth Engine, because the platforms computers are optimized for this type of heavy processing. Arithmetic on bands can be done even at planetary scale very quickly—an idea that was out of reach before the advent of cloud-based remote sensing. Earth Engine automatically partitions calculations across a large number of computers as needed, and assembles the answer for display.</p>
<p>As an example, lets examine an image of San Francisco (Fig. F2.0.3).</p>
@@ -435,7 +423,7 @@ Chapter Information
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image46.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image46.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.0.3 False color Sentinel-2 imagery of San Francisco and surroundings</figcaption><p></p>
</figure>
</div>
@@ -462,14 +450,14 @@ Chapter Information
<p>Examine the resulting index, using the Inspector to pick out pixel values in areas of vegetation and non-vegetation if desired.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image50.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image50.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.0.4 NDVI calculated using Sentinel-2. Remember that outputs for NDVI vary between 1 and 1. High amounts of green vegetation have values around 0.80.9. Absence of green leaves gives values near 0, and water gives values near 1.</figcaption><p></p>
</figure>
</div>
<p>Using these simple arithmetic tools, you can build almost any index, or develop and visualize your own. Earth Engine allows you to quickly and easily calculate and display the index across a large area.</p>
</section>
<section id="single-operation-computation-of-normalized-difference-for-ndvi" class="level4" data-number="5.1.1.2">
<h4 data-number="5.1.1.2" class="anchored" data-anchor-id="single-operation-computation-of-normalized-difference-for-ndvi"><span class="header-section-number">5.1.1.2</span> Single-Operation Computation of Normalized Difference for NDVI</h4>
<section id="single-operation-computation-of-normalized-difference-for-ndvi" class="level4">
<h4 class="anchored" data-anchor-id="single-operation-computation-of-normalized-difference-for-ndvi">Single-Operation Computation of Normalized Difference for NDVI</h4>
<p>Normalized differences like NDVI are so common in remote sensing that Earth Engine provides the ability to do that particular sequence of subtraction, addition, and division in a single step, using the normalizedDifference method. This method takes an input image, along with bands you specify, and creates a normalized difference of those two bands. The NDVI computation previously created with band arithmetic can be replaced with one line of code:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Now use the built-in normalizedDifference function to achieve the same outcome. </span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> ndviND <span class="op">=</span> sfoImage<span class="op">.</span><span class="fu">normalizedDifference</span>([<span class="st">'B8'</span><span class="op">,</span> <span class="st">'B4'</span>])<span class="op">;</span> </span>
@@ -481,13 +469,13 @@ Chapter Information
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>Note that the order in which you provide the two bands to normalizedDifference is important. We use B8, the near-infrared band, as the first parameter, and the red band B4 as the second. If your two computations of NDVI do not look identical when drawn to the screen, check to make sure that the order you have for the NIR and red bands is correct.</p>
</section>
<section id="using-normalized-difference-for-ndwi" class="level4" data-number="5.1.1.3">
<h4 data-number="5.1.1.3" class="anchored" data-anchor-id="using-normalized-difference-for-ndwi"><span class="header-section-number">5.1.1.3</span> Using Normalized Difference for NDWI</h4>
<section id="using-normalized-difference-for-ndwi" class="level4">
<h4 class="anchored" data-anchor-id="using-normalized-difference-for-ndwi">Using Normalized Difference for NDWI</h4>
<p>As mentioned, the normalized difference approach is used for many different indices. Lets apply the same normalizedDifference method to another index.</p>
<p>The Normalized Difference Water Index (NDWI) was developed by Gao (1996) as an index of vegetation water content. The index is sensitive to changes in the liquid content of vegetation canopies. This means that the index can be used, for example, to detect vegetation experiencing drought conditions or differentiate crop irrigation levels. In dry areas, crops that are irrigated can be differentiated from natural vegetation. It is also sometimes called the Normalized Difference Moisture Index (NDMI). NDWI is formulated as follows:</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image2.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image2.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">(F2.0.2)</figcaption><p></p>
</figure>
</div>
@@ -505,7 +493,7 @@ Chapter Information
<p>Examine the areas of the map that NDVI identified as having a lot of vegetation. Notice which are more blue. This is vegetation that has higher water content.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image40.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image40.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.0.5 NDWI displayed for Sentinel-2 over San Francisco</figcaption><p></p>
</figure>
</div>
@@ -524,11 +512,11 @@ Note
</div>
</section>
</section>
<section id="thresholding-masking-and-remapping-images" class="level3" data-number="5.1.2">
<h3 data-number="5.1.2" class="anchored" data-anchor-id="thresholding-masking-and-remapping-images"><span class="header-section-number">5.1.2</span> Thresholding, Masking, and Remapping Images</h3>
<section id="thresholding-masking-and-remapping-images" class="level3">
<h3 class="anchored" data-anchor-id="thresholding-masking-and-remapping-images">Thresholding, Masking, and Remapping Images</h3>
<p>The previous section in this chapter discussed how to use band arithmetic to manipulate images. Those methods created new continuous values by combining bands within an image. This section uses logical operators to categorize band or index values to create a categorized image.</p>
<section id="implementing-a-threshold" class="level4" data-number="5.1.2.1">
<h4 data-number="5.1.2.1" class="anchored" data-anchor-id="implementing-a-threshold"><span class="header-section-number">5.1.2.1</span> Implementing a Threshold</h4>
<section id="implementing-a-threshold" class="level4">
<h4 class="anchored" data-anchor-id="implementing-a-threshold">Implementing a Threshold</h4>
<p>Implementing a threshold uses a number (the threshold value) and logical operators to help us partition the variability of images into categories. For example, recall our map of NDVI. High amounts of vegetation have NDVI values near 1 and non-vegetated areas are near 0. If we want to see what areas of the map have vegetation, we can use a threshold to generalize the NDVI value in each pixel as being either “no vegetation” or “vegetation”. That is a substantial simplification, to be sure, but can help us to better comprehend the rich variation on the Earths surface. This type of categorization may be useful if, for example, we want to look at the proportion of a city that is vegetated. Lets create a Sentinel-2 map of NDVI near Seattle, Washington, USA. Enter the code below in a new script.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Create an NDVI image using Sentinel 2. </span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> seaPoint <span class="op">=</span> ee<span class="op">.</span><span class="at">Geometry</span><span class="op">.</span><span class="fu">Point</span>(<span class="op">-</span><span class="fl">122.2040</span><span class="op">,</span> <span class="fl">47.6221</span>)<span class="op">;</span> </span>
@@ -551,7 +539,7 @@ Note
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true" tabindex="-1"></a></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image30.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image30.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.0.6 NDVI image of Sentinel-2 imagery over Seattle, Washington, USA</figcaption><p></p>
</figure>
</div>
@@ -571,15 +559,15 @@ Note
<p>The gt method is from the family of Boolean operators — that is, gt is a function that performs a test in each pixel and returns the value 1 if the test evaluates to true, and 0 otherwise. Here, for every pixel in the image, it tests whether the NDVI value is greater than 0.5. When this condition is met, the layer seaVeg gets the value 1. When the condition is false, it receives the value 0.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image47.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image47.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.0.7 Thresholded forest and non-forest image based on NDVI for Seattle, Washington, USA</figcaption><p></p>
</figure>
</div>
<p>Use the Inspector tool to explore this new layer. If you click on a green location, that NDVI should be greater than 0.5. If you click on a white pixel, the NDVI value should be equal to or less than 0.5.</p>
<p>Other operators in this Boolean family include less than (lt), less than or equal to (lte), equal to (eq), not equal to (neq), and greater than or equal to (gte) and more.</p>
</section>
<section id="building-complex-categorizations-with-.where" class="level4" data-number="5.1.2.2">
<h4 data-number="5.1.2.2" class="anchored" data-anchor-id="building-complex-categorizations-with-.where"><span class="header-section-number">5.1.2.2</span> Building Complex Categorizations with .where</h4>
<section id="building-complex-categorizations-with-.where" class="level4">
<h4 class="anchored" data-anchor-id="building-complex-categorizations-with-.where">Building Complex Categorizations with .where</h4>
<p>A binary map classifying NDVI is very useful. However, there are situations where you may want to split your image into more than two bins. Earth Engine provides a tool, the where method, that conditionally evaluates to true or false within each pixel depending on the outcome of a test. This is analogous to an if statement seen commonly in other languages. However, to perform this logic when programming for Earth Engine, we avoid using the JavaScript if statement. Importantly, JavaScript if commands are not calculated on Googles servers, and can create serious problems when running your code — in effect, the servers try to ship all of the information to be executed to your own computers browser, which is very underequipped for such enormous tasks. Instead, we use the where clause for conditional logic.</p>
<p>Suppose instead of just splitting the forested areas from the non-forested areas in our NDVI, we want to split the image into likely water, non-forested and forested areas. We can use where and thresholds of -0.1 and 0.5. We will start by creating an image using ee.Image. We then clip the new image so that it covers the same area as our seaNDVI layer.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Implement .where. </span></span>
@@ -603,13 +591,13 @@ Note
<p>There are a few interesting things to note about this code that you may not have seen before. First, were not defining a new variable for each where call. As a result, we can perform many where calls without creating a new variable each time and needing to keep track of them. Second, when we created the starting image, we set the value to 1. This means that we could easily set the bottom and top values with one where clause each. Finally, while we did not do it here, we can combine multiple where clauses using and and or. For example, we could identify pixels with an intermediate level of NDVI using seaNDVI.gte(-0.1).and(seaNDVI.lt(0.5)).</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image37.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image37.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.0.8 Thresholded water, forest, and non-forest image based on NDVI for Seattle, Washington, USA.</figcaption><p></p>
</figure>
</div>
</section>
<section id="masking-specific-values-in-an-image" class="level4" data-number="5.1.2.3">
<h4 data-number="5.1.2.3" class="anchored" data-anchor-id="masking-specific-values-in-an-image"><span class="header-section-number">5.1.2.3</span> Masking Specific Values in an Image</h4>
<section id="masking-specific-values-in-an-image" class="level4">
<h4 class="anchored" data-anchor-id="masking-specific-values-in-an-image">Masking Specific Values in an Image</h4>
<p>Masking an image is a technique that removes specific areas of an image — those covered by the mask — from being displayed or analyzed. Earth Engine allows you to both view the current mask and update the mask.</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Implement masking. </span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="co">// View the seaVeg layer's current mask. </span></span>
@@ -618,7 +606,7 @@ Note
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image23.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image23.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.0.9 The existing mask for the seaVeg layer we created previously</figcaption><p></p>
</figure>
</div>
@@ -642,7 +630,7 @@ Note
<p>Turn off all of the other layers. You can see how the maskedVeg layer now has masked out all non-forested areas.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image26.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image26.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.0.10 An updated mask now displays only the forested areas. Non-forested areas are masked out and transparent.</figcaption><p></p>
</figure>
</div>
@@ -652,13 +640,13 @@ Note
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image33.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image33.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.0.11 The updated mask. Areas of non-forest are now masked out as well (black areas of the image).</figcaption><p></p>
</figure>
</div>
</section>
<section id="remapping-values-in-an-image" class="level4" data-number="5.1.2.4">
<h4 data-number="5.1.2.4" class="anchored" data-anchor-id="remapping-values-in-an-image"><span class="header-section-number">5.1.2.4</span> Remapping Values in an Image</h4>
<section id="remapping-values-in-an-image" class="level4">
<h4 class="anchored" data-anchor-id="remapping-values-in-an-image">Remapping Values in an Image</h4>
<p>Remapping takes specific values in an image and assigns them a different value. This is particularly useful for categorical datasets, including those you read about in Chap. F1.2 and those we have created earlier in this chapter.</p>
<p>Lets use the remap method to change the values for our seaWhere layer. Note that since were changing the middle value to be the largest, well need to adjust our palette as well.</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Implement remapping. </span></span>
@@ -675,7 +663,7 @@ Note
<p>Use the inspector to compare values between our original seaWhere (displayed as Water, Non-Forest, Forest) and the seaRemap, marked as “Remapped Values.” Click on a forested area and you should see that the Remapped Values should be 10, instead of 2 (Fig. F2.0.12).</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image28.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image28.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.0.12 For forested areas, the remapped layer has a value of 10, compared with the original layer, which has a value of 2. You may have more layers in your Inspector.</figcaption><p></p>
</figure>
</div>
@@ -715,8 +703,8 @@ Note
<p>Souza Jr CM, Siqueira JV, Sales MH, et al (2013) Ten-year Landsat classification of deforestation and forest degradation in the Brazilian Amazon. Remote Sens 5:54935513. https://doi.org/10.3390/rs5115493</p>
</section>
</section>
<section id="interpreting-an-image-classification" class="level2" data-number="5.2">
<h2 data-number="5.2" class="anchored" data-anchor-id="interpreting-an-image-classification"><span class="header-section-number">5.2</span> Interpreting an Image: Classification</h2>
<section id="interpreting-an-image-classification" class="level2">
<h2 class="anchored" data-anchor-id="interpreting-an-image-classification">Interpreting an Image: Classification</h2>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
@@ -760,15 +748,15 @@ Chapter Information
<p>In remote sensing, image classification is an attempt to categorize all pixels in an image into a finite number of labeled land cover and/or land use classes. The resulting classified image is a simplified thematic map derived from the original image (Fig. F2.1.1). Land cover and land use information is essential for many environmental and socioeconomic applications, including natural resource management, urban planning, biodiversity conservation, agricultural monitoring and carbon accounting.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image48.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image48.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.1 Image classification concept</figcaption><p></p>
</figure>
</div>
<p>Image classification techniques for generating land cover and land use information have been in use since the 1980s (Li et al.&nbsp;2014). Here, we will cover the concepts of pixel-based supervised and unsupervised classifications, testing out different classifiers. Chapter F3.3 covers the concept and application of object-based classification.</p>
<p>It is important to define land use and land cover. Land cover relates to the physical characteristics of the surface: simply put, it documents whether an area of the Earths surface is covered by forests, water, impervious surfaces, etc. Land use refers to how this land is being used by people. For example, herbaceous vegetation is considered a land cover but can indicate different land uses: the grass in a pasture is an agricultural land use, whereas the grass in an urban area can be classified as a park.</p>
</section>
<section id="supervised-classification" class="level3" data-number="5.2.1">
<h3 data-number="5.2.1" class="anchored" data-anchor-id="supervised-classification"><span class="header-section-number">5.2.1</span> Supervised Classification</h3>
<section id="supervised-classification" class="level3">
<h3 class="anchored" data-anchor-id="supervised-classification">Supervised Classification</h3>
<p>If you have not already done so, be sure to add the books code repository to the Code Editor by entering <a href="https://www.google.com/url?q=https://code.earthengine.google.com/?accept_repo%3Dprojects/gee-edu/book&amp;sa=D&amp;source=editors&amp;ust=1671458829866098&amp;usg=AOvVaw16x5swm9HlorS5Mbw7E42X"></a><a href="https://www.google.com/url?q=https://code.earthengine.google.com/?accept_repo%3Dprojects/gee-edu/book&amp;sa=D&amp;source=editors&amp;ust=1671458829866485&amp;usg=AOvVaw0-N-JCWWgnM493BKa7Ichm">https://code.earthengine.google.com/?accept_repo=projects/gee-edu/book</a> into your browser. The books scripts will then be available in the script manager panel. If you have trouble finding the repo, you can visit <a href="https://www.google.com/url?q=https://docs.google.com/presentation/d/1Kt6wGNoesYm__Cu3k3bnlbbyPN6m9SF4hQHK-pIDHfc/edit%23slide%3Did.g18a7b4b055d_0_624&amp;sa=D&amp;source=editors&amp;ust=1671458829866823&amp;usg=AOvVaw0ytMyRvutssBcVr2GdcBHA">this link</a> for help.</p>
<p>Supervised classification uses a training dataset with known labels and representing the spectral characteristics of each land cover class of interest to “supervise” the classification. The overall approach of a supervised classification in Earth Engine is summarized as follows:</p>
<ol type="1">
@@ -801,7 +789,7 @@ Chapter Information
<span id="cb13-21"><a href="#cb13-21" aria-hidden="true" tabindex="-1"></a></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image44.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image44.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.2 Landsat image</figcaption><p></p>
</figure>
</div>
@@ -815,7 +803,7 @@ Chapter Information
<p>In the Geometry Tools, click on the marker option (Fig. F2.1.3). This will create a point geometry which will show up as an import named “geometry”. Click on the gear icon to configure this import.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image22.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image22.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.3 Creating a new layer in the Geometry Imports</figcaption><p></p>
</figure>
</div>
@@ -824,35 +812,35 @@ Chapter Information
<p>Returning to the coloring of the forest points, the hexadecimal value “589400” is a little bit of red, about twice as much green and no blue: the deep green seen in Figure F2.1.4. Enter that value, with or without the “#” in front, and click OK after finishing the configuration.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image36.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image36.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.4 Edit geometry layer properties</figcaption><p></p>
</figure>
</div>
<p>Now, in the Geometry Imports, we will see that the import has been renamed forest. Click on it to activate the drawing mode (Fig. F2.1.5) in order to start collecting forest points.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image29.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image29.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.5 Activate forest layer to start collection</figcaption><p></p>
</figure>
</div>
<p>Now, start collecting points over forested areas (Fig. F2.1.6). Zoom in and out as needed. You can use the satellite basemap to assist you, but the basis of your collection should be the Landsat image. Remember that the more points you collect, the more the classifier will learn from the information you provide. For now, lets set a goal to collect 25 points per class. Click Exit next to Point drawing (Fig. F2.1.5) when finished.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image38.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image38.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.6 Forest points</figcaption><p></p>
</figure>
</div>
<p>Repeat the same process for the other classes by creating new layers (Fig. F2.1.7). Dont forget to import using the FeatureCollection option as mentioned above. For the developed class, collect points over urban areas. For the water class, collect points over the Ligurian Sea, and also look for other bodies of water, like rivers. For the herbaceous class, collect points over agricultural fields. Remember to set the “class” property for each class to its corresponding code (see Table 2.1.1) and click Exit once you finalize collecting points for each class as mentioned above. We will be using the following hexadecimal colors for the other classes: #FF0000 for developed, #1A11FF for water, and #D0741E for herbaceous.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image41.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image41.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.7 New layer option in Geometry Imports</figcaption><p></p>
</figure>
</div>
<p>You should now have four FeatureCollection imports named forest, developed, water, and herbaceous (Fig. F2.1.8).</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image42.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image42.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.8 Example of training points</figcaption><p></p>
</figure>
</div>
@@ -893,14 +881,14 @@ Note
<p>You can check whether the classifierTraining object extracted the properties of interest by printing it and expanding the first feature. You should see the band and class information (Fig. F2.1.9).</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image20.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image20.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.9 Example of extracted band information for one point of class 0 (forest)</figcaption><p></p>
</figure>
</div>
<p>Now we can choose a classifier. The choice of classifier is not always obvious, and there are many options from which to pick — you can quickly expand the ee.Classifier object under Docs to get an idea of how many options we have for image classification. Therefore, we will be testing different classifiers and comparing their results. We will start with a Classification and Regression Tree (CART) classifier, a well-known classification algorithm (Fig. F2.1.10) that has been around for decades.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image25.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image25.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.10 Example of a decision tree for satellite image classification. Values and classes are hypothetical.</figcaption><p></p>
</figure>
</div>
@@ -940,14 +928,14 @@ Note
</ul>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image21.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image21.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.11 CART classification</figcaption><p></p>
</figure>
</div>
<p>For now, we will try another supervised learning classifier that is widely used: Random Forests (RF). The RF algorithm (Breiman 2001, Pal 2005) builds on the concept of decision trees, but adds strategies to make them more powerful. It is called a “forest” because it operates by constructing a multitude of decision trees. As mentioned previously, a decision tree creates the rules which are used to make decisions. A Random Forest will randomly choose features and make observations, build a forest of decision trees and then use the full set of trees to estimate the class. It is a great choice when you do not have a lot of insight about the training data.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image27.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image27.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.12 General concept of Random Forests</figcaption><p></p>
</figure>
</div>
@@ -972,7 +960,7 @@ Note
<p>Inspect the result (Fig. F2.1.13). How does this classified image differ from the CART one? Is the classifications better or worse? Zoom in and out and change the transparency of layers as needed. In Chap. F2.2, you will see more systematic ways to assess what is better or worse, based on accuracy metrics.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image34.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image34.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.13 Random Forest classified image</figcaption><p></p>
</figure>
</div>
@@ -990,8 +978,8 @@ Note
</div>
</div>
</section>
<section id="unsupervised-classification" class="level3" data-number="5.2.2">
<h3 data-number="5.2.2" class="anchored" data-anchor-id="unsupervised-classification"><span class="header-section-number">5.2.2</span> Unsupervised Classification</h3>
<section id="unsupervised-classification" class="level3">
<h3 class="anchored" data-anchor-id="unsupervised-classification">Unsupervised Classification</h3>
<p>In an unsupervised classification, we have the opposite process of supervised classification. Spectral classes are grouped first and then categorized into clusters. Therefore, in Earth Engine, these classifiers are ee.Clusterer objects. They are “self-taught” algorithms that do not use a set of labeled training data (i.e., they are “unsupervised”). You can think of it as performing a task that you have not experienced before, starting by gathering as much information as possible. For example, imagine learning a new language without knowing the basic grammar, learning only by watching a TV series in that language, listening to examples and finding patterns.</p>
<p>Similar to the supervised classification, unsupervised classification in Earth Engine has this workflow:</p>
<ol type="1">
@@ -1015,7 +1003,7 @@ Note
<p>Now we can instantiate a clusterer and train it. As with the supervised algorithms, there are many unsupervised algorithms to choose from. We will use the k-means clustering algorithm, which is a commonly used approach in remote sensing. This algorithm identifies groups of pixels near each other in the spectral space (image x bands) by using an iterative regrouping strategy. We define a number of clusters, k, and then the method randomly distributes that number of seed points into the spectral space. A large sample of pixels is then grouped into its closest seed, and the mean spectral value of this group is calculated. That mean value is akin to a center of mass of the points, and is known as the centroid. Each iteration recalculates the class means and reclassifies pixels with respect to the new means. This process is repeated until the centroids remain relatively stable and only a few pixels change from class to class on subsequent iterations.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image35.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image35.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.14 K-means visual concept</figcaption><p></p>
</figure>
</div>
@@ -1032,7 +1020,7 @@ Note
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image31.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image31.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.1.15 K-means classification</figcaption><p></p>
</figure>
</div>
@@ -1069,8 +1057,8 @@ Note
<p>Witten IH, Frank E, Hall MA, et al (2005) Practical machine learning tools and techniques. In: Data Mining. pp 4</p>
</section>
</section>
<section id="accuracy-assessment-quantifying-classification-quality" class="level2" data-number="5.3">
<h2 data-number="5.3" class="anchored" data-anchor-id="accuracy-assessment-quantifying-classification-quality"><span class="header-section-number">5.3</span> Accuracy Assessment: Quantifying Classification Quality</h2>
<section id="accuracy-assessment-quantifying-classification-quality" class="level2">
<h2 class="anchored" data-anchor-id="accuracy-assessment-quantifying-classification-quality">Accuracy Assessment: Quantifying Classification Quality</h2>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
@@ -1114,8 +1102,8 @@ Chapter Information
<p>In Chap. F2.1, we asked whether the classification results were satisfactory. In remote sensing, the quantification of the answer to that question is called accuracy assessment. In the classification context, accuracy measurements are often derived from a confusion matrix.</p>
<p>In a thorough accuracy assessment, we think carefully about the sampling design, the response design, and the analysis (Olofsson et al.&nbsp;2014). Fundamental protocols are taken into account to produce scientifically rigorous and transparent estimates of accuracy and area, which requires robust planning and time. In a standard setting, we would calculate the number of samples needed for measuring accuracy (sampling design). Here, we will focus mainly on the last step, analysis, by examining the confusion matrix and learning how to calculate the accuracy metrics. This will be done by partitioning the existing data into training and testing sets.</p>
</section>
<section id="quantifying-classification-accuracy-through-a-confusion-matrix" class="level3" data-number="5.3.1">
<h3 data-number="5.3.1" class="anchored" data-anchor-id="quantifying-classification-accuracy-through-a-confusion-matrix"><span class="header-section-number">5.3.1</span> Quantifying Classification Accuracy Through a Confusion Matrix</h3>
<section id="quantifying-classification-accuracy-through-a-confusion-matrix" class="level3">
<h3 class="anchored" data-anchor-id="quantifying-classification-accuracy-through-a-confusion-matrix">Quantifying Classification Accuracy Through a Confusion Matrix</h3>
<p>If you have not already done so, be sure to add the books code repository to the Code Editor by entering <a href="https://www.google.com/url?q=https://code.earthengine.google.com/?accept_repo%3Dprojects/gee-edu/book&amp;sa=D&amp;source=editors&amp;ust=1671458829937499&amp;usg=AOvVaw3qqOwSX_A-Pllh6X3X31q4"></a><a href="https://www.google.com/url?q=https://code.earthengine.google.com/?accept_repo%3Dprojects/gee-edu/book&amp;sa=D&amp;source=editors&amp;ust=1671458829937976&amp;usg=AOvVaw0WioXIhzue8-WoaX4UtabH">https://code.earthengine.google.com/?accept_repo=projects/gee-edu/book</a> into your browser. The books scripts will then be available in the script manager panel. If you have trouble finding the repo, you can visit <a href="https://www.google.com/url?q=https://docs.google.com/presentation/d/1Kt6wGNoesYm__Cu3k3bnlbbyPN6m9SF4hQHK-pIDHfc/edit%23slide%3Did.g18a7b4b055d_0_624&amp;sa=D&amp;source=editors&amp;ust=1671458829938470&amp;usg=AOvVaw2CH8V3-_qV99EcgMxUAaSO">this link</a> for help.</p>
<p>To illustrate some of the basic ideas about classification accuracy, we will revisit the data and location of part of Chap. F2.1, where we tested different classifiers and classified a Landsat image of the area around Milan, Italy. We will name this dataset data. This variable is a FeatureCollection with features containing the “class” values and spectral information of four land cover / land use classes: forest, developed, water, and herbaceous (see Fig. F2.1.8 and Fig. F2.1.9 for a refresher). We will also define a variable, predictionBands, which is a list of bands that will be used for prediction (classification)—the spectral information in the data variable.</p>
<p>Class Values:</p>
@@ -1228,32 +1216,32 @@ Chapter Information
</table>
<p>In this case, the classifier correctly identified 307 forest pixels, wrongly classified 18 non-forest pixels as forest, correctly identified 661 non-forest pixels, and wrongly classified 14 forest pixels as non-forest. Therefore, the classifier was correct 968 times and wrong 32 times. Lets calculate the main accuracy metrics for this example.</p>
<p>The overall accuracy tells us what proportion of the reference data was classified correctly, and is calculated as the total number of correctly identified pixels divided by the total number of pixels in the sample.</p>
<p><img src="../images/F2/image6.png" class="img-fluid"></p>
<p>In this case, the overall accuracy is 96.8%, calculated using (<img src="../images/F2/image7.png" class="img-fluid">.</p>
<p><img src="images/F2/image6.png" class="img-fluid"></p>
<p>In this case, the overall accuracy is 96.8%, calculated using (<img src="images/F2/image7.png" class="img-fluid">.</p>
<p>Two other important accuracy metrics are the producers accuracy and the users accuracy, also referred to as the “recall” and the “precision,” respectively. Importantly, these metrics quantify aspects of per-class accuracy.</p>
<p>The producers accuracy is the accuracy of the map from the point of view of the map maker (the “producer”), and is calculated as the number of correctly identified pixels of a given class divided by the total number of pixels actually in that class. The producers accuracy for a given class tells us the proportion of the pixels in that class that were classified correctly.</p>
<p><img src="../images/F2/image8.png" class="img-fluid"></p>
<p><img src="../images/F2/image9.png" class="img-fluid"></p>
<p>In this case, the producers accuracy for the forest class is 95.6%, calculated using <img src="../images/F2/image10.png" class="img-fluid">). The producers accuracy for the non-forest class is 97.3%, calculated from <img src="../images/F2/image11.png" class="img-fluid">).</p>
<p><img src="images/F2/image8.png" class="img-fluid"></p>
<p><img src="images/F2/image9.png" class="img-fluid"></p>
<p>In this case, the producers accuracy for the forest class is 95.6%, calculated using <img src="images/F2/image10.png" class="img-fluid">). The producers accuracy for the non-forest class is 97.3%, calculated from <img src="images/F2/image11.png" class="img-fluid">).</p>
<p>The users accuracy (also called the “consumers accuracy”) is the accuracy of the map from the point of view of a map user, and is calculated as the number of correctly identified pixels of a given class divided by the total number of pixels claimed to be in that class. The users accuracy for a given class tells us the proportion of the pixels identified on the map as being in that class that are actually in that class on the ground.</p>
<p><img src="../images/F2/image12.png" class="img-fluid"></p>
<p><img src="../images/F2/image13.png" class="img-fluid"></p>
<p>In this case, the users accuracy for the forest class is 94.5%, calculated using <img src="../images/F2/image14.png" class="img-fluid">). The users accuracy for the non-forest class is 97.9%, calculated from <img src="../images/F2/image15.png" class="img-fluid">).</p>
<p><img src="images/F2/image12.png" class="img-fluid"></p>
<p><img src="images/F2/image13.png" class="img-fluid"></p>
<p>In this case, the users accuracy for the forest class is 94.5%, calculated using <img src="images/F2/image14.png" class="img-fluid">). The users accuracy for the non-forest class is 97.9%, calculated from <img src="images/F2/image15.png" class="img-fluid">).</p>
<p>Fig. F2.2.1 helps visualize the rows and columns used to calculate each accuracy.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image43.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image43.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.2.1 Confusion matrix for a binary classification where the classes are “positive” (forest) and “negative” (non-forest), with accuracy metrics</figcaption><p></p>
</figure>
</div>
<p>It is very common to talk about two types of error when addressing remote-sensing classification accuracy: omission errors and commission errors. Omission errors refer to the reference pixels that were left out of (omitted from) the correct class in the classified map. In a two-class system, an error of omission in one class will be counted as an error of commission in another class. Omission errors are complementary to the producers accuracy.</p>
<p><img src="../images/F2/image16.png" class="img-fluid"></p>
<p><img src="images/F2/image16.png" class="img-fluid"></p>
<p>Commission errors refer to the class pixels that were erroneously classified in the map and are complementary to the users accuracy.</p>
<p><img src="../images/F2/image17.png" class="img-fluid"></p>
<p><img src="images/F2/image17.png" class="img-fluid"></p>
<p>Finally, another commonly used accuracy metric is the kappa coefficient, which evaluates how well the classification performed as compared to random. The value of the kappa coefficient can range from 1 to 1: a negative value indicates that the classification is worse than a random assignment of categories would have been; a value of 0 indicates that the classification is no better or worse than random; and a positive value indicates that the classification is better than random.</p>
<p><img src="../images/F2/image18.png" class="img-fluid"></p>
<p><img src="images/F2/image18.png" class="img-fluid"></p>
<p>The chance agreement is calculated as the sum of the product of row and column totals for each class, and the observed accuracy is the overall accuracy. Therefore, for our example, the kappa coefficient is 0.927.</p>
<p><img src="../images/F2/image19.png" class="img-fluid"></p>
<p><img src="images/F2/image19.png" class="img-fluid"></p>
<p>Now, lets go back to the script. In Earth Engine, there are API calls for these operations. Note that our confusion matrix will be a 4 x 4 table, since we have four different classes.</p>
<p>Copy and paste the code below to classify the testingSet and get a confusion matrix using the method errorMatrix. Note that the classifier automatically adds a property called “classification,” which is compared to the “class” property of the reference dataset.</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Now, to test the classification (verify model's accuracy), </span></span>
@@ -1286,8 +1274,8 @@ Note
</div>
</div>
</section>
<section id="hyperparameter-tuning" class="level3" data-number="5.3.2">
<h3 data-number="5.3.2" class="anchored" data-anchor-id="hyperparameter-tuning"><span class="header-section-number">5.3.2</span> Hyperparameter tuning</h3>
<section id="hyperparameter-tuning" class="level3">
<h3 class="anchored" data-anchor-id="hyperparameter-tuning">Hyperparameter tuning</h3>
<p>We can also assess how the number of trees in the Random Forest classifier affects the classification accuracy. Copy and paste the code below to create a function that charts the overall accuracy versus the number of trees used. The code tests from 5 to 100 trees at increments of 5, producing Fig. F2.2.2. (Do not worry too much about fully understanding each item at this stage of your learning. If you want to find out how these operations work, you can see more in Chaps. F4.0 and F4.1.)</p>
<div class="sourceCode" id="cb26"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Hyperparameter tuning. </span></span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> numTrees <span class="op">=</span> ee<span class="op">.</span><span class="at">List</span><span class="op">.</span><span class="fu">sequence</span>(<span class="dv">5</span><span class="op">,</span> <span class="dv">100</span><span class="op">,</span> <span class="dv">5</span>)<span class="op">;</span> </span>
@@ -1317,7 +1305,7 @@ Note
<span id="cb26-26"><a href="#cb26-26" aria-hidden="true" tabindex="-1"></a></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F2/image45.png" class="img-fluid figure-img"></p>
<p><img src="images/F2/image45.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F2.2.2 Chart showing accuracy per number of Random Forest trees</figcaption><p></p>
</figure>
</div>
@@ -1719,12 +1707,12 @@ window.document.addEventListener("DOMContentLoaded", function (event) {
<nav class="page-navigation">
<div class="nav-page nav-page-previous">
<a href="./B1_Getting_Started.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Getting Started</span></span>
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-title">Getting Started</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="./B3_Image_Series.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Image Series</span></span> <i class="bi bi-arrow-right-short"></i>
<span class="nav-page-text"><span class="chapter-title">Image Series</span></span> <i class="bi bi-arrow-right-short"></i>
</a>
</div>
</nav>