Statistical Parametric Mapping (SPM) comes with a nice user interface, but sometimes small Matlab scripts can help answer your research question. A quick search of the web is usually able to find someone else who has encountered the same problem and written a Matlab script. Here are some useful links for SPM scripting.
- Wiki introduction to SPM scripting
- John Ashburners’ Gems for (old versions of SPM, SPM2, SPM5)
- Ged Ridgway’s useful scripts
- Jimmy’s Toolbox.
- Martin Pyka’s SPM for Programmers web pages elegantly illustratea several SPM functions.
- Michael Lombardo has some very useful SPM scripts.
I have a separate web pages describing my various SPM toolboxes and more complicated scripting pipelines:
My own scripts
On this web page I include many of the scripts I use. Several of these scripts were inspired or derived from other people’s scripts, and in these cases the comments in the script gives credit to the original author. For most of these you can run them by passing a parameter (“nii_8bit (‘C:\dir\image.nii’)”) or without (“nii_8bit”) – in the latter case a graphical dialog box(es) guide you through the possible options. The ‘nii_*.m’ scripts are for manipulating NIfTI format images and typically require SPM, the ‘bmp_*.m’ scripts are for manipulating bitmap images, the ‘stat_*.m’ are general statistics, and the ‘t*’ scripts demonstrate the principles of MRI. You can click on each of the links below to view each script independently. However, it is easier to download all of the scripts, executables and images as a single zip archive:
- click here to download all the scripts as a single archive.
- function bmp_blend (A,B,Frac,Outname) Creates weighted average of image A and B
- function bmp_contrast(Filename, Gain, Bias, Linear, Prefix, ShowFigures) Adjusts contrast of image, saving output as bitmap with prefix
- function bmp_mexicanhat(Filename, ShowFigures) Blurs image, uses difference between blur and orignal for edges, creates image with enhanced edges
- function bmp_onCenter_offSurround emulate response of on-center off-surround retinal ganglion cell
- function bmp_scramble (Filename) Creates phase spectrum scrambling bitmap with ‘s’ prefix
- function bmp_sinewave_1d creates a graph of a 1D sinewave
- function bmp_sinewave_2d creates a 2D grayscale sinewave grating
- function bmp_unsharpmask(Filename, lambda, ShowFigures) Blurs image, uses difference between blur and orignal for edges, creates image with enhanced edges
- function bmp_yuv(Filename, Sigma, ShowFigures) Blurs y, u, v components of an image, saving output as bitmap with prefix
- function nii_anat (Img, Outtext) Find normalized mm for MRIcron anat file
- function nii_change_datatype (fname, newType) Change format of stored image data
- function nii_cleanup5(gi,wi,ci, bi,si,ri) clean segmentation partitions for 5 tissue types, optionally create image for volume rendering
- function nii_combine_mask(fnms, filt, isAndMask) Input: multiple images combined using AND or OR logical functions
- function [cropName4D] = nii_cropVolumes (imgName4D, skipVol, nVol) given 4D NIfTI image creates NIfTI image with only selected input volumes
- function d = nii_dice(im1, im2, binarize, im1inten, im2inten) computes Dice’s coefficient (see also nii_jaccard)
- function nii_dilate(P, dilatemm, thresh) dilate binary volume
- function nii_enantiomorphic (anat,lesion) Enantiomorphic normalization, see Nachev et al (2008) http://www.ncbi.nlm.nih.gov/pubmed/18023365
- function nii_extract (V,ClusterMM, V2) Extract object: remove noise from air.
- function nii_fslflirt (Src, Ref, Shadow, OutDir, Prefix, IsInputMask,IsLinearInterp, InvRefWeight) Normalize P->Ref using FLIRT
- function [tr] = nii_getTR(fmriname) Returns Repeat Time in seconds often stored in raw NIfTI header (though removed during processing)
- function j = nii_jaccard(im1, im2, binarize, im1inten, im2inten) computes Jaccard Similarity Index
- function nii_label (fnm, threshold) Threshold volume, then label each cluster in the volume
- function nii_make3d simple script to generate 4d nifti image – useful for testing other routines
- function nii_make4d simple script to generate 4d nifti image – useful for testing other routines
- function nii_makeseed (V, Radius,Mask) Finds peak for each image V, generates image with sphere at peak
- function nii_mask(imgNames, maskName, thresh, val) Masks images imgName with image maskName: values less that thresh in mask are set to val in imgNames
- function nii_mean_stdev (fnms, normBrightness) Given multiple volumes, generate mean, standard deviation, SNR maps and report unusual images. Useful for quality assurance
- function nii_mricro_roi2nii (roinames, imgnames) Convert old MRIcro ROI format to NIfTI format
- function nii_nii2voi (V) Converts a NIfTI image to a MRIcron VOI file.
- function nii_render (P, PreserveCSF, Normalize, Thresh, DilateVox) use segmentation-normalization to generate scalp stripped image for rendering
- function [outhdr, outimg] = nii_reslice_target(inhdr, inimg, tarhdr, linearInterp) Reslice input image to match dimensions of target image (either to disk or memory)
- function coivox = nii_setOrigin(vols, modality) Sets position and orientation of input image(s) to match SPM’s templates
- function nii_xor_mask(fnms, filt) Exclusive or masking, Input: multiple images, output image: voxels are unique to each input
- function nii_thresh (volNames, normalizeIntensity, maxThresh, maxVal, minThresh, minVal) Clip bright and/or dark voxels of input image(s)
- function nii_threshreslicecluster(srcNam, tarNam, thresh, clusterMM3) Reslice image to isotropic 1mm resolution, zero dark voxels, zero small clusters
- function [MeanSignal] = nii_timecourse_roi(IMGname, ROIname) Signal in region of interest: average signal in each volume of Img within mask image ROI
- function Vout = nii_ungz (V) Unzips a .nii.gz image to .nii
- function nii_zeronan(fnms) Voxels with NaN’s are replaced with zero, output has ‘z’ prefix
- function nii_zintensity (Subj, Maskname) Creates version of image where intensity is z-score of brightness in mask
- function [d,beta] = stat_dprime(pHit,pFA) — Convert to Z scores, no error checking
- function t1_fieldstrength plots T1-recovery for same tissue at two field strengths
- function t1_tissue plots T1-recovery for two tissues at the same field strength
- function t2_contrast plots T2-decay curves for two tissues as well as their relative contrast
- function t2_fieldstrength plots T2-decay curves for two tissues as well as their relative contrast
- function t2_tissue plots T2-decay curves for several tissues at the same field strength
- function tr_flipangle(tr) Plots optimal flip angle as a function of repetition time (TR) for given T1