Inneuroim2 there is basic support for creatingregions of interest (ROI). To create a spherical ROI around a centralpoint, we need an existing object of typeNeuroVol orNeuroSpace.
To create a spherical region of interest with a 5mm radius around acentral voxel at i=20, j=20, k=20, we first read in an image.
library(neuroim2) file_name<-system.file("extdata","global_mask2.nii.gz",package="neuroim2") vol<-read_vol(file_name)Next, we create a spherical ROI centered around voxel coordinates[20,20,20] with a 5mm radius, filling all values in the ROI with100.
#> #> ROIVol Object #> #> Properties: #> Dimensions: 11 x 3#> ROI Points: 11#> Value Range: [100.00, 100.00]To create a spherical ROI centered around a real coordinate inmillimeters, we need to first convert the real-valued coordinates to avoxel-based coordinate. Suppose our real-world coordinate is at -50,-28, 10 in coordinate space.
Because the functionspherical_roi takes a coordinate invoxel units, we need to convert the real-world coordinate(i.e. in millimeter units) to voxel coordinates.
vox<-coord_to_grid(vol, rpoint) sphere<-spherical_roi(vol, vox,radius=10,fill=1)dim(coords(sphere))#> [1] 85 3Now we convert back to real-world coordinates
We may want to convert a region of interest to a NeuroVol instance.But we don’t want to store every value in a dense array. Here we canmake use of theSparseNeuroVol class which only storesnon-zero values my using aMatrix::sparseVector under thehood.
sphere<-spherical_roi(vol,c(50,10,10),radius=10,fill=1) sphere#>#> ROIVol Object#>#> Properties:#> Dimensions: 85 x 3#> ROI Points: 85#> Value Range: [1.00, 1.00]Now we construct aSparseNeuroVol and fill it with thevalues stored in the ROI:
The so-called roving “searchlight” is often used to performmultivariate statistical analyses in a local neighborhood of each voxelof an image. Several functions inneuroim2 can be used tocarry out searchlight analyses. These functions produceslists of theROIVol instances that encapsulatethe local neighborhood around each voxel.
Here, we compute the mean value in an exhaustive set of sphericalsearchlights in an image volume.
library(purrr)## generate a list of searchlight ROIsslist<-searchlight(vol,eager=TRUE,radius=8)## compute the mean value in each searchlight ROI.ret<- slist%>% purrr::map(~mean(vol[coords(.)]))We can also use a “randomized searchlight”, which samples voxelswithout replacement until all voxels have been included in at least onesearchlight.
Another related method involves using a “parcellation” or clusteringto define successive regions of interest for an analysis. Here we showhow to do this in a similar way as above. First we must define a‘clustering’ over the voxel space:
Now we create aClusteredNeuroVol and map themean function over all clusters:
Another type of ROI analysis, similar to the ‘searchlight’, involvesworking with sets of square or cuboid image “patches”. Thepatch_set function can be used to generate a set ofequally-sized patches that span the image space (or some mask coveringthe space). The patches are guaranteed to be of equal size. This meansthat at edges, ‘patches’ will be padded out with the value at the imageextremes.
Here we create a patch set consistting of 3 by 3 by 1 square patchesthat span the image.
Now we limit patches so that the set of patch centers are within amask.