Layers
Welcome to the composite layers module!
In this module, we will explore the powerful concept of composite layers and how they can be used to add multiple bands to a single map. This technique will allow us to create composite maps that reveal fascinating and detailed information about the world around us.
We will examine the difference between true-color and false-color composites - while the former uses the red, green, and blue bands to show images as the human eye would see them, the latter uses these bands to display visualizations of non-visible bands. Along the way, we will also learn to adjust the opacity of a layer and toggle its visibility. With these new skills and tools at our disposal, we're ready to take our mapping game to the next layer!
“Ogres have layers. Onions have layers.
You get it? We both have layers. ”
Visualizing an Image
Let’s add two more bands to the map we made in Training 1.
Map.addLayer( first_image, //dataset to display { bands: ['SR_B2'], //band to display min: 8000, //display range max: 17000 }, 'Layer 2', //name to show in layer manager 0, //shown 1 //opacity ); Map.addLayer( first_image, //dataset to display { bands: ['SR_B3'], //band to display min: 8000, //display range max: 17000 }, 'Layer 3', //name to show in layer manager 1, //shown 0 //opacity );
In the code above, notice that we included two additional parameters to the Map.addLayer function. One parameter controls whether or not the layer is shown on the screen when the layer is drawn. It may be either 1 (shown) or 0 (not shown). The other parameter defines the opacity of the layer, or your ability to “see through” the map layer. The opacity value can range between 0 (transparent) and 1 (opaque).
Since we set the shown parameter to 0 for layer 2 and the opacity to 0 for layer 3, neither layer is visible to us when we run the code! Use the Layers manager on the map to make layer 2 visible and adjust layer 3's opacity.
You've created a stack of satellite images. Note how the ordering of operations in your script affects the layering order on the map.
True-color composite images
Using the controls in the Layers manager, explore the layers and examine how the pixel values in each band differ. We can use color to compare these visual differences in the pixel values of each band layer all at once as an RGB composite. This method uses the three primary colors (red, green, and blue) to display each pixel’s values across three bands.
The image that this code creates is called a natural-color composite because it looks like any image we're used to seeing in our world! We specified the pairing simply through the order of the bands in the list: B3, B2, B1 because bands 3, 2, and 1 of Landsat 5 correspond to the real-world colors of red, green, and blue.
Map.addLayer( first_image, { bands: ['SR_B3','SR_B2','SR_B1'], min: 8000, max: 17000 }, 'Natural Color');
False-color composites
As you saw when you printed the band list, a Landsat image contains many more bands than just the three true-color bands. We can make RGB composites to show combinations of any of the bands—even those outside what the human eye can see. For example, band 4 represents the near-infrared band, just outside the range of human vision. Because of its value in distinguishing environmental conditions, this band was included on even the earliest 1970s Landsats. It has different values in coniferous and deciduous forests, for example, and can indicate crop health. To see an example of this, add this code to your script and run it.
This creates an image called a false-color composite because it takes bands outside of the human's visible spectrum and displays them on our visible spectrum (infrared to RGB for example). This particular example is a scene that we could not observe with our eyes, but that you can learn to read and interpret. Its meaning can be deciphered logically by thinking through what is passed to the red, green, and blue color channels.
Map.addLayer( first_image, { bands: ['SR_B4','SR_B3','SR_B2'], min: 8000, max: 17000 }, 'False Color');
Notice how the land on the northern peninsula appears bright red (area A). This is because for that area, the pixel value of the first band (which is drawing the near-infrared brightness) is much higher relative to the pixel value of the other two bands. You can check this by using the Inspector tool. Try zooming into a part of the image with a red patch (area B) and clicking on a pixel that appears red. Then expand the “False Color” layer in the Inspector panel, click the blue icon next to the layer name and read the pixel value for the three bands of the composite. The pixel value for B4 should be much greater than for B3 or B2.
Examine other areas similarly for other parts of the image. Look at the dark blue spots in the bottom corner of the false-color composite (area C). Which band has the greatest pixel value here? How can you interpret this?
More false-color composites
In total, the false-color composite provides more contrast than the true-color image for understanding differences across the scene. This suggests that other bands might contain more useful information as well. We saw earlier that our satellite image consisted of 19 bands. Six of these represent different portions of the electromagnetic spectrum, including three beyond the visible spectrum, that can be used to make different false-color composites. Use the code below to explore a composite that shows shortwave infrared, near infrared, and visible green.
The code below can be used to inspire you to try many combinations of different bands - don't limit yourself to just the ones shown above!
You should notice that bright red locations in the first composite appear bright green in the second composite. Why do you think that is? Does the image on the right show new distinctions not seen in the image on the left? If so, what do you think they are?
Map.addLayer( first_image, { bands: ['SR_B5','SR_B4','SR_B2'], min: 8000, max: 17000 }, 'Short-wave False Color');
Recap
Here’s what we learned in this module:
We can add multiple bands to a map layer by passing the “bands” argument as a vector of band names in the Map.addLayer function
These layers with multiple bands are called composites
True-color composites use the red, green, and blue bands and appear as the human eye would see the image
False-color composites use red, green, and blue to visualize bands that aren’t actually visible to the human eye.
New code elements:
We can adjust the opacity of a layer and whether the layer is shown or not when we run our code by adding a 0 or 1 argument to the Map.addLayer function