# R/hessian.R In neuroconductor-devel/lesiontools: Statistical and Computational Tools for Brain Lesion Analysis

```#' @title 3D Image Hessian
#' @description This function returns the eigenvalues of the hessian matrices for a 3D array or NIfTI volume.
#' @param image a 3D array or image of class \code{nifti}
#' @param mask an array or \code{nifti} mask of voxels for which vesselness will be calculated,
#' with more selective masking improving speed significantly.
#' Note that mask should be in the same space as the image volume
#' @param radius an integer specifying radius of the neighborhood (in voxels) for which the hessian should be calculated
#' @param parallel is a logical value that indicates whether the user's computer
#' is Linux or Unix (i.e. macOS), and should run the code in parallel
#' @param cores if parallel = TRUE, cores is an integer value that indicates how many cores
#' the function should be run on
#'
#' @return A list of three eigenvalue volumes.
#' @examples \dontrun{
#' library(neurobase)
#' @export
#' @importFrom pbmcapply pbmclapply
#' @importFrom pbapply pblapply
#' @importFrom parallel detectCores

print("Getting derivatives")

print("Creating hessian matrices")

rm(gxx,gxy,gxz,gyx,gyy,gyz,gzx,gzy,gzz)

biglist=split(bigmat,row(bigmat))
biglist=lapply(biglist,matrix,nrow=3,byrow=T)

rm(bigmat)

getevals=function(matrix){
thiseig=eigen(matrix)\$values
sort=order(abs(thiseig))
return(thiseig[sort])
}

print("Calculating eigenvalues")
if(parallel==TRUE){
result=matrix(unlist(pbmclapply(biglist,getevals,mc.cores=cores)),
ncol=3,byrow=T)
}else if(parallel==FALSE){
result=matrix(unlist(pblapply(biglist,getevals)),ncol=3,byrow=T)
}