Thông báo: Tất cả dự án phi thương mại đã đăng ký sử dụng Earth Engine trước
ngày 15 tháng 4 năm 2025 phải
xác minh điều kiện sử dụng phi thương mại để duy trì quyền truy cập. Nếu bạn chưa xác minh trước ngày 26 tháng 9 năm 2025, quyền truy cập của bạn có thể bị tạm ngưng.
ee.Algorithms.Image.Segmentation.SNIC
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
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ụng | Giá trị trả về |
|---|
ee.Algorithms.Image.Segmentation.SNIC(image, size, compactness, connectivity, neighborhoodSize, seeds) | Hình ảnh |
| Đối số | Loại | Thông tin chi tiết |
|---|
image | Hình ảnh | Hình ảnh đầu vào để phân cụm. |
size | Số nguyên, mặc định: 5 | Khoả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. |
compactness | Số thực, mặc định: 1 | Hệ 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. |
connectivity | Số nguyên, mặc định: 8 | Khả năng kết nối. 4 hoặc 8. |
neighborhoodSize | Số nguyên, mặc định: null | Kí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. |
seeds | Hình ảnh, mặc định: rỗng | Nế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
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[],["SNIC clustering segments an image into superpixels, outputting cluster IDs and per-cluster averages for each input band. Key parameters include `size` (seed spacing), `compactness` (cluster shape), and `connectivity`. A user can provide `seeds` to define seed locations; otherwise, they are generated. The output `Image` includes cluster IDs, band averages, and optionally generated seed locations. Adjusting `size` and `compactness` is crucial for optimal results, which are also affected by pixel scale.\n"]]