ee.Algorithms.Image.Segmentation.KMeans
Performs 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.
Usage | Returns |
---|
ee.Algorithms.Image.Segmentation.KMeans(image, numClusters, numIterations, neighborhoodSize, gridSize, forceConvergence, uniqueLabels) | Image |
Argument | Type | Details |
---|
image | Image | The input image for clustering. |
numClusters | Integer, default: 8 | Number of clusters. |
numIterations | Integer, default: 20 | Number of iterations. |
neighborhoodSize | Integer, default: 0 | Neighborhood size. The amount to extend each tile (overlap) when computing the clusters. This option is mutually exclusive with gridSize. |
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. |
forceConvergence | Boolean, default: false | If true, an error is thrown if convergence is not achieved before numIterations. |
uniqueLabels | Boolean, default: true | If true, clusters are assigned unique IDs. Otherwise, they repeat per tile or grid cell. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-13 UTC.
[null,null,["Last updated 2024-07-13 UTC."],[[["Performs K-Means clustering on an input image, assigning each pixel to a cluster and outputting a single-band image with cluster IDs."],["Offers flexibility to control clustering with parameters like `numClusters`, `numIterations`, neighborhood size, and grid size."],["`neighborhoodSize` dictates the tile overlap for cluster computation, while `gridSize` allows independent clustering within fixed-size cells."],["Setting `uniqueLabels` to true ensures distinct cluster IDs across the entire image, while false results in repeated IDs per tile or grid cell."],["By default, uses tiles without overlap for clustering and assigns unique labels to clusters."]]],["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"]]