公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.Algorithms.Image.Segmentation.KMeans
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
对输入图片执行 K-Means 聚类。输出一个单波段图像,其中包含每个像素所属的聚类 ID。该算法可以处理不重叠的固定网格单元(gridSize,可以小于图块),也可以处理重叠的图块(neighborhoodSize)。默认情况下,使用不重叠的图块。一个单元格或图块中的集群与另一个单元格或图块中的集群无关。任何跨越单元格或图块边界的聚类都可能在两个半部分中收到两个不同的标签。任何具有部分遮罩的输入像素在输出中都会被完全遮罩。
用法 | 返回 |
---|
ee.Algorithms.Image.Segmentation.KMeans(image, numClusters, numIterations, neighborhoodSize, gridSize, forceConvergence, uniqueLabels) | 图片 |
参数 | 类型 | 详细信息 |
---|
image | 图片 | 用于聚类的输入图片。 |
numClusters | 整数,默认值:8 | 聚类数量。 |
numIterations | 整数,默认值:20 | 迭代次数。 |
neighborhoodSize | 整数,默认值:0 | 邻域大小。计算聚类时,每个图块的扩展量(重叠)。此选项与 gridSize 互斥。 |
gridSize | 整数,默认值:null | 网格单元格大小。如果大于 0,则 kMeans 将独立运行于此大小的单元格上。这会限制任何聚类的大小,使其不大于 gridSize。此选项与 neighborhoodSize 互斥。 |
forceConvergence | 布尔值,默认值:false | 如果为 true,则在达到 numIterations 之前未实现收敛时会抛出错误。 |
uniqueLabels | 布尔值,默认值:true | 如果值为 true,则为集群分配唯一 ID。否则,它们会按平铺或网格单元格重复。 |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003ePerforms K-Means clustering on an input image, assigning each pixel to a cluster and outputting a single-band image with cluster IDs.\u003c/p\u003e\n"],["\u003cp\u003eOffers flexibility to control clustering with parameters like \u003ccode\u003enumClusters\u003c/code\u003e, \u003ccode\u003enumIterations\u003c/code\u003e, neighborhood size, and grid size.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eneighborhoodSize\u003c/code\u003e dictates the tile overlap for cluster computation, while \u003ccode\u003egridSize\u003c/code\u003e allows independent clustering within fixed-size cells.\u003c/p\u003e\n"],["\u003cp\u003eSetting \u003ccode\u003euniqueLabels\u003c/code\u003e to true ensures distinct cluster IDs across the entire image, while false results in repeated IDs per tile or grid cell.\u003c/p\u003e\n"],["\u003cp\u003eBy default, uses tiles without overlap for clustering and assigns unique labels to clusters.\u003c/p\u003e\n"]]],["K-Means clustering is applied to an input image, generating a single-band output image where each pixel is assigned a cluster ID. Clustering can occur within a fixed grid (`gridSize`) or within overlapping tiles (`neighborhoodSize`). By default, tiles have no overlap. Clusters are independent per cell/tile, potentially resulting in different labels for clusters crossing boundaries. Parameters include the number of clusters and iterations. Convergence can be enforced and the ID labels be unique or repeat depending on the specified parameter.\n"],null,["# ee.Algorithms.Image.Segmentation.KMeans\n\nPerforms K-Means clustering on the input image. Outputs a 1-band image containing the ID of the cluster that each pixel belongs to. The algorithm can work either on a fixed grid of non-overlapping cells (gridSize, which can be smaller than a tile) or on tiles with overlap (neighborhoodSize). The default is to use tiles with no overlap. Clusters in one cell or tile are unrelated to clusters in another. Any cluster that spans a cell or tile boundary may receive two different labels in the two halves. Any input pixels with partial masks are fully masked in the output.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|\n| `ee.Algorithms.Image.Segmentation.KMeans(image, `*numClusters* `, `*numIterations* `, `*neighborhoodSize* `, `*gridSize* `, `*forceConvergence* `, `*uniqueLabels*`)` | Image |\n\n| Argument | Type | Details |\n|--------------------|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `image` | Image | The input image for clustering. |\n| `numClusters` | Integer, default: 8 | Number of clusters. |\n| `numIterations` | Integer, default: 20 | Number of iterations. |\n| `neighborhoodSize` | Integer, default: 0 | Neighborhood size. The amount to extend each tile (overlap) when computing the clusters. This option is mutually exclusive with gridSize. |\n| `gridSize` | Integer, default: null | Grid cell-size. If greater than 0, kMeans will be run independently on cells of this size. This has the effect of limiting the size of any cluster to be gridSize or smaller. This option is mutually exclusive with neighborhoodSize. |\n| `forceConvergence` | Boolean, default: false | If true, an error is thrown if convergence is not achieved before numIterations. |\n| `uniqueLabels` | Boolean, default: true | If true, clusters are assigned unique IDs. Otherwise, they repeat per tile or grid cell. |"]]