MCPcopy
hub / github.com/mne-tools/mne-python / random_parcellation

Function random_parcellation

mne/label.py:1950–1997  ·  view source on GitHub ↗

Generate random cortex parcellation by growing labels. This function generates a number of labels which don't intersect and cover the whole surface. Regions are growing around randomly chosen seeds. Parameters ---------- %(subject)s n_parcel : int Total number o

(
    subject, n_parcel, hemi, subjects_dir=None, surface="white", random_state=None
)

Source from the content-addressed store, hash-verified

1948
1949@fill_doc
1950def random_parcellation(
1951 subject, n_parcel, hemi, subjects_dir=None, surface="white", random_state=None
1952):
1953 """Generate random cortex parcellation by growing labels.
1954
1955 This function generates a number of labels which don't intersect and
1956 cover the whole surface. Regions are growing around randomly chosen
1957 seeds.
1958
1959 Parameters
1960 ----------
1961 %(subject)s
1962 n_parcel : int
1963 Total number of cortical parcels.
1964 hemi : str
1965 Hemisphere id (ie ``'lh'``, ``'rh'``, ``'both'``). In the case
1966 of ``'both'``, both hemispheres are processed with ``(n_parcel // 2)``
1967 parcels per hemisphere.
1968 %(subjects_dir)s
1969 %(surface)s
1970 %(random_state)s
1971
1972 Returns
1973 -------
1974 labels : list of Label
1975 Random cortex parcellation.
1976 """
1977 subjects_dir = get_subjects_dir(subjects_dir, raise_error=True)
1978 if hemi == "both":
1979 hemi = ["lh", "rh"]
1980 hemis = np.atleast_1d(hemi)
1981
1982 # load the surfaces and create the distance graphs
1983 tris, vert, dist = {}, {}, {}
1984 for hemi in set(hemis):
1985 surf_fname = subjects_dir / subject / "surf" / f"{hemi}.{surface}"
1986 vert[hemi], tris[hemi] = read_surface(surf_fname)
1987 dist[hemi] = mesh_dist(tris[hemi], vert[hemi])
1988
1989 # create the patches
1990 labels = _cortex_parcellation(subject, n_parcel, hemis, vert, dist, random_state)
1991
1992 # add a unique color to each label
1993 colors = _n_colors(len(labels))
1994 for label, color in zip(labels, colors):
1995 label.color = color
1996
1997 return labels
1998
1999
2000def _cortex_parcellation(

Callers 1

test_random_parcellationFunction · 0.90

Calls 6

get_subjects_dirFunction · 0.85
setFunction · 0.85
read_surfaceFunction · 0.85
mesh_distFunction · 0.85
_cortex_parcellationFunction · 0.85
_n_colorsFunction · 0.85

Tested by 1

test_random_parcellationFunction · 0.72