I am working on the nature of deforestation in the Philippines using the Global Forest Change (GFC) dataset of Hansen et al. (2013). I am trying to depict all connected pixels that has a minimum forest clearing of 5 hectares, which is approximately 56 pixels. First problem is that when I change the resolution of the map dashboard of the GEE, it seems that patches measuring below the 56 pixels slowly shows as I enlarge the image. One solution I found over the internet is to convert the projection into a nominal projection. However, this does not work well as I encountered a problem saying that the number of pixels requested from that variable exceeded the maximum allowed (2^31). I also attach the code that I made so that it would be convenient to comment down below.

var gfc2019: Image "Hansen Global Forest Change v 1.7 (2000-2019)"
var cc = ee.Number (30);
var pixels = ee.Number (6);
var lossPixels = ee.Number (56);
var forest = gfc2019.select (['treecover2000']);
var minCanopy = forest.gte(cc).selfMask ();
var contArea = minCanopy.connectedPixelCount ();
var minForest  = contArea.gte (pixels).selfMask();

var treeLoss = gfc2019.select (['lossyear']);
var treeLoss01 = treeLoss.eq(14).selfMask ();
var minLoss01 = minForest.and(treeLoss01).rename ('Forest loss in 01').selfMask ();
var contLoss = minLoss01.connectedPixelCount();
var largeLoss01 = contLoss.gte(lossPixels).selfMask();

var prj = gfc2019.projection();
var scale = prj.nominalScale();

Map.addLayer (minForest,{palette: ['green']}, 'Forest');
Map.addLayer (largeLoss01.reproject(prj.atScale(scale)),
{palette: ['red']}, 'Large Scale Loss');

1 Answer 1


It's not recommended to mask object using connected pixel count, because the connected pixel count is dependent on zoom level. When you zoom in to a finer level, the connected pixel count of each patches will multiply as pixel size is smaller. You should use area criteria to mask small objects.

The code below is quoted from the official tutorial on object-oriented analysis. It tells you how to mask small-size object using area criteria.

// Get a pixel area image.
var pixelArea = ee.Image.pixelArea();

// Multiply pixel area by the number of pixels in an object to calculate
// the object area. The result is an image where each pixel
// of an object relates the area of the object in m^2.
var objectArea = objectSize.multiply(pixelArea);

// Display object area to the Map.
             {min: 0, max: 30000, palette: ['0000FF', 'FF00FF']},
             'Object area m^2');
// Threshold the `objectArea` image to define a mask that will mask out
// objects below a given size (1 hectare in this case).
var areaMask = objectArea.gte(10000);

// Update the mask of the `objectId` layer defined previously using the
// minimum area mask just defined.
objectId = objectId.updateMask(areaMask);
Map.addLayer(objectId, null, 'Large hotspots');

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.