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 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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