– 2– AFNI = Analysis of Functional Neuro. Images • Developed to provide an environment for FMRI data analyses H And a platform for development of new software • AFNI refers to both the program of that name and the entire package of external programs and plugins (more than 100) • Important principles in the development of AFNI: H Allow user to stay close to the data and view it in many different ways H Give users the power to assemble pieces in different ways to make customized analyses o “With great power comes great responsibility” — to understand the analyses and tools H “Provide mechanism, not policy” H Allow other programmers to add features that can interact with the rest of the package

– 3– Principles (and Caveats) We* Live By • Fix significant bugs as soon as possible H But, we define “significant” • Nothing is secret or hidden (AFNI is open source) H But, possibly not very well documented or advertised • Release early and often H All users are beta-testers for life • Help the user (message board; consulting with NIH users) H Until our patience expires • Try to anticipate users’ future needs H What we think you will need may not be what you actually end up needing *

– 4– Outline of This Talk • Quick introduction to FMRI physics and physiology H So you have some idea of what is going on in the scanner and what is actually being measured • Brief discussion of FMRI experimental designs Block, Event-Related, Hybrid Event-Block H But this is not a course in how to design your FMRI experimental paradigm H • Outlines of standard FMRI processing pipeline (AFNI-ized) Keep this in mind for the rest of the class! H Many experiments require tweaking this “standard” collection of steps to fit the design of the paradigm and/or the inferential goals H • Overview of basic AFNI concepts H Datasets and file formats; Realtime input; Controller panels; SUMA; Batch programs and Plugins

– 7– B 0 = Big Field Produced by Main Magnet • • Purpose is to align H protons in H 2 O (little magnets) Units of B are Tesla (Earth’s field is about 0. 00005 Tesla) H Typical field used in FMRI is 3 Tesla [Main magnet and some of its lines of force] [Little magnets lining up with external lines of force]

– 9– Precession of Magnetization M • Magnetic field B causes M to rotate (“precess”) about the direction of B at a frequency proportional to the size of B — 42 million times per second (42 MHz), per Tesla of B H 127 MHz at B = 3 Tesla — range of radio frequencies ¨ If M is not parallel to B, then it precesses clockwise around the direction of B. ¨ However, “normal” (fully relaxed) situation has M parallel to B, which means there won’t be any precession ¨ N. B. : part of M parallel to B (Mz) does not precess

– 10– B 1 = Excitation (Transmitted) RF Field • Left alone, M will align itself with B in about 2– 3 s H No precession no detectable signal • So don’t leave it alone: apply (transmit) a magnetic field B 1 that fluctuates at the precession frequency (radio frequency=RF) and points perpendicular to B 0 ¨ The effect of the tiny B 1 is to cause M to spiral away from the direction of the static B field ¨ B 1 10– 4 Tesla ¨ This is called resonance ¨ If B 1 frequency is not close to resonance, B 1 has no effect Time = 2– 4 ms

– 11– Readout RF • When excitation RF is turned off, M is left pointed off at some angle to B 0 [flip angle] • Precessing part of M [Mxy] is like having a magnet rotating around at very high speed (at RF speed: millions of revs/second) • Will generate an oscillating voltage in a coil of wires placed around the subject — this is magnetic induction • This voltage is the RF signal = the raw data for MRI • At each instant t, can measure one voltage V(t), which is proportional to the sum of all transverse Mxy inside the coil • Must separate signals originating from different regions • • By reading out data for 5 -60 ms, manipulating B field, being clever … Then have image of Mxy = map of how much signal from each voxel

– 12– Relaxation: Nothing Lasts Forever • In the absence of external B 1, M will go back to being aligned with static field B 0 = relaxation • Part of M perpendicular to B 0 shrinks [Mxy] Time scale for this relaxation H This part of M = transverse magnetization is called T 2 or T 2* H It generates the detectable RF signal = 20 -40 ms in brain H The relaxation of Mxy during readout affects the image • Part of M parallel to B 0 grows back [Mz] Time scale H This part of M = longitudinal magnetization for this relaxation is called T 1 H Not directly detectable, but is converted into = 500 -2500 ms transverse magnetization by external B 1 o Therefore, Mz is the ultimate source of the NMR signal, but is not the proximate source of the signal

