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.
ee.Algorithms.Image.Segmentation.KMeans(image, numClusters, numIterations, neighborhoodSize, gridSize, forceConvergence, uniqueLabels)Image
imageImageThe input image for clustering.
numClustersInteger, default: 8Number of clusters.
numIterationsInteger, default: 20Number of iterations.
neighborhoodSizeInteger, default: 0Neighborhood size. The amount to extend each tile (overlap) when computing the clusters. This option is mutually exclusive with gridSize.
gridSizeInteger, default: nullGrid 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.
forceConvergenceBoolean, default: falseIf true, an error is thrown if convergence is not achieved before numIterations.
uniqueLabelsBoolean, default: trueIf true, clusters are assigned unique IDs. Otherwise, they repeat per tile or grid cell.