Skip to content

Commit b441d4f

Browse files
author
Emmanuelle Gouillart
committed
Docstring draft for spectral clustering. To be improved.
1 parent 726ab8c commit b441d4f

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

spectral_embedding.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,63 @@ def communities_clustering_sparse(adjacency, k_best=None, k_min=2, k_max=8, n_bs
223223
def separate_in_regions(data, mask=None, k_best=None, k_min=2, k_max=8, \
224224
center=None, only_connex=True, n_times=4,\
225225
take_first=True, beta=10, mode='bf'):
226+
"""
227+
Separate an image in different regions, using spectral clustering.
228+
229+
Parameters
230+
----------
231+
232+
data: array
233+
Image to be segmented in regions. `data` can be two- or
234+
three-dimensional.
235+
236+
mask: array, optional
237+
Mask of the pixels to be clustered. If mask is None, all pixels
238+
are clustered.
239+
240+
k_best: int, optional
241+
number of clusters to be found. If k_best is None, the clustering
242+
is performed for a range of numbers given by k_min and k_max.
243+
244+
k_min: int, optional
245+
minimum number of clusters
246+
247+
k_max: int, optional
248+
maximum number of clusters
249+
250+
center: tuple-like, optional
251+
coordinates of a point included in the connected component to be
252+
segmented, if there are several connected components.
253+
254+
only_connex: boolean, optional
255+
whether to return only the segmentation of the principal connected
256+
component or the (non-clustered) other components as well.
257+
258+
n_times: int, optional
259+
how many times the k_means clustering is performed for each k
260+
261+
take_first: boolean, optional
262+
whether to take the first eigenmode (of eigenvalue 0) for the clustering
263+
or not. One should not take it for k=2, but I get better results with it
264+
for k >= 4 in my images.
265+
266+
beta: float, optional
267+
normalization parameter used to compute the weight of a link. The greater
268+
beta, the more gradients are penalized.
269+
270+
mode: str, {'bf', 'amg'}
271+
how the eigenmode of the spectral embedding are computed. 'bf' uses
272+
arpack, and 'amg' pyamg (multigrid methods). 'amg' should be much faster.
273+
274+
Returns
275+
-------
276+
277+
labels: array or dict with array values
278+
result of clustering. If k_best is None, a dict is return and
279+
label[k] is the clustering in k clusters, for k_min <= k <= k_max
280+
281+
scores: int or dict with int values
282+
"""
226283
if mask is not None:
227284
labs, nb_labels = ndimage.label(mask)
228285
else:

0 commit comments

Comments
 (0)