My objective is to count the number of pixel identified as water from a collection of landsat images. The following function masks out non-water area for each image in the image collection, it also add a new band called 'NDWI' to each image:
var landsat8= ee.ImageCollection('LANDSAT/LC8_L1T_TOA').filterBounds(geometry)
var waterThreshold = 0;
// water function:
var waterfunction = function(image){
//add the NDWI band to the image
var ndwi = image.normalizedDifference(['B3', 'B6']).rename('NDWI');
//isolate the water likelihood band
var quality = ndwi.select('NDWI');
//get pixels above the threshold
var water01 = quality.gt(waterThreshold);
//create a mask from high likelihood pixels
var watermask = image.mask().and(water01 );
//mask those pixels from the image
return image.updateMask(watermask).addBands(ndwi);
};
var collection= landsat8.map(waterfunction);
Could you help me do the next steps?
- Count how many pixel identified as water (band NDWI >0) in each image within the polygon called "geometry" and then calculate the water area. Pixel scale = 30 (m)
- Print a time series of (1)
I know the cloud could be a problem, and we should clean it first, but leave it like this for now.