ee.Algorithms.Image.Segmentation.SNIC

Cụm siêu điểm ảnh dựa trên SNIC (Phân cụm đơn giản không lặp lại). Xuất ra một dải gồm các mã nhận dạng 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 làm dữ liệu đầu vào, thì đầu ra sẽ bao gồm một dải "hạt giống" chứa các vị trí hạt giống được 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ương pháp phân cụm đơn giản không lặp lại), 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í của hạt siêu pixel, tính bằng pixel. Nếu bạn cung cấp hình ảnh "hạt giống", thì sẽ không có lưới nào được tạo.
compactnessSố thực, mặc định: 1Hệ số độ kết nối. Giá trị càng lớn thì các cụm càng nhỏ gọn (hình vuông). Nếu bạn đặt thông số này thành 0, thì tính năng phân bổ trọng số theo khoảng cách không gian sẽ bị tắt.
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 ô (để tránh các hiện tượng giả tạo do ranh giới ô). Giá trị mặc định là 2 * size.
seedsHình ảnh, mặc định: rỗngNếu được cung cấp, mọi pixel có giá trị khác 0 sẽ được dùng làm vị trí ban đầu. Các pixel chạm vào nhau (như được chỉ định theo "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ề API Python và cách sử dụng geemap cho quá trình phát triển 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