Skip to content
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
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Version 0.7
to manually install ``ffmpeg``. ``imageio`` has been added as an optional
dependency which can be installed with
``$ pip install pysurfer[save_movie]``.
- ``Brain.save_image`` now has the option to save with alpha channel and
antialiasing.

Version 0.6
-----------
Expand Down
1 change: 1 addition & 0 deletions surfer/tests/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_image():

brain = Brain(*std_args, size=100)
brain.save_image(tmp_name)
brain.save_image(tmp_name, 'rgba', True)
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='v')
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='h')
brain.save_montage(tmp_name, [['l', 'v'], ['m', 'f']])
Expand Down
19 changes: 12 additions & 7 deletions surfer/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ def save_single_image(self, filename, row=-1, col=-1):
mlab.draw(brain._f)
mlab.savefig(filename, figure=brain._f)

def save_image(self, filename):
def save_image(self, filename, mode='rgb', antialiased=False):
"""Save view from all panels to disk

Only mayavi image types are supported:
Expand All @@ -2020,15 +2020,23 @@ def save_image(self, filename):
----------
filename: string
path to new image file
mode: string
Either 'rgb' (default) to render solid background, or 'rgba' to
include alpha channel for transparent background
antialiased: bool
Antialias the image (see mlab.screenshot() for details; default
False)

Notes
-----
Due to limitations in TraitsUI, if multiple views or hemi='split'
is used, there is no guarantee painting of the windows will
complete before control is returned to the command line. Thus
we strongly recommend using only one figure window (which uses
a Mayavi figure to plot instead of TraitsUI) if you intend to
script plotting commands.
"""
misc.imsave(filename, self.screenshot())
misc.imsave(filename, self.screenshot(mode, antialiased))

def screenshot(self, mode='rgb', antialiased=False):
"""Generate a screenshot of current view
Expand All @@ -2040,11 +2048,8 @@ def screenshot(self, mode='rgb', antialiased=False):
mode: string
Either 'rgb' or 'rgba' for values to return
antialiased: bool
Antialias the image (see mlab.screenshot() for details)
row : int
row index of the brain to use
col : int
column index of the brain to use
Antialias the image (see mlab.screenshot() for details; default
False)

Returns
-------
Expand Down