Link Search Menu Expand Document

Tutorial 10

Grey-level Thresholding

var geometry = /* color: #d63000 */ee.Geometry.Point([-76.13999022733348, 43.044037608951704]);

//Import a top-of-atmosphere reflectance Landsat 5 image.
var image = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015030_20100531');

//Center map display on Syracuse with a zoom level of 12
Map.setCenter(-76.1467, 43.0458,12);  

//Display image as color infrared composite.
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], max: 0.5}, 'input image'); 

//Define a study area that captures Onondaga Lake and the surrounding area
var studyarea = ee.Geometry.Rectangle(-76.454, 43.692,-76.40, 42.82);

//Select out the NIR band from the input image
var NIRband = image.select('B4');

//Create a histogram of the spectral response in the NIR band using the geometry identified
var histogram2 = ui.Chart.image.histogram(NIRband, studyarea);

// Display the histogram.
print(histogram2);

//Create a binary mask to filter out water based on the reflectance information 
var watermask = NIRband.gte(0.07);

//Use the water mask to create an image with water pixels removed.
var nowaterimage= image.updateMask(watermask);

//Display the output water-masked image using a CIR composite
Map.addLayer(nowaterimage, {bands: ['B4', 'B3', 'B2'], max: 0.5}, 'water-masked'); 

##Level Slicing

var geometry = /* color: #d63000 */ee.Geometry.Point([-76.13999022733348, 43.044037608951704]);

//Load and display a top-of-atmosphere reflectance Landsat 5 image 
var image = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015030_20100531');

//Center map display on Syracuse with a zoom level of 12
Map.setCenter(-76.1467, 43.0458,12);  

//Display image as color infrared composite.
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], max: 0.5}, 'input image'); 

//Create an NDWI image using band 4 (NIR) and 5 (mid-IR) from the selected Landsat 5 image, 
var ndwi = image.normalizedDifference(['B4', 'B5']); //create a NDWI image 

/*Create an image visualization parameter to recolor the NDWI image based on pixels values:
  NDWI =< 0, display as white (FFFFFF color)
  NDWI > 0 & < 0.5, display in cyan (00FFFF color)
  NDWI >=0.5 & =< 1, display as blue (0000FF color)
Higher NDWI suggest higher water content, the three slices are represented with different colors that show no water content, low water content and high water content pixels.*/
var ndwislices = ndwi.expression(
    "(b('nd') < 0) ? 3" + //nd refer to the values of each pixel in the NDWI image
      ": (b('nd') < 0.5) ? 2" +
        ": (b('nd') < 1) ? 1" +
          ": 0"
);

//Display final image based on level sliced image.
Map.addLayer(ndwislices,
            {min: 0, max: 3, palette: ["0000FF","00FFFF","FFFFFF"]},
            'NDWI Slices');

Image Convolution

var geometry = /* color: #d63000 */ee.Geometry.Point([-76.13999022733348, 43.044037608951704]);

//Load and display a top-of-atmosphere reflectance Landsat 5 image 
var image = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015030_20100531');

//Center map display on Syracuse with a zoom level of 12
Map.setCenter(-76.1467, 43.0458,12);  

//Display image as color infrared composite.
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], max: 0.5}, 'input image'); 

/*Define a low-pass kernel.  This kernel creates a 7x7 square, the normalize parameter means the sum of values in the kernel will be 1 */
var lowpass = ee.Kernel.square({radius: 7, units: 'pixels', normalize: true});

//Smooth the image by convolving with the low-pass kernel.
var smooth = image.convolve(lowpass);
Map.addLayer(smooth, {bands: ['B4', 'B3', 'B2'], max: 0.5}, 'smoothed');