Commit 98c1b94a authored by Saad Jbabdi's avatar Saad Jbabdi
Browse files

added xtract

parent 9461b0d2
......@@ -5,7 +5,6 @@ You may be familiar with using FSLeyes for looking at your data. Perhaps you hav
This has several advantages. For example, you can re-create the same or similar figures simply by editing the script, instead of re-doing all the FSLeyes tinkering. It is also useful if you need to create complex figures for many datasets/subjects.
## Content
* [Using FSLeyes render to create a PNG](#create-png)
......@@ -25,7 +24,7 @@ Here we will instead cheat and use the lazy approach. We will first use the grap
### Creating an examplar
Start by opening FSLeyes. The command below also loads a MNI brain (copy this onto a Terminal shell):
```
```bash
fsleyes -std1mm &
```
......@@ -56,6 +55,8 @@ Now wouldn't it be nice if one could generate the same thing from scratch withou
You can even click on copy to clipboard. Do that, then open a new text file (e.g. with emacs) and paste the result into the text file. The command you get looks very long so I am highlighting in <span style="color:blue">blue</span> the bit about the scene and in <span style="color:red">red</span> the bit about the overlay.
> **Note for Paul: the colours don't render on Gitlab**
----
<code>fsleyes <span style="color:blue">--scene ortho --worldLoc -0.49994659423828125 -17.50005340576172 18.49994659423828 --displaySpace /usr/local/fsl/data/standard/MNI152_T1_1mm.nii.gz --xcentre 0.00000 0.00000 --ycentre 0.00000 0.00000 --zcentre 0.00000 0.00000 --xzoom 100.0 --yzoom 100.0 --zzoom 100.0 --hideLabels --layout horizontal --hidex --hidey --hideCursor --bgColour 1.0 1.0 1.0 --fgColour 0.0 0.0 0.0 --cursorColour 0.0 1.0 0.0 --colourBarLocation top --colourBarLabelSide top-left --colourBarSize 100.0 --labelSize 12 --performance 3 --movieSync </span> /usr/local/fsl/data/standard/MNI152_T1_1mm.nii.gz <span style="color:red">--name "MNI152_T1_1mm" --overlayType volume --alpha 100.0 --brightness 52.4977497749775 --contrast 64.99649964996499 --cmap cool --negativeCmap greyscale --displayRange 1000.0 8000.0 --clippingRange 1000.0 10098.99 --modulateRange 0.0 9999.0 --gamma 0.0 --cmapResolution 7 --interpolation spline --numSteps 100 --blendFactor 0.1 --smoothing 0 --resolution 100 --numInnerSteps 10 --clipMode intersection --volume 0</code>
......@@ -66,7 +67,7 @@ If you run it all in a Terminal it will open FSLeyes and set it up to look like
Now as I said the command line is long and contains many things that are default behaviour anyway. So let's strip it down a little bit as it will make this document shorter. In the below, I am only keeping a subset of the options, but I did not add new ones:
```
```bash
fsleyes --scene ortho --hideLabels --layout horizontal --hidex --hidey --hideCursor --bgColour 1.0 1.0 1.0 --fgColour 0.0 0.0 0.0 /usr/local/fsl/data/standard/MNI152_T1_1mm.nii.gz --overlayType volume --cmap cool --displayRange 1000.0 8000.0 --cmapResolution 7 --interpolation spline
```
......@@ -96,20 +97,20 @@ First, make sure that you have ImageMagick installed. To do that, go to your ter
We will re-use the previous render command. Start by copying that into a text editor. You can use the code below:
```
```bash
fsleyes render --outfile my_image.png --scene ortho --hideLabels --layout horizontal --hidex --hidey --hideCursor --bgColour 1.0 1.0 1.0 --fgColour 0.0 0.0 0.0 /usr/local/fsl/data/standard/MNI152_T1_1mm.nii.gz --overlayType volume --cmap cool --displayRange 1000.0 8000.0 --cmapResolution 7 --interpolation spline
```
Now to change the z-location, we will use the `-voxelLoc` flag. We will also use a FOR loop to change the location, and store a different PNG at each step. Here is what the code will look like (copy it onto your text editor):
```
```bash
rest_of_command="--scene ortho --hideLabels --layout horizontal --hidex --hidey --hideCursor --bgColour 1.0 1.0 1.0 --fgColour 0.0 0.0 0.0 /usr/local/fsl/data/standard/MNI152_T1_1mm.nii.gz --overlayType volume --cmap cool --displayRange 1000.0 8000.0 --cmapResolution 7 --interpolation spline"
mkdir -p my_folder
for ((z=0;z<=181;z+=4));do
zzz=`$FSLDIR/bin/zeropad $z 3`
echo "Slice $z"zz
echo "Slice $zzz"
out=my_folder/image_${zzz}.png
fsleyes render --outfile $out --voxelLoc 91 109 $z $rest_of_command
......@@ -124,7 +125,7 @@ Run this script and you should see that many PNGs will get created, one per slic
Now to combine all these PNGs into a single GIF, run the below ImageMagick command:
```
```bash
convert -delay 1 my_folder/image_???.png -loop 0 my_movie.gif
```
......@@ -132,14 +133,14 @@ Have a look at the GIF. On a mac you can simply use the space bar on your keyboa
It is still missing the changing text. We will also use ImageMagick for this. Below is the same script as before but with the addition of a call to `convert` that adds the text:
```
```bash
rest_of_command="--scene ortho --hideLabels --layout horizontal --hidex --hidey --hideCursor --bgColour 1.0 1.0 1.0 --fgColour 0.0 0.0 0.0 /usr/local/fsl/data/standard/MNI152_T1_1mm.nii.gz --overlayType volume --cmap cool --displayRange 1000.0 8000.0 --cmapResolution 7 --interpolation spline"
mkdir -p my_folder
for ((z=0;z<=181;z+=4));do
zzz=`$FSLDIR/bin/zeropad $z 3`
echo "Slice $z"zz
echo "Slice $zzz"
out=my_folder/image_${zzz}.png
fsleyes render --outfile $out --voxelLoc 91 109 $z $rest_of_command
......@@ -155,7 +156,7 @@ done
Now run the above, then run the below to make the final GIF:
```
```bash
convert -delay 1 my_folder/image_annot_???.png -loop 0 my_annotated_movie.gif
```
......@@ -168,7 +169,7 @@ The video that we have just created is nice. But wouldn't it be even better if w
Open a new session of FSLeyes with a 2mm standard brain, this time directly in 3D mode:
```
```bash
fsleyes -std --scene 3d &
```
......@@ -183,7 +184,7 @@ Copy the command line that creates this scene as we have done before (Settings->
Now we are going to create a FOR loop where we will change the angles of the clipping planes and save each angle in a separate PNG files. We will then combine them into a single GIF. In the code below, you can find the FOR loop, all that is missing is the command line fsleyes that you have copied to the clipboard:
```
```bash
outputfolder=my_pacman
mkdir -p $outputfolder
......@@ -193,12 +194,11 @@ for ((angle1=0,angle2=180;angle1<=16;angle1++,angle2--));do
fsleyes render --outfile $outputfolder/grot_`zeropad $z 3`.png [INSERT THE COMMAND HERE AND PUT IN $angle1 AND $angle2 WHERE YOU THINK THEY SHOULD GO ]
done
```
Run the command above (after suitable changes - or you can copy my [version](data/cmd.txt)) and then run the below to produce the GIF:
```
```bash
convert -delay .2 `ls $outputfolder/grot_???.png` `ls -r $outputfolder/grot_???.png` -loop 0 $outputfolder/pacman.gif
```
......@@ -208,18 +208,39 @@ You should be able to see this GIF:
<img src="data/snapshot4.gif" alt="snapshot4" style="width:400px;"/>
<a class="anchor" id="create-for-paper"></a>
## Figure for a paper
Often in a paper you see figures showing multiple brain slices with overlayed activations. Let's create one of these.
Again we will follow the lazy strategy of doing it manually in the graphical interface, saving the command, stripping it, and modifying it to fit our needs.
By now hopefully you have seen how you can combine the power of intuitively interacting with the FSLeyes graphical interface and the power of bash scripting. We'll do one more example of creating a nice graphic and then rendering it in a bash script. This one will look very nice.
Run the code below. It will open FSLeyes, with a 2mm MNI brain, and will also load the XTRACT tracts atlas.
```
```bash
fsleyes -std $FSLDIR/data/atlases/XTRACT/xtract-tract-atlases-prob-1mm &
```
We will try to make this nice by displaying the two images using maximum intensity projections.
Do the following:
- Change the colourmap of the MNI brain to "Bone"
- Change its min/max display range to 5000-10000
- Change the colourmap of the tracts to "Red-Yellow"
- Change the display type of both from "3d/4D volume" to "Maximum intensity projection"
- Change the MNI brain to have "Spline interpolation"
- Select volume number 14 for the tracts
- Untoggle the axial view
- Copy the command line onto the clipboard as before
[This](data/tracts.txt) is what I got after doing the above (feel free to use that).
Now use FSleyes render to create a nice looking figure. We will also control the DPI (digits per inch) of this figure, as some journal publishers insist that you have good quality images.
```
fsleyes render --outfile my_tract.png --size 800 600 <COPY REST OF THE COMMAND HERE>
```
> Exercise : create a FOR loop that produces a snapshot like the one above for all the XTRACT tracts.
The End.
\ No newline at end of file
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