Skip to content

Commit f364e94

Browse files
authored
Merge pull request #159 from ctw/addalpha
NF: added the option to specify alpha transparency for Brain binarized curvature rendering
2 parents d6350fd + f44f5d7 commit f364e94

File tree

6 files changed

+244
-81
lines changed

6 files changed

+244
-81
lines changed

CHANGES

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
PySurfer Changes
22
================
33

4+
Version 0.7
5+
-----------
6+
7+
- A new ``alpha`` keyword to the ``Brain`` constructor now controls
8+
opacity of the rendered brain surface.
9+
- The ``curv`` keyword to the ``Brain`` constructor has been
10+
deprecated. To replicate previous behavior when ``curv`` was set to
11+
``True`` simply omit the ``curv`` keyword. To replicate previous
12+
behavior when ``curv`` was set to ``False``, simply set the
13+
``cortex`` keyword to None. To ease transition the ``curv`` argument
14+
will still be caught and processed, but it will be removed in a
15+
future release.
16+
- The ``cortex`` keyword to the ``Brain`` constructor now also accepts
17+
a valid color specification (such as a 3-tuple with RGB values or a
18+
color name) to render the cortical surface in that color without
19+
rendering binary curvature values. Additionally it now also accepts
20+
a dictionary with keyword arguments that are passed on to the call
21+
to ``mlab.pipeline.surface``.
22+
423
Version 0.6
524
-----------
625

bin/pysurfer

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ if __name__ == '__main__':
7373
from surfer import Brain
7474

7575
# Load up the figure and underlying brain object
76-
b = Brain(args.subject_id, args.hemi, args.surf, args.curv,
77-
args.title, views=args.views, size=args.size,
78-
background=args.background, cortex=args.cortex)
76+
b = Brain(args.subject_id, args.hemi, args.surf, title=args.title,
77+
cortex=args.cortex, alpha=args.alpha, size=args.size,
78+
background=args.background, foreground=args.foreground,
79+
views=args.views)
7980

8081
# Maybe load some morphometry
8182
if args.morphometry is not None:

examples/plot_transparent_brain.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
=======================
3+
Plot Transparent Brain
4+
=======================
5+
6+
Plot a transparent brain to visualize foci below the surface.
7+
8+
"""
9+
import os
10+
from surfer import Brain
11+
12+
print(__doc__)
13+
14+
subject_id = "fsaverage"
15+
subjects_dir = os.environ["SUBJECTS_DIR"]
16+
17+
"""To render a transparent brain, we are specifying an alpha <
18+
1.0. This allows us to visualize foci that are not on the cortical
19+
surface. When the brain see-through, rendering of binary curvature is
20+
distracting, so we specify a color, rather than a color map as the
21+
argument for cortex:
22+
23+
"""
24+
brain = Brain(subject_id, "lh", "pial", cortex='ivory', alpha=0.5)
25+
26+
"""Here's a set of stereotaxic foci in the MNI coordinate system that
27+
are not on the cortical surface which we want to display.
28+
29+
"""
30+
31+
coords = [[-20, 10, 10],
32+
[-25, 22, 15],
33+
[-18, 8, 20]]
34+
35+
"""Now we plot the foci in the brain. Because the foci are not on the
36+
cortical surface, they are only visible when alpha is set to < 1.0 in
37+
the call to Brain.
38+
39+
"""
40+
brain.add_foci(coords, color="red")

surfer/_commandline.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
help="hemisphere to load")
3939
parser.add_argument("surf",
4040
help="surface mesh (e.g. 'pial', 'inflated')")
41-
parser.add_argument("-no-curv", action="store_false", dest="curv",
42-
help="do not display the binarized surface curvature")
4341
parser.add_argument("-morphometry", metavar="MEAS",
4442
help="load morphometry file (e.g. thickness, curvature)")
4543
parser.add_argument("-annotation", metavar="ANNOT",
@@ -64,8 +62,12 @@
6462
help="size of the display window (in pixels)")
6563
parser.add_argument("-background", metavar="COLOR", default="black",
6664
help="background color for display")
65+
parser.add_argument("-foreground", metavar="COLOR", default="white",
66+
help="foreground color for display")
6767
parser.add_argument("-cortex", metavar="COLOR", default="classic",
68-
help="colormap for binary cortex curvature")
68+
help="colormap or color for rendering the cortex")
69+
parser.add_argument("-alpha", metavar="COLOR", default="1.0",
70+
help="specifies opacity for the cortical surface")
6971
parser.add_argument("-title",
7072
help="title to use for the figure")
7173
parser.add_argument("-views", nargs="*", default=['lat'],

surfer/tests/test_viz.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,28 @@ def test_brains():
7373
# testing backend breaks when passing in a figure, so we use 'auto' here
7474
# (shouldn't affect usability, but it makes testing more annoying)
7575
mlab.options.backend = 'auto'
76-
surfs = ['inflated', 'white']
77-
hemis = ['lh', 'rh']
78-
curvs = [True, False]
79-
titles = [None, 'Hello']
80-
cortices = ["low_contrast", ("Reds", 0, 1, False)]
81-
sizes = [500, (400, 300)]
82-
backgrounds = ["white", "blue"]
83-
foregrounds = ["black", "white"]
84-
figs = [None, mlab.figure()]
85-
subj_dirs = [None, subj_dir]
86-
for surf, hemi, curv, title, cort, s, bg, fg, fig, sd \
87-
in zip(surfs, hemis, curvs, titles, cortices, sizes,
88-
backgrounds, foregrounds, figs, subj_dirs):
89-
brain = Brain(subject_id, hemi, surf, curv, title,
90-
cort, s, bg, fg, fig, sd)
76+
surfs = ['inflated', 'white', 'white', 'white', 'white', 'white', 'white']
77+
hemis = ['lh', 'rh', 'both', 'both', 'rh', 'both', 'both']
78+
titles = [None, 'Hello', 'Good bye!', 'lut test',
79+
'dict test', 'None test', 'RGB test']
80+
cortices = ["low_contrast", ("Reds", 0, 1, False), 'hotpink',
81+
['yellow', 'blue'], dict(colormap='Greys'),
82+
None, (0.5, 0.5, 0.5)]
83+
sizes = [500, (400, 300), (300, 300), (300, 400), 500, 400, 300]
84+
backgrounds = ["white", "blue", "black", "0.75",
85+
(0.2, 0.2, 0.2), "black", "0.75"]
86+
foregrounds = ["black", "white", "0.75", "red",
87+
(0.2, 0.2, 0.2), "blue", "black"]
88+
figs = [None, mlab.figure(), None, None, mlab.figure(), None, None]
89+
subj_dirs = [None, subj_dir, subj_dir, subj_dir,
90+
subj_dir, subj_dir, subj_dir]
91+
alphas = [1.0, 0.5, 0.25, 0.7, 0.5, 0.25, 0.7]
92+
for surf, hemi, title, cort, s, bg, fg, fig, sd, alpha \
93+
in zip(surfs, hemis, titles, cortices, sizes,
94+
backgrounds, foregrounds, figs, subj_dirs, alphas):
95+
brain = Brain(subject_id, hemi, surf, title=title, cortex=cort,
96+
alpha=alpha, size=s, background=bg, foreground=fg,
97+
figure=fig, subjects_dir=sd)
9198
brain.close()
9299
assert_raises(ValueError, Brain, subject_id, 'lh', 'inflated',
93100
subjects_dir='')

0 commit comments

Comments
 (0)