-
Notifications
You must be signed in to change notification settings - Fork 575
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1516 from jeromedockes/cortex_surface_projections
[MRG] Cortex surface projections
- Loading branch information
Showing
26 changed files
with
1,552 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
Making a surface plot of a 3D statistical map | ||
============================================= | ||
project a 3D statistical map onto a cortical mesh using | ||
:func:`nilearn.surface.vol_to_surf`. Display a surface plot of the projected | ||
map using :func:`nilearn.plotting.plot_surf_stat_map`. | ||
NOTE: Example needs matplotlib version higher than 1.3.1. | ||
""" | ||
|
||
############################################################################## | ||
# Get a statistical map | ||
# --------------------- | ||
|
||
from nilearn import datasets | ||
|
||
localizer_dataset = datasets.fetch_localizer_button_task() | ||
localizer_tmap = localizer_dataset.tmaps[0] | ||
|
||
############################################################################## | ||
# Get a cortical mesh | ||
# ------------------- | ||
|
||
fsaverage = datasets.fetch_surf_fsaverage5() | ||
|
||
############################################################################## | ||
# Sample the 3D data around each node of the mesh | ||
# ----------------------------------------------- | ||
|
||
from nilearn import surface | ||
|
||
texture = surface.vol_to_surf(localizer_tmap, fsaverage.pial_right) | ||
|
||
############################################################################## | ||
# Plot the result | ||
# --------------- | ||
|
||
from nilearn import plotting | ||
|
||
plotting.plot_surf_stat_map(fsaverage.infl_right, texture, hemi='right', | ||
title='Surface right hemisphere', | ||
threshold=1., bg_map=fsaverage.sulc_right, | ||
cmap='cold_hot') | ||
|
||
############################################################################## | ||
# Plot 3D image for comparison | ||
# ---------------------------- | ||
|
||
plotting.plot_glass_brain(localizer_tmap, display_mode='r', plot_abs=False, | ||
title='Glass brain', threshold=2.) | ||
|
||
plotting.plot_stat_map(localizer_tmap, display_mode='x', threshold=1., | ||
cut_coords=range(0, 51, 10), title='Slices') | ||
|
||
plotting.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
examples/01_plotting/plot_surface_projection_strategies.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
""" | ||
Technical point: Illustration of the volume to surface sampling schemes | ||
======================================================================= | ||
In nilearn, :func:`nilearn.surface.vol_to_surf` allows us to measure values of | ||
a 3d volume at the nodes of a cortical mesh, transforming it into surface data. | ||
This data can then be plotted with :func:`nilearn.plotting.plot_surf_stat_map` | ||
for example. | ||
This script shows, on a toy example, where samples are drawn around each mesh | ||
vertex. Image values are interpolated at each sample location, then these | ||
samples are averaged to produce a value for the vertex. | ||
Two strategies are available to choose sample locations: they can be spread | ||
along the normal to the mesh, or inside a ball around the vertex. Don't worry | ||
too much about choosing one or the other: they take a similar amount of time | ||
and give almost identical results for most images. | ||
""" | ||
|
||
import numpy as np | ||
|
||
import matplotlib | ||
from matplotlib import pyplot as plt | ||
from mpl_toolkits.mplot3d import Axes3D | ||
|
||
from nilearn.surface import surface | ||
|
||
|
||
###################################################################### | ||
# Build a mesh (of a cylinder) | ||
###################################################################### | ||
|
||
N_Z = 5 | ||
N_T = 10 | ||
u, v = np.mgrid[:N_T, :N_Z] | ||
triangulation = matplotlib.tri.Triangulation(u.flatten(), v.flatten()) | ||
angles = u.flatten() * 2 * np.pi / N_T | ||
x, y = np.cos(angles), np.sin(angles) | ||
z = v.flatten() * 2 / N_Z | ||
|
||
mesh = [np.asarray([x, y, z]).T, triangulation.triangles] | ||
|
||
|
||
######################################################################### | ||
# Get the locations from which vol_to_surf would draw its samples | ||
######################################################################### | ||
|
||
line_sample_points = surface._line_sample_locations( | ||
mesh, np.eye(4), segment_half_width=.2, n_points=6) | ||
|
||
ball_sample_points = surface._ball_sample_locations( | ||
mesh, np.eye(4), ball_radius=.15, n_points=20) | ||
|
||
|
||
###################################################################### | ||
# Plot the mesh and the sample locations | ||
###################################################################### | ||
|
||
for sample_points in [line_sample_points, ball_sample_points]: | ||
fig = plt.figure() | ||
ax = plt.subplot(projection='3d') | ||
ax.set_aspect(1) | ||
|
||
ax.plot_trisurf(x, y, z, triangles=triangulation.triangles) | ||
|
||
ax.scatter(*sample_points.T, color='r') | ||
|
||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.