– 14– The Concept of Contrast (or Weighting) • Contrast = difference in RF signals — emitted by water protons — between different tissues • Example: gray-white contrast is possible because T 1 is different between these two types of tissue

– 16– What is Functional MRI? • 1991: Discovery that MRI-measurable signal increases a few % locally in the brain subsequent to increases in neuronal activity (Kwong, et al. ) Cartoon of MRI signal in an “activated” brain voxel

– 17– • • How FMRI Experiments Are Done Alternate subject’s neural state between 2 (or more) conditions using sensory stimuli, tasks to perform, . . . H Can only measure relative signals, so must look for changes in the signal between the conditions Acquire MR images repeatedly during this process Search for voxels whose NMR signal time series (up-anddown) matches the stimulus time series pattern (on-and-off) Signal changes due to neural activity are small • Need 1000 or so images in time series (each slice) takes an hour or so to get reliable activation maps • Must break image acquisition into shorter “runs” to give the subject and scanner some break time • • Other small effects can corrupt the results postprocess the data to reduce these effects & be careful Lengthy computations for image recon and temporal pattern matching data analysis usually done offline

– 22– • BUT: “Oversupply” of oxyhemoglobin after activation H Total deoxyhemoglobin decreases H Magnetic field randomness decreases [less paramag stuff] H NMR signal goes up [near veins and capillaries] H This is the important effect for FMRI as currently practiced • Increased capillary perfusion H Most inflowing water molecules exchange to parenchyma at capillaries o i. e. , the water that flows into a brain capillary is not the water that flows out! H Can be detected with perfusion-weighted imaging methods H This factoid is also the basis for 15 O water-based PET H May someday be important in FMRI, but is hard to do now

– 26– FMRI Experiment Design - 1 • Recall hemodynamic (FMRI) response peak is 4 -6 s after neural activation H width is 4 -5 s for very brief (< 1 s) activation H two separate activations less than 12 -15 s apart will have their responses overlap and add up (approximately — more on this in a later talk!) H • Block design experiments: Extended activation, or multiple closely-spaced (< 2 -3 s) activations Multiple FMRI responses overlap and add up to something more impressive than a single brief blip H But can’t distinguish distinct but closely-spaced activations; example: H o o Each brief activation is “subject sees a face for 1 s, presses button #1 if male, #2 if female” and faces come in every 2 s for a 20 s block, then 20 s of “rest”, then a new faces block, etc. What to do about trials where the subject makes a mistake? These are presumably neurally different than correct trials, but there is no way to separate out the activations when the hemodynamics blurs so much in time.

– 27– FMRI Experiment Design - 2 • Event-related designs: H Separate activations in time so can model the FMRI response from each separately, as needed (e. g. , in the case of subject mistakes) H Need to make inter-stimulus intervals vary (“jitter”) if there is any potential time overlap in their FMRI response curves; e. g. , if the events are closer than 12 -15 s in time o H Otherwise, the tail of event #x always overlaps the head of event #x+1 in the same way, and as a result the amplitude of the response in the tail of #x can’t be told from the response in the head of #x+1 Important note! o o o You cannot treat every single event as a distinct entity whose response amplitude is to be calculated separately! You must still group events into classes, and assume that all events in the same class evoke the same response. å Approximate rule: 25+ events per class (with emphasis on the ‘+’) There is just too much noise in FMRI to be able to get an accurate activation map from a single event!

– 28– FMRI Experiment Design - 3 • Hybrid Block/Event-related designs: H The long “blocks” are situations where you set up some continuing condition for the subject H Within this condition, multiple distinct events are given H Example: o o Event stimulus is a picture of a face Block condition is instruction on what the subject is to do when he sees the face: å Condition A: press button #1 for male, #2 for female å Condition B: press button #1 if face is angry, #2 if face is happy Event stimuli in the two conditions may be identical, or at least fungible It is the instructional+attentional modulation between the two conditions that is the goal of such a study å Perhaps you have two groups of subjects (patients and controls) which respond differently in bench tests å You want to find some neural substrates for these differences

– 31– Fundamental AFNI Concepts • Basic unit of data in AFNI is the dataset H A collection of 1 or more 3 D arrays of numbers Each entry in the array is in a particular spatial location in a 3 D grid (a voxel = 3 D pixel) o Image datasets: each array holds a collection of slices from the scanner å Each number is the signal intensity for that particular voxel o Derived datasets: each number is computed from other dataset(s) å e. g. , each voxel value is a t-statistic reporting “activation” significance from an FMRI time series dataset, for that voxel o H Each 3 D array in a dataset is called a sub-brick o There is one number in each voxel in each sub-brick 3 x 3 x 3 Dataset With 4 Sub-bricks

– 32– Dataset Contents: Numbers • Different types of numbers can be stored in datasets H 8 bit bytes (e. g. , from grayscale photos) H 16 bit short integers (e. g. , from MRI scanners) o Each sub-brick may also have a floating point scale factor attached, so that “true” value in each voxel is actually (value in dataset file) H 32 bit floats (e. g. , calculated values; lets you avoid the ) H 24 bit RGB color triples (e. g. , JPEGs from your digital camera!) H 64 bit complex numbers (e. g. , for the physicists in the room) • Different sub-bricks are allowed to have different numeric types and I mean this H But this is not recommended H Will occur if you “catenate” two dissimilar datasets together (e. g. , using 3 d. Tcat or 3 dbucket commands) o Programs will display a warning to the screen if you try this

– 33– Dataset Contents: Header • Besides the voxel numerical values, a dataset also contains auxiliary information, including (some of which is optional): H xyz dimensions of each voxel (in mm) H Orientation of dataset axes; for example, x-axis=R-L, y-axis=A-P, z-axis=I-S axial slices (we call this orientation “RAI”) H Location of dataset in scanner coordinates Needed to overlay one dataset onto another o Very important to get right in FMRI, since we deal with many datasets o H Time between sub-bricks, for 3 D+time datasets o Such datasets are the basic unit of FMRI data (one per imaging run) H Statistical parameters associated with each sub-brick e. g. , a t-statistic sub-brick has degrees-of-freedom parameter stored o e. g. , an F-statistic sub-brick has 2 DOF parameters stored o

– 34– AFNI Dataset Files - I • AFNI formatted datasets are stored in 2 files H The. HEAD file holds all the auxiliary information H The. BRIK file holds all the numbers in all the sub-bricks • Datasets can be in one of 3 coordinate systems (AKA views) H Original data or +orig view: from the scanner H AC-PC aligned or +acpc view: o Dataset rotated/shifted so that the anterior commissure and posterior commissure are horizontal (y-axis), the AC is at (x, y, z)=(0, 0, 0), and the hemispheric fissure is vertical (z-axis) H Talairach or +tlrc view: Dataset has also been rescaled to conform to the Talairach. Tournoux atlas dimensions (R-L=136 mm; A-P=172 mm; I-S=116 mm) o AKA Talairach or Stererotaxic coordinates o Not quite the same as MNI coordinates, but very close o

– 37– Dataset Directories • Datasets are stored in directories, also called sessions H All the datasets in the same session, in the same view, are presumed to be aligned in xyz-coordinates o Voxels with same value of (x, y, z) correspond to same brain location H Can overlay (in color) any one dataset on top of any other one dataset (in grayscale) from same session o Even if voxel sizes and orientations differ H Typical AFNI contents of a session directory are all data derived from a single scanning session for one subject Anatomical reference (T 1 -weighted SPGR or MP-RAGE volume) o 10 -20 3 D+time datasets from FMRI EPI functional runs o Statistical datasets computed from 3 D+time datasets, showing activation (you hope and pray) o Datasets transformed from +orig to +tlrc coordinates, for comparison and conglomeration with datasets from other subjects o

– 38– Getting and Installing AFNI • AFNI runs on Unix systems: Linux, Sun, SGI, Mac OS X H Can run under Windows with Cygwin Unix emulator o This option is really just for trying it out — not for production use • If you are at the NIH: SSCC can install AFNI and update it on your system(s) H You must give us an account with ssh access • You can download precompiled binaries from our Website H http: //afni. nimh. nih. gov/afni H Also: documentation, message board, humor, data, … • You can download source code and compile it • AFNI is updated fairly frequently, so it is important to update occasionally H We won’t help you with old versions!

– 39– AFNI at the NIH Scanners • AFNI can take images in “realtime” from an external program and assemble them into 3 D+time datasets slice-byslice • Jerzy Bodurka (FMRIF) has set up the GE Excite-based scanners (3 T-1, 1. 5 T, NMRF 3 T, and 7 T) to start AFNI automagically when scanning, and send reconstructed images over as soon as they are available: H For immediate display (images and graphs of time series) H Plus graphs of estimate subject head movement • Goal is to let you see data as it is acquired, so that if there any big problems, you can fix them right away H Sample problem: someone typed in the imaging field-ofview (FOV) size wrong (240 cm instead of 24 cm), and got garbage data, but only realized this too late (after subject had left the scanner and gone home) — D’oh!

– 40– A Quick Overview of AFNI • Starting AFNI from the Unix command line H afni reads datasets from the current directory H afni dir 1 dir 2 … reads datasets from directories listed H afni -R reads datasets from current directory and from all directories below it • AFNI also reads a file named. afnirc from your home directory H Used to change many of the defaults Window layout and image/graph viewing setup; popup hints; whether to compress. BRIK files when writing o cf. file README. environment in the AFNI documentation o • Also can read file. afni. startup_script to restore the window layout from a previous run H Created from Define Datamode->Misc->Save Layout menu o cf. file README. driver for what can be done with AFNI scripts

– 41– AFNI controller window at startup Titlebar shows current datasets Switch to different coordinate system Coordinates of current focus point Markers control transformation to +acpc and +tlrc coordinates Control crosshairs appearance Time index Controls color functional overlay Open images and graphs of datasets Miscellaneous menus Open new AFNI controller Switch between directories, underlay (anatomical) datasets, and overlay (functional) datasets Help Button Controls display of overlaid surfaces Close this controller

– 45– Volume Rendering: an AFNI plugin Pick new underlay dataset Name of underlay dataset Sub-brick to display Range of values in underlay Open color overlay controls Range of values to render Change mapping from values in dataset to brightness in image Histogram of values in underlay dataset Mapping from values to opacity Maximum voxel opacity Cutout parts of 3 D volume Menu to control scripting (control rendering from a file) Compute many images in a row Show 2 D crosshairs Render new image immediately when a control is changed Control viewing angles Accumulate a history of rendered images (can later save to an animation) Detailed instructions Force a new image to be Reload values from the dataset rendered Close all rendering windows

– 47– Other Parts of AFNI • Batch mode programs H Are run by typing commands directly to computer, or by putting commands into a text file (script) and later executing them • Good points about batch mode H Can process new datasets exactly the same as old ones H Can link together a sequence of programs to make a customized analysis (a personalized pipeline) H Some analyses take a long time • Bad points about batch mode H Learning curve is “all at once” rather than gradual H If you are, like, under age 35, you may not know how to, like, type commands into a computer o At least we don’t make you use punched cards (yet)

– 49– AFNI Plugins • A plugin is an extension to AFNI that attaches itself to the interactive AFNI GUI H Not the same as a batch program H Offers a relatively easy way to add certain types of interactive functionality to AFNI H A few examples: • Draw Dataset = ROI drawing (draws numbers into voxels) • Render [new] = Volume renderer • Dataset#N = Lets you plot multiple 3 D+time datasets as overlays in an AFNI graph viewer (e. g. , fitted model over data) • Histogram = Plots a histogram of a dataset or piece of one • Edit Tagset = Lets you attach labeled “tag points” to a dataset (e. g. , as anatomical reference markers)

– 50– SUMA, et alii • SUMA is the AFNI surface mapper H For displaying surface models of the cortex o Surface models come from Free. Surfer (MGH) or Sure. Fit/Caret (Wash U) or Brain. Voyager H Can display functional activations mapped from 3 D volumes to the cortical surface H Can draw ROIs directly on the cortical surface o vs. AFNI: ROIs are drawn into the volume • SUMA is a separate program from AFNI, but can “talk” to AFNI so that volume and surface viewing are linked H Click in AFNI or SUMA to change focus point, and the other program jumps to that location at the same time H Functional overlay in AFNI can be sent to SUMA for simultaneous display • And much more — stayed tuned for the SUMA talks to come!