ee.Algorithms.Image.Segmentation.SNIC

Phân cụm siêu điểm ảnh dựa trên SNIC (Phân cụm đơn giản không lặp). Xuất một dải mã cụm và giá trị trung bình trên mỗi cụm cho từng dải đầu vào. Nếu hình ảnh "hạt giống" không được cung cấp dưới dạng đầu vào, thì đầu ra sẽ bao gồm một dải "hạt giống" chứa vị trí hạt giống đã tạo.

Xem: Achanta, Radhakrishna và Susstrunk, Sabine, "Superpixels and Polygons using Simple Non-Iterative Clustering" (Siêu điểm ảnh và đa giác bằng cách sử dụng Phân cụm đơn giản không lặp), CVPR, 2017.

Cách sử dụngGiá trị trả về
ee.Algorithms.Image.Segmentation.SNIC(image, size, compactness, connectivity, neighborhoodSize, seeds)Hình ảnh
Đối sốLoạiThông tin chi tiết
imageHình ảnhHình ảnh đầu vào để phân cụm.
sizeSố nguyên, mặc định: 5Khoảng cách vị trí hạt giống siêu điểm ảnh, tính bằng pixel. Nếu hình ảnh "hạt giống" được cung cấp, thì sẽ không có lưới nào được tạo.
compactnessSố thực, mặc định: 1Hệ số độ gọn. Giá trị càng lớn thì các cụm càng gọn (hình vuông). Việc đặt giá trị này thành 0 sẽ tắt tính năng phân bổ trọng số khoảng cách không gian.
connectivitySố nguyên, mặc định: 8Khả năng kết nối. 4 hoặc 8.
neighborhoodSizeSố nguyên, mặc định: nullKích thước vùng lân cận của ô xếp (để tránh các hiện vật ranh giới ô xếp). Mặc định là 2 * kích thước.
seedsHình ảnh, mặc định: nullNếu được cung cấp, mọi pixel có giá trị khác 0 sẽ được dùng làm vị trí hạt giống. Các pixel chạm vào nhau (như được chỉ định bởi "khả năng kết nối") được coi là thuộc cùng một cụm.

Ví dụ

Trình soạn thảo mã (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');

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về Python API và cách sử dụng geemap cho quá trình phát triển có tính tương tác.

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