Title: | Extra Utilities for the 'ggseg' and 'ggseg3d' Plotting Tools |
---|---|
Description: | Contains functions to create new data sets compatible with the 'ggseg' and 'ggseg3d' packages for plotting brain segmentations through R. Requires several external software to be installed on the system for atlas creations to work, and most of these are not available for windows. But atlas creation tools exist for 2d simple features data, and also 3d tri-surface mesh plots. Also has a list of compatible data sets and functions for easy installation of these. |
Authors: | Athanasia Mo Mowinckel [aut, cre] , Didac Vidal-Piñeiro [aut] , John Muschelli [ctb] |
Maintainer: | Athanasia Mo Mowinckel <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.5.33.004 |
Built: | 2024-11-20 02:52:40 UTC |
Source: | https://github.com/ggseg/ggsegExtra |
This function will create an atlas ready data.frame for ggseg3d to plot with plotly.
aparc_2_mesh( subject = "fsaverage5", hemisphere = "rh", surface = "inflated", annot = "aparc", subjects_dir = freesurfer::fs_subj_dir(), annot_dir = file.path(subjects_dir, subject, "label"), output_dir = tempdir(), cleanup = TRUE, verbose = TRUE )
aparc_2_mesh( subject = "fsaverage5", hemisphere = "rh", surface = "inflated", annot = "aparc", subjects_dir = freesurfer::fs_subj_dir(), annot_dir = file.path(subjects_dir, subject, "label"), output_dir = tempdir(), cleanup = TRUE, verbose = TRUE )
subject |
Freesurfer subject, must exist in whatever subject directory specified or set in the environment with $SUBJECTS_DIR |
hemisphere |
hemisphere, either "rh" or "lh" |
surface |
surface from subjects surf-folder |
annot |
base-name of annot file |
subjects_dir |
Freesurfer subject directory |
annot_dir |
path to directory with annot-files |
output_dir |
output directory path |
cleanup |
logical to toggle removal of all intermediary files |
verbose |
logical indicating to be verbose or not |
Based on A. Winkler scripts
data frame with one row per label
## Not run: dt <- aparc_2_mesh() dt <- aparc_2_mesh(surface = "white") dt <- aparc_2_mesh(hemisphere = "lh") dt <- aparc_2_mesh(annot = "aparc.a2009s") ## End(Not run)
## Not run: dt <- aparc_2_mesh() dt <- aparc_2_mesh(surface = "white") dt <- aparc_2_mesh(hemisphere = "lh") dt <- aparc_2_mesh(annot = "aparc.a2009s") ## End(Not run)
Create a FreeSurfer colortab based
on labels. Calls FreeSurfer's mris_lab2ctab
atlas_lab2ctab(output_dir, verbose)
atlas_lab2ctab(output_dir, verbose)
output_dir |
output directory path |
verbose |
logical indicating to be verbose or not |
returns nothing, creates files on the file system
Turn volumetric files into labels for
use in annotations. Calls FreeSurfer's
mri_vol2label
.
atlas_vol2label(annot_lab, output_dir, verbose, ncores = 2)
atlas_vol2label(annot_lab, output_dir, verbose, ncores = 2)
annot_lab |
annotation label |
output_dir |
output directory path |
verbose |
logical indicating to be verbose or not |
ncores |
number of cores for parallel processing (default numcores-2) |
invisibly returns the list of labels.
Transform a Nifti volume to a surface
file for FreeSurfer. Calls
FreeSurfer's mri_vol2surf
for the transformation.
atlas_vol2surf(input_file, output_dir, projfrac = 0.5, verbose = TRUE)
atlas_vol2surf(input_file, output_dir, projfrac = 0.5, verbose = TRUE)
input_file |
nifti volume |
output_dir |
output directory path |
projfrac |
value to mri_vol2surf -projfrac |
verbose |
logical indicating to be verbose or not |
nothing, creates surface files
Change meshes to new system
change_meshes(mesh)
change_meshes(mesh)
mesh |
mesh object |
Check if FS can be run
check_fs(msg = NULL)
check_fs(msg = NULL)
msg |
message to print on error |
logical
Function to convert Freesurfer curvature file into .ply
curv2ply(input_file, output_file = paste(input_file, ".ply"), verbose = TRUE)
curv2ply(input_file, output_file = paste(input_file, ".ply"), verbose = TRUE)
input_file |
path to Freesurfer curvature file |
output_file |
path to output file |
verbose |
logical indicating to be verbose or not |
.ply text
Available Freesurfer curvatures
fs_curvatures()
fs_curvatures()
character
fs_curvatures()
fs_curvatures()
Available Freesurfer no fix curvatures
fs_nofixcurv()
fs_nofixcurv()
character
fs_nofixcurv()
fs_nofixcurv()
Available Freesurfer surfaces
fs_surfaces()
fs_surfaces()
character
fs_surfaces()
fs_surfaces()
.ply files contain a lot of information. for ggseg3d, we only need information on the vertices and faces of the mesh. Thes function opens a ply file, and organises the meshes and faces into a single list.
get_mesh(ply, ...)
get_mesh(ply, ...)
ply |
path to ply-file |
... |
arguments to |
list of meshes and faces
## Not run: get_mesh("path/to/surface.ply") # Turn off showing the ply when reading get_mesh("path/to/surface.ply", ShowSpecimen = FALSE) ## End(Not run)
## Not run: get_mesh("path/to/surface.ply") # Turn off showing the ply when reading get_mesh("path/to/surface.ply", ShowSpecimen = FALSE) ## End(Not run)
Function to easily find all online repositories that contain ggseg atlases
ggseg_atlas_repos(pattern = NULL, ...)
ggseg_atlas_repos(pattern = NULL, ...)
pattern |
string pattern to search repos |
... |
additional arguments to |
data frame of online repositories with ggseg-atlases
ggseg_atlas_repos() ggseg_atlas_repos("yeo")
ggseg_atlas_repos() ggseg_atlas_repos("yeo")
installs ggseg-atlas library from the ggseg r-universe <https://ggseg.r-universe.dev/ui#builds> .
install_ggseg_atlas( package, repos = c(ggseg = "https://ggseg.r-universe.dev", getOption("repos")), ... )
install_ggseg_atlas( package, repos = c(ggseg = "https://ggseg.r-universe.dev", getOption("repos")), ... )
package |
package name |
repos |
vector of repositories to install from. Defaults to ggseg r-universe and CRAN. |
... |
additional arguments to |
To install, will temporarily alter your install repo settings to also use the ggseg r-universe build as source for packages. These settings will be restored when the function exits.
## Not run: yeo2011_repo <- ggseg_atlas_repos("yeo2011") install_ggseg_atlas(yeo2011_repo$repo, yeo2011_repo$source) ## End(Not run)
## Not run: yeo2011_repo <- ggseg_atlas_repos("yeo2011") install_ggseg_atlas(yeo2011_repo$repo, yeo2011_repo$source) ## End(Not run)
Calls ggseg_atlas_repos
,
and installs all libraries listed.
Be careful calling this function, this
will likely take quite some time to
complete, and also will contain a lot of
heavy data. We recommend only installing
atlases you are likely to use and on demand.
install_ggseg_atlas_all( repos = c(ggseg = "https://ggseg.r-universe.dev", getOption("repos")), ... )
install_ggseg_atlas_all( repos = c(ggseg = "https://ggseg.r-universe.dev", getOption("repos")), ... )
repos |
repositories to install from. Defaults to ggseg r-universe and a CRAN mirror. |
... |
additional arguments to |
## Not run: install_ggseg_atlas_all() ## End(Not run)
## Not run: install_ggseg_atlas_all() ## End(Not run)
Check if object is colourtable
is_ctab(colourtable)
is_ctab(colourtable)
colourtable |
data frame with colour table |
logical
Convert LCBC surface file to other subjects
lcbc_surf2surf( input_volume, source_subject = "fsaverage", target_subject = "fsaverage5", hemisphere = "rh", subjects_dir = fs_subj_dir(), output_dir = file.path(subjects_dir, target_subject, "surf"), cortex = TRUE, verbose = TRUE )
lcbc_surf2surf( input_volume, source_subject = "fsaverage", target_subject = "fsaverage5", hemisphere = "rh", subjects_dir = fs_subj_dir(), output_dir = file.path(subjects_dir, target_subject, "surf"), cortex = TRUE, verbose = TRUE )
input_volume |
path to input volume |
source_subject |
source subject |
target_subject |
target subject |
hemisphere |
hemisphere, either "rh" or "lh" |
subjects_dir |
Freesurfer subject directory |
output_dir |
output directory path |
cortex |
toggle "–cortex" (TRUE) or "–no-cortex" (FALSE) |
verbose |
logical indicating to be verbose or not |
Function loops through hemispheres and surfaces to create a data frame that is ready to use with ggseg3d.
make_aparc_2_3datlas( annot, subject = "fsaverage5", hemisphere = c("rh", "lh"), surface = c("inflated", "LCBC"), subjects_dir = freesurfer::fs_subj_dir(), annot_dir = file.path(subjects_dir, subject, "label"), output_dir = tempdir(), ncores = parallel::detectCores() - 2, cleanup = TRUE, verbose = TRUE )
make_aparc_2_3datlas( annot, subject = "fsaverage5", hemisphere = c("rh", "lh"), surface = c("inflated", "LCBC"), subjects_dir = freesurfer::fs_subj_dir(), annot_dir = file.path(subjects_dir, subject, "label"), output_dir = tempdir(), ncores = parallel::detectCores() - 2, cleanup = TRUE, verbose = TRUE )
annot |
annotation file, with name [hemi].[annot].annot abd be in annot_dir |
subject |
Freesurfer subject, must exist in whatever subject directory specified or set in the environment with $SUBJECTS_DIR |
hemisphere |
hemisphere, either "rh" or "lh" |
surface |
Freesurfer surface |
subjects_dir |
Freesurfer subject directory |
annot_dir |
path to directory with annot-files |
output_dir |
output directory path |
ncores |
number of cores for parallel processing (default numcores-2) |
cleanup |
logical to toggle removal of all intermediary files |
verbose |
logical indicating to be verbose or not |
It is recommended that you change the region names for the atlas, and the atlas name to something shorter. See the dk_3d atlas for examples.
nested data frame as ggseg3d-atlas
## Not run: dt <- aparc_2_3datlas(annot = "aparc.a2009s") dt <- aparc_2_3datlas(annot = "aparc.a2009s", surface = "sphere") ## End(Not run)
## Not run: dt <- aparc_2_3datlas(annot = "aparc.a2009s") dt <- aparc_2_3datlas(annot = "aparc.a2009s", surface = "sphere") ## End(Not run)
Function will create a data.frame based on a ggseg3d atlas, based on the contours of each segment.
make_ggseg3d_2_ggseg( ggseg3d_atlas, steps = 1:7, output_dir = tempdir(), tolerance = 0, smoothness = 5, cleanup = FALSE, ncores = 2 )
make_ggseg3d_2_ggseg( ggseg3d_atlas, steps = 1:7, output_dir = tempdir(), tolerance = 0, smoothness = 5, cleanup = FALSE, ncores = 2 )
ggseg3d_atlas |
object of class ggseg3d-atlas |
steps |
numeric vector of steps to run |
output_dir |
output directory path |
tolerance |
tolerance during vertex reduction |
smoothness |
smoothing factor, argument to |
cleanup |
logical to toggle removal of all intermediary files |
ncores |
number of cores for parallel processing (default numcores-2) |
data.frame ready for manual cleaning before turning into a proper ggseg3d-atlas
## Not run: # Create the DKT atlas as found in the FreeSurfer Subjects directory # And output the temporary files to the Desktop. dkt_3d <- make_aparc_2_3datlas(annot = "aparc.DKTatlas", output_dir = "~/Desktop/") ## End(Not run)
## Not run: # Create the DKT atlas as found in the FreeSurfer Subjects directory # And output the temporary files to the Desktop. dkt_3d <- make_aparc_2_3datlas(annot = "aparc.DKTatlas", output_dir = "~/Desktop/") ## End(Not run)
atlases in ggseg have palettes based on colours from the paper originally introducing the atlas. These colours are hard-coded into ggseg3d-atlases. This function extracts those and makes a object ready for incorporation to a ggseg-atlas repository
make_palette_ggseg(ggseg3d_atlas)
make_palette_ggseg(ggseg3d_atlas)
ggseg3d_atlas |
ggseg3d-atlas |
list with a colour palette
make_palette_ggseg(dk_3d)
make_palette_ggseg(dk_3d)
Function to create a ggseg3d-atlas
from a volumetric parcellation.
Currently only tested using .mgz
extension images. Will call command-line
tools to complete the process.
make_volumetric_2_3datlas( template, color_lut, subject = "fsaverage5", subjects_dir = freesurfer::fs_subj_dir(), steps = 1:5, output_dir = tempdir(), verbose = TRUE, ncores = parallel::detectCores() - 2, cleanup = TRUE )
make_volumetric_2_3datlas( template, color_lut, subject = "fsaverage5", subjects_dir = freesurfer::fs_subj_dir(), steps = 1:5, output_dir = tempdir(), verbose = TRUE, ncores = parallel::detectCores() - 2, cleanup = TRUE )
template |
template |
color_lut |
Freesurfer colour look-up-table. Either
as a path or a data.frame that |
subject |
Freesurfer subject, must exist in whatever subject directory specified or set in the environment with $SUBJECTS_DIR |
subjects_dir |
Freesurfer subject directory |
steps |
if cleanup is disabled, all files are saved, and steps can be re-run individually |
output_dir |
output directory path |
verbose |
logical indicating to be verbose or not |
ncores |
number of cores for parallel processing (default numcores-2) |
cleanup |
logical to toggle removal of all intermediary files |
the function is aggressive in the number
of cores used to minimize time taken to
create the atlas. Set the ncores
argument for less aggressive approach.
returns a ggseg3d-atlas ready object. Might need manual cleaning to become a good atlas.
## Not run: fs_subject_dir <- freesurfer::fs_dir() aseg_temp <- file.path(fs_subject_dir, "fsaverage5/mri/aseg.mgz") colorlut <- file.path(fs_subject_dir, "ASegStatsLUT.txt") make_volumetric_2_3datlas(aseg_temp, colorlut) ## End(Not run)
## Not run: fs_subject_dir <- freesurfer::fs_dir() aseg_temp <- file.path(fs_subject_dir, "fsaverage5/mri/aseg.mgz") colorlut <- file.path(fs_subject_dir, "ASegStatsLUT.txt") make_volumetric_2_3datlas(aseg_temp, colorlut) ## End(Not run)
If making an atlas from a non-cortical atlas,
volumetric atlases are the best options.
Instead of snapshotting images of inflated
brain, will snapshot brain slices given x, y, z
coordinates for the slices trhoush the slices
argument.
make_volumetric_ggseg( label_file, subject = "fsaverage5", subjects_dir = fs_subj_dir(), output_dir = tempdir(), color_lut = NULL, steps = 1:8, skip_existing = TRUE, slices = data.frame(x = c(130, 122, 122), y = c(130, 235, 112), z = c(130, 100, 106), view = c("axial", "sagittal", "coronal"), stringsAsFactors = FALSE), vertex_size_limits = NULL, dilate = NULL, tolerance = 0, ncores = 2, smoothness = 5, verbose = TRUE, cleanup = FALSE )
make_volumetric_ggseg( label_file, subject = "fsaverage5", subjects_dir = fs_subj_dir(), output_dir = tempdir(), color_lut = NULL, steps = 1:8, skip_existing = TRUE, slices = data.frame(x = c(130, 122, 122), y = c(130, 235, 112), z = c(130, 100, 106), view = c("axial", "sagittal", "coronal"), stringsAsFactors = FALSE), vertex_size_limits = NULL, dilate = NULL, tolerance = 0, ncores = 2, smoothness = 5, verbose = TRUE, cleanup = FALSE )
label_file |
a volumetric image containing the labels |
subject |
Freesurfer subject, must exist in whatever subject directory specified or set in the environment with $SUBJECTS_DIR |
subjects_dir |
Freesurfer subject directory |
output_dir |
output directory path |
color_lut |
a file containing color information for the labels |
steps |
numeric vector of steps to run |
skip_existing |
logical. If slice snapshots already exist, should these be skipped. |
slices |
a data.frame with columns x, y, z, and view specifying coordinates and view of slice snapshots. |
vertex_size_limits |
numeric vector of two, setting the minimum and maximum vector size of polygons. Defaults to NULL, which sets no limits. |
dilate |
numeric. Dilation factor for polygons. Default NULL applies no dilation. |
tolerance |
tolerance during vertex reduction |
ncores |
number of cores for parallel processing (default numcores-2) |
smoothness |
smoothing factor, argument to |
verbose |
logical indicating to be verbose or not |
cleanup |
logical to toggle removal of all intermediary files |
brain-atlas class
## Not run: label_file <- file.path(fs_subj_dir(), subject, "mri/aseg.mgz") slices = data.frame(x=130, y=130, z=130, view="axial", stringsAsFactors = FALSE) aseg2 <- make_volumetric_ggseg( label_file = label_file, slices = slices ) # Have a look at the atlas plot(aseg2) ## End(Not run)
## Not run: label_file <- file.path(fs_subj_dir(), subject, "mri/aseg.mgz") slices = data.frame(x=130, y=130, z=130, view="axial", stringsAsFactors = FALSE) aseg2 <- make_volumetric_ggseg( label_file = label_file, slices = slices ) # Have a look at the atlas plot(aseg2) ## End(Not run)
Calls FreeSurfer's mri_annotation2label
to split an annotation file into several labels.
mri_annotation2label( annot_name, subject = "fsaverage5", hemisphere = "lh", output_dir = fs_subj_dir(), verbose = TRUE, opts = NULL )
mri_annotation2label( annot_name, subject = "fsaverage5", hemisphere = "lh", output_dir = fs_subj_dir(), verbose = TRUE, opts = NULL )
annot_name |
annotation name. File should exist in subjects label directory |
subject |
Freesurfer subject, must exist in whatever subject directory specified or set in the environment with $SUBJECTS_DIR |
hemisphere |
hemisphere, either "rh" or "lh" |
output_dir |
output directory path |
verbose |
logical indicating to be verbose or not |
opts |
other arguments to freesurfer command |
nothing. Runs command line to write label files
if(freesurfer::have_fs()){ # for freesurfer help see: freesurfer::fs_help("mri_annotation2label") mri_annotation2label(annot_name = "aparc") mri_annotation2label(annot_name = "aparc.a2009s") mri_annotation2label(subject = "fsaverage", annot_name = "aparc.a2009s") }
if(freesurfer::have_fs()){ # for freesurfer help see: freesurfer::fs_help("mri_annotation2label") mri_annotation2label(annot_name = "aparc") mri_annotation2label(annot_name = "aparc.a2009s") mri_annotation2label(subject = "fsaverage", annot_name = "aparc.a2009s") }
Annotation files are subject specific. Most are registered for fsaverage, but we recommend using fsaverage5 for the mesh plots in ggseg3d, as these contain a decent balance in number of vertices for detailed rendering and speed.
mri_surf2surf_rereg( subject, annot, hemi = c("lh", "rh"), target_subject = "fsaverage5", output_dir = file.path(fs_subj_dir(), subject, "label"), verbose = TRUE )
mri_surf2surf_rereg( subject, annot, hemi = c("lh", "rh"), target_subject = "fsaverage5", output_dir = file.path(fs_subj_dir(), subject, "label"), verbose = TRUE )
subject |
subject the original annotation file is registered to |
annot |
annotation file name (as found in subjects_dir) |
hemi |
hemisphere (one of "lh" or "rh") |
target_subject |
subject to re-register the annotation (default fsaverage5) |
output_dir |
output directory path |
verbose |
logical indicating to be verbose or not |
nothing
if(freesurfer::have_fs()){ # For help see: freesurfer::fs_help("mri_surf2surf") mri_surf2surf_rereg(subject = "bert", annot = "aparc.DKTatlas", target_subject = "fsaverage5") }
if(freesurfer::have_fs()){ # For help see: freesurfer::fs_help("mri_surf2surf") mri_surf2surf_rereg(subject = "bert", annot = "aparc.DKTatlas", target_subject = "fsaverage5") }
Converts values in a volume or surface overlay to a label. The program
searches the input for values equal to labelid. The xyz values for
each point are then computed based on the tkregister voxel-to-RAS
matrix (volume) or from the xyz of the specified surface. The xyz
values are then stored in labelfile in the label file format. The
statistic value is set to 0. While this program can be used with any
mri volume, it was designed to convert parcellation volumes, which
happen to be stored in mri format.
Calls FreeSurfer's mri_vol2label
.
mri_vol2label( input_file, label_id, hemisphere, output_dir, surface = NULL, subject = "fsaverage5", subjects_dir = fs_subj_dir(), opts = NULL, verbose = TRUE )
mri_vol2label( input_file, label_id, hemisphere, output_dir, surface = NULL, subject = "fsaverage5", subjects_dir = fs_subj_dir(), opts = NULL, verbose = TRUE )
input_file |
input volume |
label_id |
label to run |
hemisphere |
hemisphere, either "rh" or "lh" |
output_dir |
output directory path |
surface |
output surface |
subject |
Freesurfer subject, must exist in whatever subject directory specified or set in the environment with $SUBJECTS_DIR |
subjects_dir |
Freesurfer subject directory |
opts |
other arguments to freesurfer command |
verbose |
logical indicating to be verbose or not |
returns nothing. Writes a label file.
if(freesurfer::have_fs()){ # for freesurfer help see: freesurfer::fs_help("mri_vol2label") out_dir <- tempdir() vol <- file.path(freesurfer::fs_subj_dir(), "fsaverage5/mri/aseg.mgz") mri_vol2label(vol, label_id = 2, hemisphere = "rh", output_dir = out_dir) # delete output dir when not needed unlink(out_dir) }
if(freesurfer::have_fs()){ # for freesurfer help see: freesurfer::fs_help("mri_vol2label") out_dir <- tempdir() vol <- file.path(freesurfer::fs_subj_dir(), "fsaverage5/mri/aseg.mgz") mri_vol2label(vol, label_id = 2, hemisphere = "rh", output_dir = out_dir) # delete output dir when not needed unlink(out_dir) }
For a single subject, produces an annotation file, in which each cortical surface vertex is assigned a neuroanatomical label. This automatic procedure employs data from a previously-prepared atlas file. An atlas file is created from a training set, capturing region data manually drawn by neuroanatomists combined with statistics on variability correlated to geometric information derived from the cortical model (sulcus and curvature). Besides the atlases provided with FreeSurfer, new ones can be prepared using mris_ca_train).
mris_ca_label( subject = "fsaverage5", hemisphere = "lh", canonsurf = "sphere.reg", classifier = file.path(fs_dir(), "average/lh.DKTatlas40.gcs"), output_file, subjects_dir = fs_subj_dir(), opts = NULL )
mris_ca_label( subject = "fsaverage5", hemisphere = "lh", canonsurf = "sphere.reg", classifier = file.path(fs_dir(), "average/lh.DKTatlas40.gcs"), output_file, subjects_dir = fs_subj_dir(), opts = NULL )
subject |
Freesurfer subject, must exist in whatever subject directory specified or set in the environment with $SUBJECTS_DIR |
hemisphere |
hemisphere, either "rh" or "lh" |
canonsurf |
canonical surface file. Ie: the name of the spherical surface file which describes the registration of a subject's vertices to the reference "average" surface. Example: sphere.reg |
classifier |
specify classifier array input file (atlas file) |
output_file |
path to output file |
subjects_dir |
Freesurfer subject directory |
opts |
other arguments to freesurfer command |
if(freesurfer::have_fs()){ # for freesurfer help see: freesurfer::fs_help("mris_ca_label") mris_ca_label(output_file = "test.lh.annot") mris_ca_label(hemisphere = "rh", output_file = "test.rh.annot") }
if(freesurfer::have_fs()){ # for freesurfer help see: freesurfer::fs_help("mris_ca_label") mris_ca_label(output_file = "test.lh.annot") mris_ca_label(hemisphere = "rh", output_file = "test.rh.annot") }
If you have labels rather than a full annotation
file, these can be combined with FreeSurfer's
mris_label2annot
.
mris_label2annot( labels, hemisphere = "rh", ctab, subject = "fsaverage5", subjects_dir = fs_subj_dir(), output_dir = subjects_dir, opts = NULL, verbose = TRUE )
mris_label2annot( labels, hemisphere = "rh", ctab, subject = "fsaverage5", subjects_dir = fs_subj_dir(), output_dir = subjects_dir, opts = NULL, verbose = TRUE )
labels |
label file path vector |
hemisphere |
hemisphere, either "rh" or "lh" |
ctab |
colourtable file |
subject |
Freesurfer subject, must exist in whatever subject directory specified or set in the environment with $SUBJECTS_DIR |
subjects_dir |
Freesurfer subject directory |
output_dir |
output directory path |
opts |
other arguments to freesurfer command |
verbose |
logical indicating to be verbose or not |
if(freesurfer::have_fs()){ # for freesurfer help see: freesurfer::fs_help("mris_label2annot") subj_dir <- freesurfer::fs_subj_dir() # Split up aparc annot into labels mri_annotation2label(annot_name = "aparc") # get annot for colour labels annot <- freesurfer::read_annotation( file.path(subj_dir, "fsaverage5/label/rh.aparc.annot")) labels <- list.files( file.path(subj_dir, "fsaverage5/label/aparc"), full.names = TRUE) # Combine them again into annot. mris_label2annot(labels, annot$colortable) }
if(freesurfer::have_fs()){ # for freesurfer help see: freesurfer::fs_help("mris_label2annot") subj_dir <- freesurfer::fs_subj_dir() # Split up aparc annot into labels mri_annotation2label(annot_name = "aparc") # get annot for colour labels annot <- freesurfer::read_annotation( file.path(subj_dir, "fsaverage5/label/rh.aparc.annot")) labels <- list.files( file.path(subj_dir, "fsaverage5/label/aparc"), full.names = TRUE) # Combine them again into annot. mris_label2annot(labels, annot$colortable) }
Read in a FreeSurfer colortab file.
read_ctab(path)
read_ctab(path)
path |
path to read from |
a data.frame with index, label name and RGBA colours
Change old atlas setup to new
restruct_old_3datlas(atlas_data)
restruct_old_3datlas(atlas_data)
atlas_data |
ggseg3d-atlas object |
Turn smooth file to ascii
smooth2srf(input_file, output_file, verbose)
smooth2srf(input_file, output_file, verbose)
input_file |
input file path |
output_file |
path to output file |
verbose |
logical indicating to be verbose or not |
This function goes through all specified subject, per hemisphere, surface, curvature and no fix curvature specified and turns them into ascii files.
subject_2_ascii( subject = "fsaverage5", hemisphere = c("rh", "lh"), surfaces = fs_surfaces(), curvatures = fs_curvatures(), nofix_curv = fs_nofixcurv(), subjects_dir = freesurfer::fs_subj_dir(), output_dir = subjects_dir, verbose = TRUE )
subject_2_ascii( subject = "fsaverage5", hemisphere = c("rh", "lh"), surfaces = fs_surfaces(), curvatures = fs_curvatures(), nofix_curv = fs_nofixcurv(), subjects_dir = freesurfer::fs_subj_dir(), output_dir = subjects_dir, verbose = TRUE )
subject |
Freesurfer subject, must exist in whatever subject directory specified or set in the environment with $SUBJECTS_DIR |
hemisphere |
hemisphere, either "rh" or "lh" |
surfaces |
string vector of surfaces |
curvatures |
string vector of curvatures |
nofix_curv |
string vector of nofix curvatures |
subjects_dir |
Freesurfer subject directory |
output_dir |
output directory path |
verbose |
logical indicating to be verbose or not |
no return. Writes files.
## Not run: subject_2_ascii() subject_2_ascii("fsaverage") subject_2_ascii("bert") ## End(Not run)
## Not run: subject_2_ascii() subject_2_ascii("fsaverage") subject_2_ascii("bert") ## End(Not run)
Function to convert Freesurfer surface file into .ply
surf2ply(input_file, output_file = paste(input_file, ".ply"), verbose = TRUE)
surf2ply(input_file, output_file = paste(input_file, ".ply"), verbose = TRUE)
input_file |
path to Freesurfer surface file |
output_file |
path to output file |
verbose |
logical indicating to be verbose or not |
ply text
Function to split up a surface ply into several ply's based on a freesurfer label file.
surfsplit( srf_ply, label_path, prefix = "test", output_dir = dirname(label_path), verbose = TRUE )
surfsplit( srf_ply, label_path, prefix = "test", output_dir = dirname(label_path), verbose = TRUE )
srf_ply |
Surface ply path |
label_path |
label dpv file |
prefix |
output prefix |
output_dir |
output directory path |
verbose |
logical indicating to be verbose or not |
Script adapted to R and ggseg based on scripts from Anderson M. Winkler: http://brainder.org
list of ply meshes. Will also write ply meshes to files.
write a colortab to file, will be in a format that is accessible by FreeSurfer.
write_ctab(x, path)
write_ctab(x, path)
x |
colourtab data |
path |
path to write to |
returns nothing, writes file