Skip to content

ENH: Add scale parameter to Brain screenshot and save_image (#14385) - #14447

Merged
larsoner merged 2 commits into
mne-tools:mainfrom
ishaaaan17:enh/brain-screenshot-scale
Oct 23, 2026
Merged

larsoner merged 2 commits into
mne-tools:mainfrom
ishaaaan17:enh/brain-screenshot-scale

Conversation

@ishaaaan17

Copy link
Copy Markdown
Contributor

summary of changes

addresses #14385.

this adds a scale parameter to Brain.screenshot() and Brain.save_image(), so users can export high-resolution images for publications.

  • scale is passed through the renderer backend to PyVista's plotter.screenshot(scale=scale).
  • when time_viewer=True, the DPI of the Matplotlib trace is scaled by the same factor, so it matches the size of the 3D canvas.
  • added a check in test_image_screenshot that the dimensions are doubled and that the image has a high correlation (> 0.95) with a bilinear downsampled version.
  • added a towncrier changelog entry.

checklist

  • code style checked with ruff and codespell
  • tests added and passing locally
  • changelog entry added in doc/changes/dev/14385.newfeature.rst

Comment thread mne/viz/_brain/_brain.py Outdated
Either ``'rgb'`` or ``'rgba'`` for values to return.
scale : float | None
The scale factor for the screenshot. Larger values produce higher
resolution images. Supported when using PyVista.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs versionadded. I don't think you need the "Supported when using PyVista" (we always do currently)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done! added .. versionadded:: 1.14 and removed the PyVista mention.

Comment thread mne/viz/_brain/_brain.py Outdated
renderer.reset_camera()

def save_image(self, filename=None, mode="rgb"):
def save_image(self, filename=None, mode="rgb", scale=None):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def save_image(self, filename=None, mode="rgb", scale=None):
def save_image(self, filename=None, mode="rgb", *, scale=None):

@ishaaaan17 ishaaaan17 Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done! made scale keyword-only (with default 1).

Comment thread mne/viz/_brain/_brain.py Outdated

@fill_doc_static("time_viewer_brain_screenshot")
def screenshot(self, mode="rgb", time_viewer=False):
def screenshot(self, mode="rgb", time_viewer=False, scale=None):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def screenshot(self, mode="rgb", time_viewer=False, scale=None):
def screenshot(self, mode="rgb", time_viewer=False, *, scale=None):

@ishaaaan17 ishaaaan17 Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done! made scale keyword-only here too.

Comment thread mne/viz/_brain/_brain.py Outdated
``time_viewer=True`` and ``separate_canvas=False``.
scale : float | None
The scale factor for the screenshot. Larger values produce higher
resolution images. Supported when using PyVista.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs versionadded

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done! added .. versionadded:: 1.14 and removed the PyVista mention.

Comment thread mne/viz/_brain/_brain.py Outdated
Path to new image file.
mode : str
Either ``'rgb'`` or ``'rgba'`` for values to return.
scale : float | None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think pyvista might actually only take int... we should probably only support int here and default to 1 (no need for `None)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! changed scale to an int with default 1, checked it with _ensure_int (and added a unit test that asserts a TypeError for non-int values), and updated the docstrings with .. versionadded:: 1.14. thanks!

@ishaaaan17
ishaaaan17 force-pushed the enh/brain-screenshot-scale branch from 3fcd094 to f2a9b80 Compare October 23, 2026 18:51
Support exporting high-resolution images from Brain by exposing a scale parameter in Brain.screenshot() and Brain.save_image(), which forwards down to PyVista's plotter.screenshot(scale=scale).

Closes mne-tools#14385.
@ishaaaan17
ishaaaan17 force-pushed the enh/brain-screenshot-scale branch from f2a9b80 to 696e1fe Compare October 23, 2026 18:56

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking for merge-when-green, thanks in advance @ishaaaan17 !

@larsoner
larsoner enabled auto-merge (squash) October 23, 2026 19:01
@larsoner
larsoner merged commit f348177 into mne-tools:main Oct 23, 2026
25 checks passed
@ishaaaan17
ishaaaan17 deleted the enh/brain-screenshot-scale branch November 5, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants