Creating A Movie

For the Experts only. Here we're going to make a spinning "Maximum Intensity Projection" rendered on a spinning background slice of the brain!

There are two example input pairs of functional/background images provided, a low resolution pair (zstat2 / example_func), which is useful for testing the script on, and a high resolution pair (hr_zstat1 / highres), for the final rendering.

The output will be an animated GIF, which you can view with your web browser.

  1. Inputs
    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
  2. 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
  3. 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 sin and cos 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 x-y plane.
  4. 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.
  5. Making the movie
    Make a while loop which will carry on repeating until the total rotation has reached 360 degrees. Inside this loop you will need to:
    • Using fslmaths and the -Xmax option, make mips of the current rotated zstat and mid-sagittal plane images (outputs will be 2D)
    • Using overlay, render the zstat mip on the mid-sag mip with the required threshold
    • Using slicer, create a ppm of the resulting 2D image.
    • Using convert, convert the ppm to a gif - store this gif to a sensible name.
    • Using convert_xfm, create the rotation matrix for the next rotation
    • Using flirt rotate the zstat and mid-sag images to their next position.
  6. use whirlgif to merge all the gifs into a single animated gif.
    Get rid of all unneccessary files you've created.
  7. Look here for the cheat.