current position:Home>GEE(9): Area area statistics (using connectedPixelCount and ee.Image.pixelArea())

GEE(9): Area area statistics (using connectedPixelCount and ee.Image.pixelArea())

2022-08-06 08:54:46BetterQ.

在GEE(Google Earth Engine)in if you want to filter the area as needed,and calculate the area of ​​the area,可以使用connectedPixelCountee.Image.pixelArea()来进行计算.

connectedPixelCount:生成一个图像,where each pixel contains 4 或 8 Pixels in the field(包括其自身)的数量,4Neighborhood is an object of edge neighborhoods,8Neighborhoods include objects in edge and corner neighborhoods.

ee.Image.pixelArea():Returns the area of ​​a single pixel.

connectedPixelCountee.Image.pixelArea()The product of the two is the statistical area of ​​the region.
The implementation code is described below:

1. First load the temperature data,and filter for greater than303的数据,The temperature data here is in Kelvin

// Make an area of interest geometry centered on San Francisco.
var point = ee.Geometry.Point(-122.1899, 37.5010);
var aoi = point.buffer(10000);

// Import a Landsat 8 image, subset the thermal band, and clip to the
// area of interest.
var kelvin = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318')
  .select(['B10'], ['kelvin'])

// Display the thermal band.
Map.centerObject(point, 13);
Map.addLayer(kelvin, {
    min: 288, max: 305}, 'Kelvin');

// Threshold the thermal band to set hot pixels as value 1, mask all else.
var hotspots =

// Display the thermal hotspots on the Map.
Map.addLayer(hotspots, {
    palette: 'FF0000'}, 'Hotspots');


2.使用connectedPixelCountCount the number of pixels in the filtered area

// Compute the number of pixels in each object defined by the "labels" band.
var objectSize = hotspots
    maxSize: 128, eightConnected: false

// Display object pixel count to the Map.
Map.addLayer(objectSize, null, 'Object n pixels');


3.Calculates the area of ​​the filtered area,单位为㎡

// 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');

4.Filters areas based on the size of the calculated area value

// 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');

小结:connectedPixelCountThis function is mainly used in situations like the above,What is returned is an image,Contains the number of adjacent pixels for each pixel,参数中的maxSize refers to the maximum value of each pixel's neighborhood,可根据需要进行设置.Commonly used, for example, to filter out areas based on reflectivity or other factors,The area of ​​the area you want to count;Or after filtering out the area,The regions into patches are further filtered according to the value of the number of pixel neighborhoods,That is, the area with high connectivity,This method is also commonly used in the extraction of water bodies.

copyright notice
author[BetterQ.],Please bring the original link to reprint, thank you.

Random recommended