Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pytreat-practicals-2020
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
pytreat-practicals-2020
Commits
f80d0658
Commit
f80d0658
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: render for macOS (MC), new wrapper output syntax, other small tweaks
parent
c4304366
No related branches found
No related tags found
1 merge request
!14
fslpy practical
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
advanced_topics/08_fslpy.md
+44
-26
44 additions, 26 deletions
advanced_topics/08_fslpy.md
with
44 additions
and
26 deletions
advanced_topics/08_fslpy.md
+
44
−
26
View file @
f80d0658
...
...
@@ -102,13 +102,24 @@ And another function which uses FSLeyes for more complex plots:
```
import shlex
import IPython.display as display
from fsleyes.render import main
def render(cmdline):
import shlex
import IPython.display as display
prefix = '-of screenshot.png -hl -c 2 '
main(shlex.split(prefix + cmdline))
try:
from fsleyes.render import main
main(shlex.split(prefix + cmdline))
except ImportError:
# fall-back for macOS - we have to run
# FSLeyes render in a separate process
from fsl.utils.run import runfsl
prefix = 'render ' + prefix
runfsl(prefix + cmdline, env={})
return display.Image('screenshot.png')
```
...
...
@@ -278,7 +289,7 @@ corresponding `nibabel` types:
class uses `
dcm2niix
` to load NIfTI images contained within a DICOM
directory<sup>*</sup>.
* The
[`
fsl.data.mghima
h
e.MGHImage
`](https://users.fmrib.ox.ac.uk/~paulmc/fsleyes/fslpy/latest/fsl.data.mghimage.html)
[`
fsl.data.mghima
g
e.MGHImage
`](https://users.fmrib.ox.ac.uk/~paulmc/fsleyes/fslpy/latest/fsl.data.mghimage.html)
class can be used too load `
.mgh
`/`
.mgz
` images (they are converted into
NIfTI images).
* The
...
...
@@ -304,11 +315,12 @@ corresponding `nibabel` types:
and
[`
fsl.data.vtk
`](https://users.fmrib.ox.ac.uk/~paulmc/fsleyes/fslpy/latest/fsl.data.vtk.html)
modules contain functionality form loading surface data from GIfTI,
freesurfer, and VTK files respectively.
freesurfer, and
ASCII
VTK files respectively.
> <sup>*</sup>You must make sure that `
dcm2niix
` is installed on your system
> in order to use this class.
> <sup>*</sup>You must make sure that
> [`
dcm2niix
`](https://github.com/rordenlab/dcm2niix/) is installed on your
> system in order to use this class.
<a class="anchor" id="nifti-coordinate-systems"></a>
...
...
@@ -440,6 +452,10 @@ from fsl.transform.affine import concat
funcvox2mni = concat(fsl2mni, func2std, vox2fsl)
```
> Below we will use the
> [`
fsl.transform.flirt.fromFlirt
`](https://users.fmrib.ox.ac.uk/~paulmc/fsleyes/fslpy/latest/fsl.transform.flirt.html#fsl.transform.flirt.fromFlirt)
> function, which does all of the above for us.
So we've now got some voxel coordinates from our functional data, and an
affine to transform into MNI world coordinates. The rest is easy:
...
...
@@ -631,12 +647,16 @@ fig = ortho(betted .data, (80, 112, 85), cmap=plt.cm.inferno, fig=fig)
By using the special `
fsl.wrappers.LOAD
` symbol, you can also have any output
files produced by the tool automatically loaded:
files produced by the tool automatically loaded
into memory for you
:
```
cropped = Image('bighead_cropped')
betted = bet(cropped, LOAD)['output']
# The loaded result is called "output",
# because that is the name of the
# argument in the bet wrapper function.
betted = bet(cropped, LOAD).output
fig = ortho(cropped.data, (80, 112, 85), cmap=plt.cm.gray)
fig = ortho(betted .data, (80, 112, 85), cmap=plt.cm.inferno, fig=fig)
...
...
@@ -644,8 +664,7 @@ fig = ortho(betted .data, (80, 112, 85), cmap=plt.cm.inferno, fig=fig)
You can use the `
LOAD
` symbol for any output argument - any output files which
are loaded will be returned in a dictionary, with the argument name used as
the key:
are loaded will be available through the return value of the wrapper function:
```
...
...
@@ -657,9 +676,10 @@ func2std = np.loadtxt(op.join('08_fslpy', 'fmri.feat', 'reg', 'example_func2stan
aligned = flirt(tstat1, std2mm, applyxfm=True, init=func2std, out=LOAD)
print(aligned)
aligned = aligned['out'].data
# Here the resampled tstat image
# is called "out", because that
# is the name of the flirt argument.
aligned = aligned.out.data
aligned[aligned < 1] = 0
fig = ortho(std2mm .data, (45, 54, 45), cmap=plt.cm.gray)
...
...
@@ -669,18 +689,16 @@ fig = ortho(aligned.data, (45, 54, 45), cmap=plt.cm.inferno, fig=fig)
For tools like `
bet
` and `
fast
`, which expect an output *prefix* or
*basename*, you can just set the prefix to `
LOAD
` - all output files with that
prefix will be available in the
returned dictionary
:
prefix will be available in the
object that is returned
:
```
img = Image('bighead_cropped')
betted = bet(img, LOAD, f=0.3, m=True)
print(betted)
fig = ortho(img .data, (80, 112, 85), cmap=plt.cm.gray)
fig = ortho(betted['output'] .data, (80, 112, 85), cmap=plt.cm.inferno, fig=fig)
fig = ortho(betted['output_mask'].data, (80, 112, 85), cmap=plt.cm.summer, fig=fig, alpha=0.5)
fig = ortho(img .data, (80, 112, 85), cmap=plt.cm.gray)
fig = ortho(betted.output .data, (80, 112, 85), cmap=plt.cm.inferno, fig=fig)
fig = ortho(betted.output_mask.data, (80, 112, 85), cmap=plt.cm.summer, fig=fig, alpha=0.5)
```
...
...
@@ -1089,8 +1107,8 @@ std2mm = Image(op.join(stddir, 'MNI152_T1_2mm'))
frontal = lblatlas.get(name='Frontal Pole').data
frontal = np.ma.masked_where(frontal < 1, frontal)
fig = ortho(std2mm,
(45, 54, 45), cmap=plt.cm.gray)
fig = ortho(frontal, (45, 54, 45), cmap=plt.cm.winter, fig=fig)
fig = ortho(std2mm
.data
, (45, 54, 45), cmap=plt.cm.gray)
fig = ortho(frontal,
(45, 54, 45), cmap=plt.cm.winter, fig=fig)
```
...
...
@@ -1104,8 +1122,8 @@ std2mm = Image(op.join(stddir, 'MNI152_T1_2mm'))
frontal = probatlas.get(name='Frontal Pole')
frontal = np.ma.masked_where(frontal < 1, frontal)
fig = ortho(std2mm,
(45, 54, 45), cmap=plt.cm.gray)
fig = ortho(frontal, (45, 54, 45), cmap=plt.cm.inferno, fig=fig)
fig = ortho(std2mm
.data
, (45, 54, 45), cmap=plt.cm.gray)
fig = ortho(frontal,
(45, 54, 45), cmap=plt.cm.inferno, fig=fig)
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment