Illustration generated with AI; not experimental data.¶
Clustering¶
“Clustering” groups similar pixels together without needing any labeled
examples — an unsupervised method. juspice.clustering_module
gives you six clustering algorithms (watershed, SLIC, Felzenszwalb,
multi-Otsu, Quickshift, K-means) through the spice.clustering
accessor.
Native interface — ClusteringAccessor¶
spice.clustering is the main way to do unsupervised image clustering
in JuSPICE. Each method returns a new SPICEData
holding the resulting label array, and shares the input’s
DatasetHistory — it never changes
spice.data itself. This is the same derived-object pattern used by
juspice.feature_extract.FeatureExtractionAccessor.extract():
ws_spice = spice.clustering.watershed_clustering(footprint_size=60, min_distance=20)
slic_spice = spice.clustering.slic_clustering(n_segments=200)
fz_spice = spice.clustering.felzenszwalb_clustering(scale=500)
otsu_spice = spice.clustering.otsu_multithreshold(n_classes=2)
qs_spice = spice.clustering.quickshift_clustering(kernel_size=5)
km_spice = spice.clustering.kmeans_clustering(n_clusters=3)
Available algorithms
watershed_clustering()— Marker-based watershed. Intermediate states (binary mask, distance transform, markers) returned inresult.extra.slic_clustering()— Simple Linear Iterative Clustering superpixels.felzenszwalb_clustering()— Graph-based Felzenszwalb segmentation.otsu_multithreshold()— Multi-level Otsu thresholding. Computed thresholds inresult.extraandresult.metadata.quickshift_clustering()— Quickshift mode-seeking segmentation.kmeans_clustering()— K-means clustering (scikit-learn) over per-pixel feature vectors. Fitted cluster centers and inertia returned inresult.extraandresult.metadatarespectively.
Watershed, SLIC, Felzenszwalb, Otsu, and Quickshift all work on the same
preprocessed grayscale image, in the [0, 1] range, kept ready for the
whole session at spice.clustering.image. kmeans_clustering is the
exception: it clusters the raw spice.data array directly, without
collapsing it to grayscale first — so for a multi-channel dataset (e.g. all
channels of an AFM .spm scan), every channel feeds into each pixel’s
feature vector, not just one grayscale value.
Reproducibility¶
Each ClusteringAccessor() call records a
clustering.<method_name> operation (e.g.
clustering.watershed_clustering) into spice.history.
to_lines() turns these back into
plain, runnable code:
ws_spice = spice.clustering.watershed_clustering(footprint_size=60)
slic_spice = spice.clustering.slic_clustering(n_segments=200)
km_spice = spice.clustering.kmeans_clustering(n_clusters=3)
See also
juspice.clustering_module — full API reference
Image Clustering — domain background