For the Experts only. Here we're going to make a spinning "Maximum
Intensity Projection" rendered on a spinning background slice of the
There are two example input pairs of functional/background images
provided, a low resolution pair (
example_func), which is useful for testing the script on,
and a high resolution pair (
highres), for the final rendering.
The output will be an animated GIF, which you can view with your
The inputs are going to be.
- A zstat image
- A Background image
- The incremental rotation (How much the picture should rotate between successive frames)
- The required z-threshold
- The output filename
- Check inputs
- Include a
usage clause which will run if the script is run with the wrong number of inputs.
- Check whether the input files exist.
- Check that the background image and the zstat image have the same dimensions
- Making the rotation matrix
We are going to need a matrix which performs an incremental rotation about a vertical line through centre of the
x-y plane. Remember that (0,0,0) isn't at the centre of a volume so we have to be a little clever...
- Make a matrix which translates the centre of the image to the origin.
- Make a matrix which rotates by the correct increment about the z-axis
- Hint 1: You will need to convert the incremental angle to radians using bc:
inc_rad=`echo "scale=10; $inc_deg * 3.1417 /180"|bc` ;
- Hint2: You can calculate
using bc -l:
cosinc=`echo "c($inc_rad)" | bc -l`; and
sininc=`echo "s($inc_rad)"|bc -l`;
- Invert the first matrix to get a matrix which translates the origin to the image centre.
- Concatenate these three matrices to generate a matrix which rotates around a vertical line through the centre of the
- Generating the Background Image.
We want a "background" slice to rotate with our MIP. A good choice for this is the mid-sagittal plane. Use
fslmaths with the
-roi option to generate an image of the same size as your background but with zeros everywhere apart from the mid-sagittal plane - we're going to rotate this image underneath the MIP.
- Making the movie
while loop which will carry on repeating until the total rotation has reached 360 degrees. Inside this loop you will need to:
fslmaths and the
make mips of the current rotated zstat and mid-sagittal plane images
(outputs will be 2D)
overlay, render the zstat mip on the mid-sag mip with the required threshold
slicer, create a ppm of the resulting 2D image.
convert, convert the ppm to a gif - store this gif to a sensible name.
convert_xfm, create the rotation matrix for the next rotation
flirt rotate the zstat and mid-sag images to their next position.
gifmerge to merge all the gifs into a single animated gif.
Get rid of all unneccessary files you've created.
- Look here for the cheat.