R/fsl_dice.R

Defines functions fsl_dice

Documented in fsl_dice

#' @title Calculate Dice Coefficient of 2 Binary images
#'
#' @description Creates a 2 by 2 table for 
#' @param x filename of logical or 0/1 image
#' @param y filename of logical or 0/1 image
#' @param ... arguments passed to \code{\link{fsl_bin_tab}}
#' 
#' @return Single number of the dice coefficient
#' @export
#' 
fsl_dice = function(
  x, y, ...) {
  
  tab = fsl_bin_tab(x, y, ...)
  dtab = dim(tab)
  stopifnot(all(dtab == c(2,2)))
  good = 2 * tab[2, 2]
  dice = good/(good + tab[1, 2] + tab[2, 1])
  
  return(dice)
}

Try the fslr package in your browser

Any scripts or data that you put into this service are public.

fslr documentation built on Aug. 25, 2022, 5:07 p.m.