公告:凡是在
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。否則會依圖塊或格線儲存格重複顯示。 |
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間: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. |"]]