Skip to content

ENH: Allow painting all annotation vertices in a single color #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions surfer/tests/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
12 changes: 11 additions & 1 deletion surfer/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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(
Expand Down