I am working on a code to detect/count the patches of burned areas in an image. I thought using the function connectedPixelCount() in GEE would help me in doing so. However, the latter seems to not work with composite images. Is there a way to make it perceive the composite image as a typical one layer image? (If there is an alternative function for composites, that would solve my issue too)


var country = ['ZA'];
var geometry = ee.FeatureCollection('USDOS/LSIB/2013')
                      .filter(ee.Filter.inList('cc', country));
Map.centerObject(geometry, 5);

var modisFire = ee.ImageCollection('MODIS/006/MCD64A1')
                  .map(function(image) { return image.clip(geometry);})
                  .filter(ee.Filter.date('2017-06-01', '2017-08-31'))

var date = ee.Date('2017-06-01');
var composite = modisFire.mean().set('system:time_start', date.millis(), 
                                     'dateYMD', date.format('YYYY-MM-dd'), 
                                      'numbImages', modisFire.size());

var img = ee.Image(modisFire.toList(3).get(0));
var img1 = ee.Image(composite);

Map.addLayer(img, {palette: 'red'}, 'June Fire');
Map.addLayer(img, {palette: 'orange'}, 'Summer Fire');

var patches = img1.connectedPixelCount(5, false);
patches = patches.updateMask(patches.gte(5));
Map.addLayer(patches, {palette: 'blue'}, 'Burned Area');

1 Answer 1


Your error message give you a hint of what's wrong:

Burned Area: Layer error: Image.connectedPixelCount: Segment size calculation on floating point bands is not supported. Unsupported type: Type>.

Your img is int16, while img1 is double. If you cast img1 to int16, you should be good:

var patches = img1.int16().connectedPixelCount(5, false);
  • thanks for the help!
    – farhat
    Apr 20, 2020 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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