brain_image = system.file("extdata", "brain.mgz",
package = "freesurferformats",
mustWork = TRUE);
vd = read.fs.mgh(brain_image);
cat(sprintf("Read voxel data with dimensions %s. Values: min=%d, mean=%f, max=%d.\n",
paste(dim(vd), collapse = ' '), min(vd), mean(vd), max(vd)));
# Read it again with full header data:
vdh = read.fs.mgh(brain_image, with_header = TRUE);
# Use the vox2ras matrix from the header to compute RAS coordinates at CRS voxel (0, 0, 0):
vdh$header$vox2ras_matrix %*% c(0,0,0,1);
Run the code above in your browser using DataLab