-
Notifications
You must be signed in to change notification settings - Fork 576
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
[MRG] Cortex surface projections #1516
Changes from 96 commits
b966ac9
07881d0
0f29725
0771374
e15d04b
c0c39d3
398965d
4589a95
c7af4b1
9f84b24
0c3e1d4
c5d83b5
d1d9536
cdcbed1
58bd2f8
33bb932
536cc19
389851d
07d62bd
9fb10f0
d836a6f
5704948
eef5060
85624ab
6da5a92
c234e60
3cf1f35
8ad1071
2e585d5
21a7ff0
bfe4c74
11e8c17
ecd96c3
63533ec
9d16db7
c6e34a1
c49c5c0
25ae312
2a20304
4739d22
6ac2386
1f55f47
e8cc677
55878d6
6f309ad
c50a5c3
77dd10f
c5eea1d
6aa3f12
fe49498
244eab2
6ba9b53
76d4f50
1cbd3b3
754b834
7d85051
f1f3836
fa838cf
83ca7a4
40bbfa4
d3d69c2
d0982ad
2128c77
fcb8954
73c3d25
e0bd9b8
756bd31
6785cda
2c74c84
43bae74
bf904e3
5e5f264
59049a8
ea3f39e
94cf01c
b11d0d1
fca0e78
1f03b77
cec5afd
43e4be2
91b2c17
ed016cc
a70bb83
f313e3d
c0d56d6
82d7670
a00d642
e38ecb9
9f294a8
e717059
079ddcd
25a09f6
9e52d9f
1b2aec1
6c2244f
4cca98a
ed78a66
3376c51
d1a5779
c8c440d
1ad5546
28c26a0
256a8b1
b86bfb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
# --------------- | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be aware that could you please comment saying that plot_surf_stat_map works ? NOTE: Example needs matplotlib version higher than 1.3.1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry what should the comment say? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added your NOTE to the docstring |
||
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() |
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add load_surf_data and load_surf_mes here