Prepare an atlas for the subcortical pipeline with anatomical context
Source:R/coregister_volume.R
prepare_subcortical_anatomical.RdConvenience wrapper that runs coregister_volume() followed by
project_volume_anatomical() in one call, producing a merged volume
on a FreeSurfer subject's aparc+aseg grid together with a matching
colour table, ready to feed create_subcortical_from_volume().
Usage
prepare_subcortical_anatomical(
input_volume,
lut = NULL,
target_subject = "cvs_avg35_inMNI152",
target_volume = "brain",
threshold = 0.3,
id_offset = 200L,
protect_cortex = TRUE,
dof = 12,
output_file = NULL,
output_lta = NULL,
binarise = TRUE,
subjects_dir = freesurfer::fs_subj_dir(),
skip_existing = FALSE,
verbose = get_verbose()
)Arguments
- input_volume
Path to the atlas volume to coregister, or an
RNiftiobject.- lut
Optional colour LUT (data frame with at least an
idxcolumn, or path to a TSV withidx, label, R, G, B, A). When provided, itsidx(intersected with the volume) selects which labels to project, and it is returned alongside the volume withidxshifted byid_offsetto match. With nolut, every non-zero label is projected. To project a subset, subset thelut.- target_subject
FreeSurfer subject name to register to. Defaults to
"cvs_avg35_inMNI152", which is in MNI152 1mm space.- target_volume
Name of the volume in the subject's
mri/directory used as the registration target. Defaults to"brain"(i.e.brain.mgz).- threshold
Numeric in
[0, 1]. Voxels whose argmax probability does not exceed this threshold are kept as the sourceaparc+aseglabel. Defaults to0.3.- id_offset
Integer added to every input label ID when writing the merged volume to avoid collisions with FreeSurfer
aparc+aseglabels. Defaults to200L. Set to0Lif you have already remapped your IDs (or if you've verified there are no collisions).- protect_cortex
Logical. If
TRUE(default), the cerebral outline inaparc+asegis never overwritten by user labels even when argmax wins abovethreshold: the cortical ribbon (aparc labels1000-2999) plus cerebral white matter (2,41) and the corpus callosum (251-255). This preserves the brain-outline geometry the subcortical pipeline renders as context. Cerebellar structures are not protected here (they are handled downstream byaseg_context()). Disable only if you intentionally want user labels to overwrite the cerebrum.- dof
Degrees of freedom for
mri_coreg(6,9, or12). Defaults to12(rigid + per-axis scale + shear).- output_file
Path for the merged volume. Defaults to a temp file.
- output_lta
Path to write the resulting LTA file. Defaults to a temporary file.
- binarise
Logical. If
TRUE(default), binarise both volumes before coregistration. Set toFALSEto register on raw intensities.- subjects_dir
FreeSurfer
SUBJECTS_DIR. Defaults tofreesurfer::fs_subj_dir().- skip_existing
Skip generating output files that already exist, allowing interrupted atlas creation to resume. If not specified, uses
options("ggseg.extra.skip_existing")or theGGSEG_EXTRA_SKIP_EXISTINGenvironment variable. Default is TRUE.- verbose
Verbosity level:
0(silent),1(standard progress, default), or2(debug, includes FreeSurfer output). Logical values are accepted (TRUE= 1,FALSE= 0). If not specified, uses the value fromoptions("ggseg.extra.verbose")or theGGSEG_EXTRA_VERBOSEenvironment variable.
Value
Invisibly, the list(volume, lut, id_offset) returned by
project_volume_anatomical(). Pass it straight to
create_subcortical_from_volume(), which unpacks volume and lut.
Examples
if (FALSE) { # \dontrun{
merged <- prepare_subcortical_anatomical(
input_volume = "shen_2mm_268_parcellation.nii.gz",
lut = subcortical_lut
)
atlas <- create_subcortical_from_volume(
input_volume = merged,
context = list(focus = "my-structures")
)
} # }