Skip to content

Commit 80c3ccb

Browse files
mwaskomlarsoner
authored andcommitted
Allow painting all annotation vertices in a single color (#273)
1 parent b2474cf commit 80c3ccb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

surfer/tests/test_viz.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ def test_annot():
165165
labels, ctab, names = nib.freesurfer.read_annot(annot_path)
166166
brain.add_annotation((labels, ctab))
167167

168+
brain.add_annotation('aparc', color="red", remove_existing=True)
169+
surf = brain.annot["surface"]
170+
ctab = surf.module_manager.scalar_lut_manager.lut.table
171+
for color in ctab:
172+
assert color[:3] == (255, 0, 0)
173+
168174
brain.close()
169175

170176

surfer/viz.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ def time_label(x):
11961196
self._toggle_render(True, views)
11971197

11981198
def add_annotation(self, annot, borders=True, alpha=1, hemi=None,
1199-
remove_existing=True):
1199+
remove_existing=True, color=None):
12001200
"""Add an annotation file.
12011201
12021202
Parameters
@@ -1220,6 +1220,10 @@ def add_annotation(self, annot, borders=True, alpha=1, hemi=None,
12201220
for both hemispheres.
12211221
remove_existing : bool
12221222
If True (default), remove old annotations.
1223+
color : matplotlib-style color code
1224+
If used, show all annotations in the same (specified) color.
1225+
Probably useful only when showing annotation borders.
1226+
12231227
"""
12241228
hemis = self._check_hemis(hemi)
12251229

@@ -1292,6 +1296,12 @@ def add_annotation(self, annot, borders=True, alpha=1, hemi=None,
12921296
alpha_vec = cmap[:, 3]
12931297
alpha_vec[alpha_vec > 0] = alpha * 255
12941298

1299+
# Override the cmap when a single color is used
1300+
if color is not None:
1301+
from matplotlib.colors import colorConverter
1302+
rgb = np.round(np.multiply(colorConverter.to_rgb(color), 255))
1303+
cmap[:, :3] = rgb.astype(cmap.dtype)
1304+
12951305
for brain in self._brain_list:
12961306
if brain['hemi'] == hemi:
12971307
self.annot_list.append(

0 commit comments

Comments
 (0)