Commit f80d0658 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: render for macOS (MC), new wrapper output syntax, other small tweaks

parent c4304366
...@@ -102,13 +102,24 @@ And another function which uses FSLeyes for more complex plots: ...@@ -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): def render(cmdline):
import shlex
import IPython.display as display
prefix = '-of screenshot.png -hl -c 2 ' 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') return display.Image('screenshot.png')
``` ```
...@@ -278,7 +289,7 @@ corresponding `nibabel` types: ...@@ -278,7 +289,7 @@ corresponding `nibabel` types:
class uses `dcm2niix` to load NIfTI images contained within a DICOM class uses `dcm2niix` to load NIfTI images contained within a DICOM
directory<sup>*</sup>. directory<sup>*</sup>.
* The * The
[`fsl.data.mghimahe.MGHImage`](https://users.fmrib.ox.ac.uk/~paulmc/fsleyes/fslpy/latest/fsl.data.mghimage.html) [`fsl.data.mghimage.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 class can be used too load `.mgh`/`.mgz` images (they are converted into
NIfTI images). NIfTI images).
* The * The
...@@ -304,11 +315,12 @@ corresponding `nibabel` types: ...@@ -304,11 +315,12 @@ corresponding `nibabel` types:
and and
[`fsl.data.vtk`](https://users.fmrib.ox.ac.uk/~paulmc/fsleyes/fslpy/latest/fsl.data.vtk.html) [`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, 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 > <sup>*</sup>You must make sure that
> in order to use this class. > [`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> <a class="anchor" id="nifti-coordinate-systems"></a>
...@@ -440,6 +452,10 @@ from fsl.transform.affine import concat ...@@ -440,6 +452,10 @@ from fsl.transform.affine import concat
funcvox2mni = concat(fsl2mni, func2std, vox2fsl) 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 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: 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) ...@@ -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 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') 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(cropped.data, (80, 112, 85), cmap=plt.cm.gray)
fig = ortho(betted .data, (80, 112, 85), cmap=plt.cm.inferno, fig=fig) 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) ...@@ -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 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 are loaded will be available through the return value of the wrapper function:
the key:
``` ```
...@@ -657,9 +676,10 @@ func2std = np.loadtxt(op.join('08_fslpy', 'fmri.feat', 'reg', 'example_func2stan ...@@ -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) aligned = flirt(tstat1, std2mm, applyxfm=True, init=func2std, out=LOAD)
print(aligned) # Here the resampled tstat image
# is called "out", because that
aligned = aligned['out'].data # is the name of the flirt argument.
aligned = aligned.out.data
aligned[aligned < 1] = 0 aligned[aligned < 1] = 0
fig = ortho(std2mm .data, (45, 54, 45), cmap=plt.cm.gray) 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) ...@@ -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 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 *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') img = Image('bighead_cropped')
betted = bet(img, LOAD, f=0.3, m=True) 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(img .data, (80, 112, 85), cmap=plt.cm.gray) fig = ortho(betted.output_mask.data, (80, 112, 85), cmap=plt.cm.summer, fig=fig, alpha=0.5)
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')) ...@@ -1089,8 +1107,8 @@ std2mm = Image(op.join(stddir, 'MNI152_T1_2mm'))
frontal = lblatlas.get(name='Frontal Pole').data frontal = lblatlas.get(name='Frontal Pole').data
frontal = np.ma.masked_where(frontal < 1, frontal) frontal = np.ma.masked_where(frontal < 1, frontal)
fig = ortho(std2mm, (45, 54, 45), cmap=plt.cm.gray) fig = ortho(std2mm.data, (45, 54, 45), cmap=plt.cm.gray)
fig = ortho(frontal, (45, 54, 45), cmap=plt.cm.winter, fig=fig) fig = ortho(frontal, (45, 54, 45), cmap=plt.cm.winter, fig=fig)
``` ```
...@@ -1104,8 +1122,8 @@ std2mm = Image(op.join(stddir, 'MNI152_T1_2mm')) ...@@ -1104,8 +1122,8 @@ std2mm = Image(op.join(stddir, 'MNI152_T1_2mm'))
frontal = probatlas.get(name='Frontal Pole') frontal = probatlas.get(name='Frontal Pole')
frontal = np.ma.masked_where(frontal < 1, frontal) frontal = np.ma.masked_where(frontal < 1, frontal)
fig = ortho(std2mm, (45, 54, 45), cmap=plt.cm.gray) fig = ortho(std2mm.data, (45, 54, 45), cmap=plt.cm.gray)
fig = ortho(frontal, (45, 54, 45), cmap=plt.cm.inferno, fig=fig) fig = ortho(frontal, (45, 54, 45), cmap=plt.cm.inferno, fig=fig)
``` ```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment