SPM/Programming intro

< SPM

Aim

This page is intended to provide a quick-start guide to writing your own MATLAB scripts and functions using SPM as a library. SPM programming can mean simply writing batch scripts to automate common pipelines, writing short helper scripts or functions to accomplish useful tasks, writing your own SPM extensions, or even modifying your local installation of SPM.

MATLAB

MATLAB is a programming language developed by MathWorks.

Many MATLAB tutorials are available online:

There are also useful books:

MATLAB courses:

SPM functions

Introduction

SPM has extensive developer documentation in the headers of the source files. To view the documentation of a function either open the corresponding source file or call help function from the MATLAB command line. Make sure that the SPM folder is in MATLABs search path.

Reading image headers and data

Writing data

Reading and writing data with the alternative NIfTI class library

Geometry, voxel-world mappings

Linear (rigid/affine) registration and reslicing

Preprocessing, including segmentation and non-linear normalisation

Processing

Statistics

Viewing data

Configuration

Batch System

Illustrative examples

Reading and writing a volume (to replace NaNs with zeros)

A simpler (but more memory-hungry) version of an old Gem. See the SPM8 version of gem for an example of plane-wise reading and writing.

fnm = spm_select(1, 'image');
[pth, bnm, ext] = spm_fileparts(fnm);
VI = spm_vol(fnm);
VO = VI; % copy input info for output image
VO.fname = fullfile(pth, [bnm '_zn' ext]);
img = spm_read_vols(VI);
img(isnan(img)) = 0; % use ~isfinite instead of isnan to replace +/-inf with zero
spm_write_vol(VO,img);

See also:

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.