Ogłoszenie: wszystkie projekty niekomercyjne zarejestrowane do korzystania z Earth Engine przed
15 kwietnia 2025 r. muszą
potwierdzić spełnianie warunków użycia niekomercyjnego, aby zachować dostęp. Jeśli nie przejdziesz weryfikacji do 26 września 2025 r., Twój dostęp może zostać wstrzymany.
ee.Algorithms.Image.Segmentation.SNIC
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Klastrowanie superpikseli na podstawie algorytmu SNIC (Simple Non-Iterative Clustering). Zwraca pasmo identyfikatorów klastrów i średnie wartości dla każdego klastra w poszczególnych pasmach wejściowych. Jeśli obraz „seeds” nie zostanie podany jako dane wejściowe, dane wyjściowe będą zawierać pasmo „seeds” z wygenerowanymi lokalizacjami nasion. Zobacz: Achanta, Radhakrishna i Susstrunk, Sabine, „Superpixels and Polygons using Simple Non-Iterative Clustering”, CVPR, 2017.
| Wykorzystanie | Zwroty |
|---|
ee.Algorithms.Image.Segmentation.SNIC(image, size, compactness, connectivity, neighborhoodSize, seeds) | Obraz |
| Argument | Typ | Szczegóły |
|---|
image | Obraz | Obraz wejściowy do klastrowania. |
size | Liczba całkowita, domyślnie: 5 | Odstępy między lokalizacjami początkowymi superpikseli (w pikselach). Jeśli podasz obraz „seeds”, nie zostanie wygenerowana siatka. |
compactness | Liczba zmiennoprzecinkowa, domyślnie: 1 | Współczynnik zwartości. Większe wartości powodują, że klastry są bardziej zwarte (kwadratowe). Ustawienie tej wartości na 0 wyłącza ważenie odległości przestrzennej. |
connectivity | Liczba całkowita, domyślnie: 8 | Łączność. Może to być 4 lub 8. |
neighborhoodSize | Liczba całkowita, domyślnie: null | Rozmiar sąsiedztwa kafelka (aby uniknąć artefaktów na granicach kafelków). Domyślna wartość to 2 * rozmiar. |
seeds | Obraz, domyślny: null | Jeśli podasz piksele o wartości innej niż zero, będą one używane jako lokalizacje początkowe. Piksele, które się stykają (zgodnie z parametrem „connectivity”), są uznawane za należące do tego samego klastra. |
Przykłady
Edytor kodu (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');
Konfiguracja Pythona
Informacje o interfejsie Python API i używaniu geemap do interaktywnego programowania znajdziesz na stronie
Środowisko Python.
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
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-26 UTC.
[null,null,["Ostatnia aktualizacja: 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"]]