R/extract_ria.R

Defines functions extract_ria

Documented in extract_ria

#' @title Radiomic Feature Extraction
#' @description This function extracts radiomic features from a given T2*-phase image and a lesion label map
#' @param phasefile Location of the T2*-phase image
#' @param leslabels Lesion label map, generated by our lesion identification method
#' @param disc Calculate discretized versions of first order radiomic features? 
#' @import RIA
#' @import neurobase
#' @return A dataframe containing radiomic features for each identified lesion

extract_ria = function(phasefile, leslabels, disc = T){
  numles = max(leslabels)
  
  return.stats = list()
  for(i in 1:numles){
    
    RIA.image <- RIA::load_nifti(filename = phasefile,
                                 crop_in = FALSE, 
                                 switch_z = FALSE, 
                                 reorient_in = FALSE, 
                                 replace_in = FALSE,
                                 reorient = FALSE)
    image <- neurobase::readnii(phasefile)
    image[leslabels != i] <- NA 
    RIA.image$data$orig <- image
    
    first.order.orig <- RIA::first_order(RIA.image)
    
    if(disc == T){
      RIA.image <- RIA::discretize(RIA.image, bins_in = c(8, 64), equal_prob = TRUE)
      first.order.disc <- RIA::first_order(RIA.image, use_type = "discretized")
      
      stats.orig <- unlist(first.order.orig$stat_fo)
      stats.disc <- unlist(first.order.disc$stat_fo)
      return.stats[[i]] <- c(stats.orig, stats.disc)
    } else{
      stats.orig <- unlist(first.order.orig$stat_fo)
      return.stats[[i]] <- stats.orig
    }
    
  }
  all.stats <- do.call(rbind, return.stats)
  return(all.stats)
}
carolynlou/prlr documentation built on Oct. 2, 2020, 10:28 a.m.