Coregistration of two images using core functions¶
This tutorial demonstrates how to coregister two images using the core functions of SPM, instead of relying on the batch system. This leaves the input images untouched and does not write any output files. Instead, the calculated co-registration parameters are returned and can be converter to an affine transformation matrix.
Import SPM
- The SPM-Python module
- Standard operating system tools, which we’ll use to create directories
- To manipulate file paths
- To extract the example data from a zip file
Download example data
print("Downloading Auditory dataset... ")
spm.Runtime.call("urlwrite", url, zip_path) # (1)!
with zipfile.ZipFile(zip_path, "r") as f:
f.extractall(data_path)
- Only SPM functions have a “nice” python wrapper, but you can
also call any MATLAB function using
spm.Runtime.call.
Paths to the two images to co-register
Coregister the two images
spm.spm_figure('Create', 'Graphics', 'Graphics', 'on') # (1)!
ref = spm.spm_vol(fname_struct) # (2)!
mov = spm.spm_vol(fname_func)
prm = spm.spm_coreg(ref, mov) # (3)!
- Create a graphics window to display the results
- Map the two images into a
spm_volobject. - Co-register the two images.