Anuncio: Todos los proyectos no comerciales registrados para usar Earth Engine antes del
15 de abril de 2025 deben
verificar su elegibilidad no comercial para mantener el acceso a Earth Engine.
ee.ImageCollection.count
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Reduce una colección de imágenes calculando la cantidad de imágenes con una máscara válida en cada píxel de la pila de todas las bandas coincidentes. Las bandas coinciden por nombre.
Uso | Muestra |
---|
ImageCollection.count() | Imagen |
Argumento | Tipo | Detalles |
---|
esta: collection | ImageCollection | Es la colección de imágenes que se reducirá. |
Ejemplos
Editor de código (JavaScript)
// Sentinel-2 image collection for July 2021 intersecting a point of interest.
// Reflectance, cloud probability, and scene classification bands are selected.
var col = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2021-07-01', '2021-08-01')
.filterBounds(ee.Geometry.Point(-122.373, 37.448))
.select('B.*|MSK_CLDPRB|SCL');
// Visualization parameters for reflectance RGB.
var visRefl = {
bands: ['B11', 'B8', 'B3'],
min: 0,
max: 4000
};
Map.setCenter(-122.373, 37.448, 9);
Map.addLayer(col, visRefl, 'Collection reference', false);
// Reduce the collection to a single image using a variety of methods.
var mean = col.mean();
Map.addLayer(mean, visRefl, 'Mean (B11, B8, B3)');
var median = col.median();
Map.addLayer(median, visRefl, 'Median (B11, B8, B3)');
var min = col.min();
Map.addLayer(min, visRefl, 'Min (B11, B8, B3)');
var max = col.max();
Map.addLayer(max, visRefl, 'Max (B11, B8, B3)');
var sum = col.sum();
Map.addLayer(sum,
{bands: ['MSK_CLDPRB'], min: 0, max: 500}, 'Sum (MSK_CLDPRB)');
var product = col.product();
Map.addLayer(product,
{bands: ['MSK_CLDPRB'], min: 0, max: 1e10}, 'Product (MSK_CLDPRB)');
// ee.ImageCollection.mode returns the most common value. If multiple mode
// values occur, the minimum mode value is returned.
var mode = col.mode();
Map.addLayer(mode, {bands: ['SCL'], min: 1, max: 11}, 'Mode (pixel class)');
// ee.ImageCollection.count returns the frequency of valid observations. Here,
// image pixels are masked based on cloud probability to add valid observation
// variability to the collection. Note that pixels with no valid observations
// are masked out of the returned image.
var notCloudCol = col.map(function(img) {
return img.updateMask(img.select('MSK_CLDPRB').lte(10));
});
var count = notCloudCol.count();
Map.addLayer(count, {min: 1, max: 5}, 'Count (not cloud observations)');
// ee.ImageCollection.mosaic composites images according to their position in
// the collection (priority is last to first) and pixel mask status, where
// invalid (mask value 0) pixels are filled by preceding valid (mask value >0)
// pixels.
var mosaic = notCloudCol.mosaic();
Map.addLayer(mosaic, visRefl, 'Mosaic (B11, B8, B3)');
Configuración de Python
Consulta la página
Entorno de Python para obtener información sobre la API de Python y el uso de geemap
para el desarrollo interactivo.
import ee
import geemap.core as geemap
Colab (Python)
# Sentinel-2 image collection for July 2021 intersecting a point of interest.
# Reflectance, cloud probability, and scene classification bands are selected.
col = (
ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2021-07-01', '2021-08-01')
.filterBounds(ee.Geometry.Point(-122.373, 37.448))
.select('B.*|MSK_CLDPRB|SCL')
)
# Visualization parameters for reflectance RGB.
vis_refl = {'bands': ['B11', 'B8', 'B3'], 'min': 0, 'max': 4000}
m = geemap.Map()
m.set_center(-122.373, 37.448, 9)
m.add_layer(col, vis_refl, 'Collection reference', False)
# Reduce the collection to a single image using a variety of methods.
mean = col.mean()
m.add_layer(mean, vis_refl, 'Mean (B11, B8, B3)')
median = col.median()
m.add_layer(median, vis_refl, 'Median (B11, B8, B3)')
min = col.min()
m.add_layer(min, vis_refl, 'Min (B11, B8, B3)')
max = col.max()
m.add_layer(max, vis_refl, 'Max (B11, B8, B3)')
sum = col.sum()
m.add_layer(
sum, {'bands': ['MSK_CLDPRB'], 'min': 0, 'max': 500}, 'Sum (MSK_CLDPRB)'
)
product = col.product()
m.add_layer(
product,
{'bands': ['MSK_CLDPRB'], 'min': 0, 'max': 1e10},
'Product (MSK_CLDPRB)',
)
# ee.ImageCollection.mode returns the most common value. If multiple mode
# values occur, the minimum mode value is returned.
mode = col.mode()
m.add_layer(
mode, {'bands': ['SCL'], 'min': 1, 'max': 11}, 'Mode (pixel class)'
)
# ee.ImageCollection.count returns the frequency of valid observations. Here,
# image pixels are masked based on cloud probability to add valid observation
# variability to the collection. Note that pixels with no valid observations
# are masked out of the returned image.
not_cloud_col = col.map(
lambda img: img.updateMask(img.select('MSK_CLDPRB').lte(10))
)
count = not_cloud_col.count()
m.add_layer(count, {'min': 1, 'max': 5}, 'Count (not cloud observations)')
# ee.ImageCollection.mosaic composites images according to their position in
# the collection (priority is last to first) and pixel mask status, where
# invalid (mask value 0) pixels are filled by preceding valid (mask value >0)
# pixels.
mosaic = not_cloud_col.mosaic()
m.add_layer(mosaic, vis_refl, 'Mosaic (B11, B8, B3)')
m
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-07-26 (UTC)
[null,null,["Última actualización: 2025-07-26 (UTC)"],[[["\u003cp\u003e\u003ccode\u003eImageCollection.count()\u003c/code\u003e reduces an image collection by calculating the number of images with valid data at each pixel location.\u003c/p\u003e\n"],["\u003cp\u003eBands with the same name are matched across images within the collection for the calculation.\u003c/p\u003e\n"],["\u003cp\u003ePixels with no valid observations are masked out in the resulting image.\u003c/p\u003e\n"],["\u003cp\u003eThe output is a single image where pixel values represent the count of valid observations.\u003c/p\u003e\n"]]],["The `ImageCollection.count()` method reduces an image collection into a single image by counting the number of images with a valid mask at each pixel, across all matching bands. Bands are matched by name. It returns an image where each pixel's value represents the frequency of valid observations at that location. An example in the provided code uses this method to count cloud-free observations. The collection can be reduced by a variety of methods.\n"],null,["# ee.ImageCollection.count\n\nReduces an image collection by calculating the number of images with a valid mask at each pixel across the stack of all matching bands. Bands are matched by name.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|---------------------------|---------|\n| ImageCollection.count`()` | Image |\n\n| Argument | Type | Details |\n|--------------------|-----------------|---------------------------------|\n| this: `collection` | ImageCollection | The image collection to reduce. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// Sentinel-2 image collection for July 2021 intersecting a point of interest.\n// Reflectance, cloud probability, and scene classification bands are selected.\nvar col = ee.ImageCollection('COPERNICUS/S2_SR')\n .filterDate('2021-07-01', '2021-08-01')\n .filterBounds(ee.Geometry.Point(-122.373, 37.448))\n .select('B.*|MSK_CLDPRB|SCL');\n\n// Visualization parameters for reflectance RGB.\nvar visRefl = {\n bands: ['B11', 'B8', 'B3'],\n min: 0,\n max: 4000\n};\nMap.setCenter(-122.373, 37.448, 9);\nMap.addLayer(col, visRefl, 'Collection reference', false);\n\n// Reduce the collection to a single image using a variety of methods.\nvar mean = col.mean();\nMap.addLayer(mean, visRefl, 'Mean (B11, B8, B3)');\n\nvar median = col.median();\nMap.addLayer(median, visRefl, 'Median (B11, B8, B3)');\n\nvar min = col.min();\nMap.addLayer(min, visRefl, 'Min (B11, B8, B3)');\n\nvar max = col.max();\nMap.addLayer(max, visRefl, 'Max (B11, B8, B3)');\n\nvar sum = col.sum();\nMap.addLayer(sum,\n {bands: ['MSK_CLDPRB'], min: 0, max: 500}, 'Sum (MSK_CLDPRB)');\n\nvar product = col.product();\nMap.addLayer(product,\n {bands: ['MSK_CLDPRB'], min: 0, max: 1e10}, 'Product (MSK_CLDPRB)');\n\n// ee.ImageCollection.mode returns the most common value. If multiple mode\n// values occur, the minimum mode value is returned.\nvar mode = col.mode();\nMap.addLayer(mode, {bands: ['SCL'], min: 1, max: 11}, 'Mode (pixel class)');\n\n// ee.ImageCollection.count returns the frequency of valid observations. Here,\n// image pixels are masked based on cloud probability to add valid observation\n// variability to the collection. Note that pixels with no valid observations\n// are masked out of the returned image.\nvar notCloudCol = col.map(function(img) {\n return img.updateMask(img.select('MSK_CLDPRB').lte(10));\n});\nvar count = notCloudCol.count();\nMap.addLayer(count, {min: 1, max: 5}, 'Count (not cloud observations)');\n\n// ee.ImageCollection.mosaic composites images according to their position in\n// the collection (priority is last to first) and pixel mask status, where\n// invalid (mask value 0) pixels are filled by preceding valid (mask value \u003e0)\n// pixels.\nvar mosaic = notCloudCol.mosaic();\nMap.addLayer(mosaic, visRefl, 'Mosaic (B11, B8, B3)');\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# Sentinel-2 image collection for July 2021 intersecting a point of interest.\n# Reflectance, cloud probability, and scene classification bands are selected.\ncol = (\n ee.ImageCollection('COPERNICUS/S2_SR')\n .filterDate('2021-07-01', '2021-08-01')\n .filterBounds(ee.Geometry.Point(-122.373, 37.448))\n .select('B.*|MSK_CLDPRB|SCL')\n)\n\n# Visualization parameters for reflectance RGB.\nvis_refl = {'bands': ['B11', 'B8', 'B3'], 'min': 0, 'max': 4000}\nm = geemap.Map()\nm.set_center(-122.373, 37.448, 9)\nm.add_layer(col, vis_refl, 'Collection reference', False)\n\n# Reduce the collection to a single image using a variety of methods.\nmean = col.mean()\nm.add_layer(mean, vis_refl, 'Mean (B11, B8, B3)')\n\nmedian = col.median()\nm.add_layer(median, vis_refl, 'Median (B11, B8, B3)')\n\nmin = col.min()\nm.add_layer(min, vis_refl, 'Min (B11, B8, B3)')\n\nmax = col.max()\nm.add_layer(max, vis_refl, 'Max (B11, B8, B3)')\n\nsum = col.sum()\nm.add_layer(\n sum, {'bands': ['MSK_CLDPRB'], 'min': 0, 'max': 500}, 'Sum (MSK_CLDPRB)'\n)\n\nproduct = col.product()\nm.add_layer(\n product,\n {'bands': ['MSK_CLDPRB'], 'min': 0, 'max': 1e10},\n 'Product (MSK_CLDPRB)',\n)\n\n# ee.ImageCollection.mode returns the most common value. If multiple mode\n# values occur, the minimum mode value is returned.\nmode = col.mode()\nm.add_layer(\n mode, {'bands': ['SCL'], 'min': 1, 'max': 11}, 'Mode (pixel class)'\n)\n\n# ee.ImageCollection.count returns the frequency of valid observations. Here,\n# image pixels are masked based on cloud probability to add valid observation\n# variability to the collection. Note that pixels with no valid observations\n# are masked out of the returned image.\nnot_cloud_col = col.map(\n lambda img: img.updateMask(img.select('MSK_CLDPRB').lte(10))\n)\ncount = not_cloud_col.count()\nm.add_layer(count, {'min': 1, 'max': 5}, 'Count (not cloud observations)')\n\n# ee.ImageCollection.mosaic composites images according to their position in\n# the collection (priority is last to first) and pixel mask status, where\n# invalid (mask value 0) pixels are filled by preceding valid (mask value \u003e0)\n# pixels.\nmosaic = not_cloud_col.mosaic()\nm.add_layer(mosaic, vis_refl, 'Mosaic (B11, B8, B3)')\nm\n```"]]