Lecture 4 Data Manipulation

This lecture covers: - Masking - Operations

4.1 Open data

The code below downloads opens the T1-weighted image and downloads the mask for this data.

fname = "113-01-MPRAGE.nii.gz"
fpath = file.path("Neurohacking_data/kirby21/visit_1/113", fname)

maskurl = "https://raw.githubusercontent.com/muschellij2/Neurohacking/master/Basic_Data_Manipulations/Kirby21/SUBJ0001_mask.nii.gz"
maskfname = "SUBJ0001_mask.nii.gz"
maskfpath = file.path("Neurohacking_data", maskfname)
download.file(maskurl, maskfpath, mode="wb")# NIfTI is binaryfile format

library(oro.nifti)
T1 = readNIfTI(fpath,reorient=FALSE)
mask = readNIfTI(maskfpath, reorient=FALSE) 

4.2 Visualization

This brain was collected with a bigger FOV than the previous scans. Thus a lot of body parts other than brain are shown.

orthographic(T1)

orthographic(mask)

4.3 Masking

masked.T1 = T1*mask
orthographic(masked.T1)

4.4 Substraction

fname = "113-02-MPRAGE.nii.gz"
fpath = file.path("Neurohacking_data/kirby21/visit_2/113", fname)

T1.follow  = readNIfTI(fpath, reorient = FALSE)

substract.T1 = T1.follow - T1
min(substract.T1)
## [1] -1810405
max(substract.T1)
## [1] 2054726
orthographic(substract.T1)