Define voxel selection for a searchlight¶
In a searchlight (Kriegeskorte et al 2006) one computes a (spatially) locally constrained measure for each feature in a dataset.
An important building block for a searchlight is the voxel selection part: for each feature, decide which features are in its neighborhood. Typically the neighborhood is defined as a sphere of a certain radius.
Compute voxel offsets in a sphere¶
In turn, computing the relative offsets from a voxel location is a building block for feature selection part. In this exercise, write a function that returns the voxel indices relative to the origin. That is, given a radius r, it returns a Px3 array where every row (i,j,k) is unique and it holds that (i,j,k) is at most at distance r from the origin (0,0,0). This function has the following signature:
function [offsets, distances] = cosmo_sphere_offsets(radius)
Then, for each radius from 2 to 6 in steps of .5, plot the indices and show how many voxels are in a sphere of that raidus.
Hint: cosmo sphere offsets skl / run sphere offsets skl
Solution: cosmo sphere offsets / run sphere offsets / Matlab output: run_sphere_offsets
Using the sphere offsets for voxel selection¶
If you are up for quite an advanced exercise: write a function that performs voxel selection (if not, don’t spend your time on this and just look at the answer). It should have the following signature:
function nbrhood = cosmo_spherical_neighborhood(ds, varargin)
As a start you can ignore the requirement that a negative value for radius should select a certain number of voxels; in other words just focus on positive values for radius.
A more advanced exercise: modify this function so that it also supports negative values for radius, which return neighborhoods of the same size (i.e. same number of voxels) at each location.
Solution: cosmo spherical neighborhood