From f48a34b849e5c2f463d920c199839e34abeae9ce Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Mon, 12 Aug 2019 11:44:07 -0400 Subject: [PATCH] Allow painting all annotation vertices in a single color --- surfer/tests/test_viz.py | 6 ++++++ surfer/viz.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/surfer/tests/test_viz.py b/surfer/tests/test_viz.py index 158518d..f62d1ca 100644 --- a/surfer/tests/test_viz.py +++ b/surfer/tests/test_viz.py @@ -165,6 +165,12 @@ def test_annot(): labels, ctab, names = nib.freesurfer.read_annot(annot_path) brain.add_annotation((labels, ctab)) + brain.add_annotation('aparc', color="red", remove_existing=True) + surf = brain.annot["surface"] + ctab = surf.module_manager.scalar_lut_manager.lut.table + for color in ctab: + assert color[:3] == (255, 0, 0) + brain.close() diff --git a/surfer/viz.py b/surfer/viz.py index f76184f..5ff64dd 100644 --- a/surfer/viz.py +++ b/surfer/viz.py @@ -1196,7 +1196,7 @@ def time_label(x): self._toggle_render(True, views) def add_annotation(self, annot, borders=True, alpha=1, hemi=None, - remove_existing=True): + remove_existing=True, color=None): """Add an annotation file. Parameters @@ -1220,6 +1220,10 @@ def add_annotation(self, annot, borders=True, alpha=1, hemi=None, for both hemispheres. remove_existing : bool If True (default), remove old annotations. + color : matplotlib-style color code + If used, show all annotations in the same (specified) color. + Probably useful only when showing annotation borders. + """ hemis = self._check_hemis(hemi) @@ -1292,6 +1296,12 @@ def add_annotation(self, annot, borders=True, alpha=1, hemi=None, alpha_vec = cmap[:, 3] alpha_vec[alpha_vec > 0] = alpha * 255 + # Override the cmap when a single color is used + if color is not None: + from matplotlib.colors import colorConverter + rgb = np.round(np.multiply(colorConverter.to_rgb(color), 255)) + cmap[:, :3] = rgb.astype(cmap.dtype) + for brain in self._brain_list: if brain['hemi'] == hemi: self.annot_list.append(