R/getTissueSubclass.R

Defines functions getTissueSubclasses

Documented in getTissueSubclasses

#' @title Create images for each identified tissue subclass.
#' 
#' @description 
#' Creates brainImage instances for each subclass 
#' preserving the original dimensions.
#' 
#' @param data data.frame of volume to split
#' @param split data.frame (key, val) with values to split at (keys)
#' 
#' @return returns a list where all list elements contain 
#' data subsets belonging to the identified tissue class
#' 
#' @export
#' 
#' @examples
#' data <- data.frame(x=rep(1:10, 5), 
#' y=c(rep(1,10),rep(2,10),rep(3,10),rep(4,10),rep(5, 10)), 
#' z=rep(1, 50), val=rnorm(50))
#' img <- new("brainImage", data, "test", 10)
#' getTissueSubclasses(img, data.frame(key=median(data$val), val=NA))
getTissueSubclasses <- function(data, split) {
    classImages <- list()
    
    ## Mehrere minima
    for (j in 1:length(split[,1])) {
        if (j == 1) {
            cpy <- setCoordToNA(data, 
                                which(data@measurements <= split[j,"key"]))
            classImages[[length(classImages) + 1 ]] <- cpy
        } else {
            cpy <- setCoordToNA(data, 
                                which(data@measurements > split[j-1,"key"] & 
                                    data@measurements <= split[j,"key"]))
            classImages[[length(classImages) + 1 ]] <- cpy
        }
        if (j == length(split[,1])) {
            cpy <- setCoordToNA(data, 
                                which(data@measurements > split[j,"key"]))
            classImages[[length(classImages) + 1 ]] <- cpy
        }
    }
    
    return(classImages)
}
mknoll/imageanalysisBrain documentation built on May 23, 2019, 2:01 a.m.