公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.Algorithms.Image.Segmentation.SNIC
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
基于 SNIC(简单非迭代聚类)的超像素聚类。针对每个输入频段,输出一个聚类 ID 频段以及每个聚类的平均值。如果未将“种子”图片作为输入提供,则输出将包含一个“种子”波段,其中包含生成的种子位置。请参阅:Achanta, Radhakrishna 和 Susstrunk, Sabine,“Superpixels and Polygons using Simple Non-Iterative Clustering”,CVPR,2017 年。
用法 | 返回 |
---|
ee.Algorithms.Image.Segmentation.SNIC(image, size, compactness, connectivity, neighborhoodSize, seeds) | 图片 |
参数 | 类型 | 详细信息 |
---|
image | 图片 | 用于聚类的输入图片。 |
size | 整数,默认值:5 | 超像素种子位置间距(以像素为单位)。如果提供了“种子”图片,则不会生成网格。 |
compactness | 浮点数,默认值:1 | 紧凑性因子。值越大,聚类就越紧凑(方形)。将此值设置为 0 可停用空间距离加权。 |
connectivity | 整数,默认值:8 | 连接。4 或 8。 |
neighborhoodSize | 整数,默认值:null | 平铺邻域大小(以避免平铺边界伪影)。默认值为 2 * size。 |
seeds | 图片,默认值:null | 如果提供,则任何非零值像素都将用作种子位置。接触(如“连通性”所指定)的像素被视为属于同一聚类。 |
示例
代码编辑器 (JavaScript)
// Note that the compactness and size parameters can have a significant impact
// on the result. They must be adjusted to meet image-specific characteristics
// and patterns, typically through trial. Pixel scale (map zoom level) is also
// important to consider. When exploring interactively through map tile
// visualization, the segmentation result it dependent on zoom level. If you
// need to evaluate the result at a specific scale, call .reproject() on the
// result, but do so with caution because it overrides the default scaling
// behavior that makes tile computation fast and efficient.
// Load a NAIP image for a neighborhood in Las Vegas.
var naip = ee.Image('USDA/NAIP/DOQQ/m_3611554_sw_11_1_20170613');
// Apply the SNIC algorithm to the image.
var snic = ee.Algorithms.Image.Segmentation.SNIC({
image: naip,
size: 30,
compactness: 0.1,
connectivity: 8,
});
// Display the original NAIP image as RGB.
// Lock map zoom to maintain the desired scale of the segmentation computation.
Map.setLocked(false, 18, 18);
Map.setCenter(-115.32053, 36.182016, 18);
Map.addLayer(naip, null, 'NAIP RGB');
// Display the clusters.
Map.addLayer(snic.randomVisualizer(), null, 'Clusters');
// Display the RGB cluster means.
var visParams = {
bands: ['R_mean', 'G_mean', 'B_mean'],
min: 0,
max: 255
};
Map.addLayer(snic, visParams, 'RGB cluster means');
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
# Note that the compactness and size parameters can have a significant impact
# on the result. They must be adjusted to meet image-specific characteristics
# and patterns, typically through trial. Pixel scale (map zoom level) is also
# important to consider. When exploring interactively through map tile
# visualization, the segmentation result it dependent on zoom level. If you
# need to evaluate the result at a specific scale, call .reproject() on the
# result, but do so with caution because it overrides the default scaling
# behavior that makes tile computation fast and efficient.
# Load a NAIP image for a neighborhood in Las Vegas.
naip = ee.Image('USDA/NAIP/DOQQ/m_3611554_sw_11_1_20170613')
# Apply the SNIC algorithm to the image.
snic = ee.Algorithms.Image.Segmentation.SNIC(
image=naip, size=30, compactness=0.1, connectivity=8
)
# Display the original NAIP image as RGB.
m = geemap.Map()
m.set_center(-115.32053, 36.182016, 18)
m.add_layer(naip, None, 'NAIP RGB')
# Display the clusters.
m.add_layer(snic.randomVisualizer(), None, 'Clusters')
# Display the RGB cluster means.
vis_params = {'bands': ['R_mean', 'G_mean', 'B_mean'], 'min': 0, 'max': 255}
m.add_layer(snic, vis_params, 'RGB cluster means')
m
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eApplies the Simple Non-Iterative Clustering (SNIC) algorithm to generate superpixels from an image.\u003c/p\u003e\n"],["\u003cp\u003eOutputs an image containing cluster IDs and per-cluster band averages.\u003c/p\u003e\n"],["\u003cp\u003eAlgorithm parameters like \u003ccode\u003esize\u003c/code\u003e and \u003ccode\u003ecompactness\u003c/code\u003e impact the resulting superpixel shapes and sizes and may require adjustments.\u003c/p\u003e\n"],["\u003cp\u003eIf no seed locations are provided, the algorithm generates them based on a grid defined by the \u003ccode\u003esize\u003c/code\u003e parameter.\u003c/p\u003e\n"],["\u003cp\u003eSuperpixel clustering is sensitive to pixel scale and zoom level during interactive visualization.\u003c/p\u003e\n"]]],["SNIC clustering segments an image into superpixels, outputting cluster IDs and per-cluster averages for each input band. Key parameters include `size` (seed spacing), `compactness` (cluster shape), and `connectivity`. A user can provide `seeds` to define seed locations; otherwise, they are generated. The output `Image` includes cluster IDs, band averages, and optionally generated seed locations. Adjusting `size` and `compactness` is crucial for optimal results, which are also affected by pixel scale.\n"],null,["# ee.Algorithms.Image.Segmentation.SNIC\n\nSuperpixel clustering based on SNIC (Simple Non-Iterative Clustering). Outputs a band of cluster IDs and the per-cluster averages for each of the input bands. If the 'seeds' image isn't provided as input, the output will include a 'seeds' band containing the generated seed locations. See: Achanta, Radhakrishna and Susstrunk, Sabine, 'Superpixels and Polygons using Simple Non-Iterative Clustering', CVPR, 2017.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|----------------------------------------------------------------------------------------------------------------------------------|---------|\n| `ee.Algorithms.Image.Segmentation.SNIC(image, `*size* `, `*compactness* `, `*connectivity* `, `*neighborhoodSize* `, `*seeds*`)` | Image |\n\n| Argument | Type | Details |\n|--------------------|------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `image` | Image | The input image for clustering. |\n| `size` | Integer, default: 5 | The superpixel seed location spacing, in pixels. If 'seeds' image is provided, no grid is produced. |\n| `compactness` | Float, default: 1 | Compactness factor. Larger values cause clusters to be more compact (square). Setting this to 0 disables spatial distance weighting. |\n| `connectivity` | Integer, default: 8 | Connectivity. Either 4 or 8. |\n| `neighborhoodSize` | Integer, default: null | Tile neighborhood size (to avoid tile boundary artifacts). Defaults to 2 \\* size. |\n| `seeds` | Image, default: null | If provided, any non-zero valued pixels are used as seed locations. Pixels that touch (as specified by 'connectivity') are considered to belong to the same cluster. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// Note that the compactness and size parameters can have a significant impact\n// on the result. They must be adjusted to meet image-specific characteristics\n// and patterns, typically through trial. Pixel scale (map zoom level) is also\n// important to consider. When exploring interactively through map tile\n// visualization, the segmentation result it dependent on zoom level. If you\n// need to evaluate the result at a specific scale, call .reproject() on the\n// result, but do so with caution because it overrides the default scaling\n// behavior that makes tile computation fast and efficient.\n\n\n// Load a NAIP image for a neighborhood in Las Vegas.\nvar naip = ee.Image('USDA/NAIP/DOQQ/m_3611554_sw_11_1_20170613');\n\n// Apply the SNIC algorithm to the image.\nvar snic = ee.Algorithms.Image.Segmentation.SNIC({\n image: naip,\n size: 30,\n compactness: 0.1,\n connectivity: 8,\n});\n\n// Display the original NAIP image as RGB.\n// Lock map zoom to maintain the desired scale of the segmentation computation.\nMap.setLocked(false, 18, 18);\nMap.setCenter(-115.32053, 36.182016, 18);\nMap.addLayer(naip, null, 'NAIP RGB');\n\n// Display the clusters.\nMap.addLayer(snic.randomVisualizer(), null, 'Clusters');\n\n// Display the RGB cluster means.\nvar visParams = {\n bands: ['R_mean', 'G_mean', 'B_mean'],\n min: 0,\n max: 255\n};\nMap.addLayer(snic, visParams, 'RGB cluster means');\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# Note that the compactness and size parameters can have a significant impact\n# on the result. They must be adjusted to meet image-specific characteristics\n# and patterns, typically through trial. Pixel scale (map zoom level) is also\n# important to consider. When exploring interactively through map tile\n# visualization, the segmentation result it dependent on zoom level. If you\n# need to evaluate the result at a specific scale, call .reproject() on the\n# result, but do so with caution because it overrides the default scaling\n# behavior that makes tile computation fast and efficient.\n\n\n# Load a NAIP image for a neighborhood in Las Vegas.\nnaip = ee.Image('USDA/NAIP/DOQQ/m_3611554_sw_11_1_20170613')\n\n# Apply the SNIC algorithm to the image.\nsnic = ee.Algorithms.Image.Segmentation.SNIC(\n image=naip, size=30, compactness=0.1, connectivity=8\n)\n\n# Display the original NAIP image as RGB.\nm = geemap.Map()\nm.set_center(-115.32053, 36.182016, 18)\nm.add_layer(naip, None, 'NAIP RGB')\n\n# Display the clusters.\nm.add_layer(snic.randomVisualizer(), None, 'Clusters')\n\n# Display the RGB cluster means.\nvis_params = {'bands': ['R_mean', 'G_mean', 'B_mean'], 'min': 0, 'max': 255}\nm.add_layer(snic, vis_params, 'RGB cluster means')\nm\n```"]]