# Load an example brain mask
mask <- read_vol(system.file("extdata", "global_mask_v4.nii", package="neuroim2"))
# Generate a resampled searchlight iterator with radii drawn from {4,6,8}
searchlights <- resampled_searchlight(mask, radius = c(4, 6, 8))
# Use a custom shape: random ellipsoid scaled along each axis
ellipsoid_fun <- function(mask, center, radius, iter, nonzero) {
scales <- runif(3, 0.5, 1.5) # axis-wise stretch/compress
vox <- spherical_roi(mask, center, radius, nonzero = FALSE)@coords
ctr_mat <- matrix(center, nrow(vox), 3, byrow = TRUE)
keep <- rowSums(((vox - ctr_mat) * scales)^2) <= radius^2
vox[keep, , drop = FALSE]
}
ellip_searchlights <- resampled_searchlight(mask, radius = c(4, 6),
iter = 50, shape_fun = ellipsoid_fun)
# Or use built-in named shapes
ellip_builtin <- resampled_searchlight(mask, radius = 6, shape_fun = "ellipsoid")
cube_builtin <- resampled_searchlight(mask, radius = 6, shape_fun = "cube")
Run the code above in your browser using DataLab