I am looking at object oriented methods and wondered if there was a way of calculating image zone statistics (zonal stats) based on connected pixels. Essentially, I want to reduce the pixels in an independent image (eg. Sentinel-1) by the image object in a connected pixels image.

For example, I have a binary image (1m res) that I turn into objects using connected pixels and remove objects below 100 pixels:

// Convert to objects
var patchsize = InFile.connectedPixelCount(256,false).reproject({crs:'EPSG:4326',scale:1})
Map.addLayer(patchsize, {}, 'patch size');

// Remove small objects
var PatchMask = patchsize.gt(100)
Map.addLayer(PatchMask, {}, 'patch mask');

var FinalSegs = InFile.updateMask(PatchMask)

I also create monthly mean Sentinel-1 images using the following code:

var sentinel1 = ee.ImageCollection("COPERNICUS/S1_GRD");

var months = ee.List.sequence(1, 12);

var byMonth = ee.ImageCollection.fromImages(
      months.map(function (m) {
    return sentinel1
    // Filter to get images with VV and VH dual polarization.
    .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
   // Filter to get images collected in interferometric wide swath mode.
    .filter(ee.Filter.eq('instrumentMode', 'IW'))
  //clip to bangladesh
    .filter(ee.Filter.calendarRange(m, m, 'month'))
                .set('month', m);

I would ideally like to reduce the pixels in the Sentinel-1 images (12 mean images) using the objects the connected pixels. I presume the output would be a 12 band image where each object has the mean backscatter value for each connected pixel. Is this possible in EE?

A badly drawn example of this would like the following image: enter image description here

1 Answer 1


I found the answer to this here, which uses a recent script by Noel Gorelick.

The lines of code required to do what I want are:

img = byMonth.mean()

var MeanImage = img.addBands(FinalSegs).reduceConnectedComponents(ee.Reducer.mean(), 'segs', 256)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.