The synthetic volumes toolbox is an SPM12 extension that allows image data to be generated on demand based on a file's name and directory.
The toolbox introduces a new file type using the .synth
extension. In order to be able to use file names ending in .synth
in a model estimation a small number of core SPM files have to be adjusted:
-
spm_select.m
Adds
.synth
to the regular expressions for filtering image-based files. -
spm_existfile.m
Always returns true if a file name ends with
.synth
-
spm_data_hdr_read.m
Handles
.synth
extensions to return volume header structures as defined by the toolbox functionspm_synth_vol()
.spm_synth_vol()
splits thefname
volume header struct field into its directory (the session key) and file name (specifier) parts. The session key and specifier are used to retrieve the image dimension from the SyntheticVolumeGenerator registered for the session. An additional fieldis_synthetic
is defined in the volume header struct and set totrue
. -
spm_data_read.m
Checks for the
is_synthetic
field in the volume header struct to detect a synthetic image.If there are no additional parameters, the volume header is passed to the toolbox function
spm_synth_vol_read()
.spm_synth_vol_read()
again splits thefname
volume header struct field into its directory (the session key) and file name (specifier) parts. Using the session key and specifierspm_synth_vol_read()
then callsSyntheticVolumeGenerator.synthesize_for_session()
to produce the volume data using the volume generator registered for the session. -
spm_read_vols.m
Check for the
is_synthetic
field in the volume header struct to detect a synthetic image. For each synthetic image callspm_synth_vol_read()
instead of the defaultspm_slice_vol()
, which does not support synthetic images.
Applications interested in using the synthetic volume mechanism simply subclass SyntheticVolumeGenerator
to provide their own implementation of two methods:
-
volume_size(obj, specifier)
Retrieve the size of the volume with the given specifier.
-
synthesize(obj, specifier)
Generate the data of the volume with the given specifier.
In order to use an instance of SyntheticVolumeGenerator
it has to be registered, otherwise the .synth
files defined for it will not be resolved. This can be achieved by calling the static method SyntheticVolumeGenerator.add(generator, session_key)
. Once a session is no longer active, an application should de-register it by calling the static method SyntheticVolumeGenerator.remove(session_key)
.
Synthetic volumes are currently not supported by spm_slice_vol()
, and all code that depends on it, except for spm_read_vols()
.
At the Matlab prompt, type:
spm_jobman('initcfg');
The command initialises SPM and ensures that all toolboxes are loaded. Then run:
spm_synth_vol_demo
This will create a directory with a timestamp in the current MATLAB directory. See spm_synth_vol_demo.m
for more details.