Last data update: 2014.03.03
R: Image thresholding
calcThreshold R Documentation
Image thresholding
Description
Threshold a contrast parameter at one or several values.
Usage
## S4 method for signature 'MRIaggr'
calcThresholdMRIaggr(object, param, hemisphere = "both", rm.CSF = FALSE,
threshold = 1:10, decreasing = FALSE,
GRalgo = FALSE, W = "ifany", seed = NULL, numeric2logical = FALSE, W.range,
W.spatial_res = rep(1,3), name_newparam = paste(param,"Th", sep = "_"),
verbose = optionsMRIaggr("verbose"), update.object = FALSE, overwrite = FALSE)
calcThreshold(contrast, param, hemisphere = NULL, rm.CSF = FALSE, threshold = 1:10,
decreasing = FALSE, GRalgo = FALSE, W = NULL, seed = NULL,
numeric2logical = FALSE, verbose = optionsMRIaggr("verbose"))
Arguments
object
an object of class MRIaggr
. REQUIRED.
contrast
the dataset containing the contrast parameter to be thresholded. matrix . REQUIRED.
param
the contrast parameters to be thresholded. character vector . REQUIRED.
hemisphere
the hemisphere to consider. character or NULL
.
rm.CSF
should the cerebral spinal fluid observations be excluded ? logical or character .
threshold
the thresholds to be used for the discretization of the contrast parameter. numeric vector .
decreasing
should the increasing thresholding (FALSE
) or decreasing thresholding (TRUE
) be used. logical .
GRalgo
should a Growing Region algorithm be used to clean the thresholded parameter ? logical .
W
the neighbourhood matrix. dgCMatrix or "ifany"
leading to use the neighbourhood matrix stored in the object
if any and else computate this matrix.
seed
the index of the seeds for the growing region algorithm . positive integer vector .
numeric2logical
should seed
be converted to logical ? logical .
W.range
only distances smaller than W.range
are stored in W
. postive numeric .
W.spatial_res
a dilatation factor for the coordinates. positive numeric vector of size 3 .
name_newparam
the name of the new parameters. character .
verbose
should the execution of the function be traced ? logical .
update.object
should the resulting thresholded parameters be stored in object
? logical .
overwrite
contrast parameters with the same names are already stored in object@data
, can it be overwritten ? logical .
Details
These functions require to have installed the Matrix and the spam package to work when argument GRalgo
is set to TRUE
.
ARGUMENTS:
[data.frame method] the hemisphere
argument must be one of the levels present in the column named "hemisphere"
in data. NULL
leading to use all observations.
[MRIaggr method] Information about the hemisphere
arguments can be found in the details section of selectContrast
.
FUNCTION:
[data.frame method] By default the indicator of CSF will be extract from the column named CSF
.
If it is contained in another column the user must specify rm.CSF
with the name of this column.
[MRIaggr method] Setting rm.CSF
to TRUE
require to have the corresponding parameter (by default CSF
) stored in the object
.
It can be done using calcTissueType
.
References
Chantal Revol and Michel Jourlin. A new minimum varance region growing algorithm for image segmentation . Pattern Recognition Letters, 18(3):249-258,1997.
See Also
selectContrast
to select contrast parameters in the MRIaggr
object.
Examples
## load a MRIaggr object
data(MRIaggr.Pat1_red, package = "MRIaggr")
#### 1- MRIaggr method
## raw parameter
multiplot(MRIaggr.Pat1_red, param = "TTP_t0", legend = FALSE, main = "TTP_t0 - slice ",
palette=rainbow(10), breaks = seq(0,10) - 10^{-10})
## thresholded parameter
calcThresholdMRIaggr(MRIaggr.Pat1_red, param = c("TTP_t0","MTT_t0"),threshold = 1:10,
name_newparam = c("TTP.th_t0","MTT.th_t0"),
update.object = TRUE, overwrite = TRUE)
multiplot(MRIaggr.Pat1_red, param = "TTP.th_t0", main = "TTP.th_t0 - slice",
legend = FALSE,palette = rainbow(10), breaks = (0:10) - 10^{-10})
## Not run:
## 1st correction
calcThresholdMRIaggr(MRIaggr.Pat1_red, param = c("TTP_t0","MTT_t0"),threshold = 1:10,
rm.CSF = TRUE, hemisphere = "lesion",
name_newparam = c("TTP.red_t0","MTT.red_t0"),
update.object = TRUE, overwrite = TRUE)
multiplot(MRIaggr.Pat1_red, param = "TTP.red_t0", main = "TTP.red_t0 - slice",
legend = FALSE, palette = rainbow(10), breaks = (0:10) - 10^{-10})
## 2nd correction
calcThresholdMRIaggr(MRIaggr.Pat1_red, param = c("TTP_t0","MTT_t0"), threshold = 1:10,
rm.CSF = TRUE, hemisphere = "lesion", name_newparam = c("TTP.GR_t0","MTT.GR_t0"),
GRalgo = TRUE, seed = c("MASK_T2_FLAIR_t2","MASK_DWI_t0"), W.range = sqrt(2),
update.object = TRUE, overwrite = TRUE)
multiplot(MRIaggr.Pat1_red, param = "TTP.GR_t0", main = "TTP.GR_t0 - slice",
legend = FALSE, palette = rainbow(10), breaks = (0:10) - 10^{-10})
#### 2- data.frame function ####
## raw parameter
multiplot(MRIaggr.Pat1_red, param = "TTP_t0", legend = FALSE, main = "TTP_t0 - slice ",
palette=rainbow(10), breaks = seq(0,10) - 10^{-10})
## thresholded parameter
data <- selectContrast(MRIaggr.Pat1_red,
param = c("TTP_t0","MTT_t0","hemisphere","CSF","WM","GM"))
hypo_Th1_10 <- calcThreshold(data,param = c("TTP_t0","MTT_t0"), threshold = 1:10)
multiplot(selectCoords(MRIaggr.Pat1_red), main = "TTP_t0_th - slice ",
hypo_Th1_10[,1], legend = FALSE, palette = rainbow(10), breaks = (0:10) - 10^{-10})
## 1st correction
data$CSF <- as.numeric(apply(data[,c("CSF","WM","GM")], 1, which.max) == 1)
hypoC_Th1_10 <- calcThreshold(data,param = c("TTP_t0","MTT_t0"), threshold = 1:10,
hemisphere = "left", rm.CSF = TRUE)
multiplot(selectCoords(MRIaggr.Pat1_red), main = "TTP_t0_thC - slice",
hypoC_Th1_10[,1], legend = FALSE, palette = rainbow(10), breaks = (0:10) - 10^{-10})
## 2nd correction
maskN <- c("MASK_T2_FLAIR_t2","MASK_DWI_t0")
data[, maskN] <- selectContrast(MRIaggr.Pat1_red, param = maskN)
W <- calcW(MRIaggr.Pat1_red, range = sqrt(2 * 1.875^2 + 0.001), row.norm = TRUE, upper = NULL,
spatial_res = c(1.875,1.875,6))$W
max(spam::rowSums(W > 0))
hypoCC_Th1_10 <- calcThreshold(data, param = c("TTP_t0","MTT_t0"), threshold = 1:10,
hemisphere = "left", rm.CSF = TRUE,
GRalgo = TRUE, seed = c("MASK_T2_FLAIR_t2","MASK_DWI_t0"), W = W)
multiplot(selectCoords(MRIaggr.Pat1_red), main = "TTP_t0_thCC - slice",
hypoCC_Th1_10[,1], legend = FALSE, palette = rainbow(10), breaks = (0:10) - 10^{-10})
## End(Not run)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(MRIaggr)
Loading required package: Rcpp
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/MRIaggr/MRIaggr-calcThresholdMRIaggr.Rd_%03d_medium.png", width=480, height=480)
> ### Name: calcThreshold
> ### Title: Image thresholding
> ### Aliases: calcThreshold calcThresholdMRIaggr
> ### calcThresholdMRIaggr,MRIaggr-method
>
> ### ** Examples
>
> ## load a MRIaggr object
> data(MRIaggr.Pat1_red, package = "MRIaggr")
>
> #### 1- MRIaggr method
> ## raw parameter
> multiplot(MRIaggr.Pat1_red, param = "TTP_t0", legend = FALSE, main = "TTP_t0 - slice ",
+ palette=rainbow(10), breaks = seq(0,10) - 10^{-10})
>
> ## thresholded parameter
> calcThresholdMRIaggr(MRIaggr.Pat1_red, param = c("TTP_t0","MTT_t0"),threshold = 1:10,
+ name_newparam = c("TTP.th_t0","MTT.th_t0"),
+ update.object = TRUE, overwrite = TRUE)
Step 1 : keep both hemipheres, keep CSF
Step 2 : thresholding **********
allocContrast[MRIaggr] : Cartographies "TTP.th_t0" "MTT.th_t0"
have been allocated
>
> multiplot(MRIaggr.Pat1_red, param = "TTP.th_t0", main = "TTP.th_t0 - slice",
+ legend = FALSE,palette = rainbow(10), breaks = (0:10) - 10^{-10})
>
> ## Not run:
> ##D ## 1st correction
> ##D calcThresholdMRIaggr(MRIaggr.Pat1_red, param = c("TTP_t0","MTT_t0"),threshold = 1:10,
> ##D rm.CSF = TRUE, hemisphere = "lesion",
> ##D name_newparam = c("TTP.red_t0","MTT.red_t0"),
> ##D update.object = TRUE, overwrite = TRUE)
> ##D
> ##D multiplot(MRIaggr.Pat1_red, param = "TTP.red_t0", main = "TTP.red_t0 - slice",
> ##D legend = FALSE, palette = rainbow(10), breaks = (0:10) - 10^{-10})
> ##D
> ##D ## 2nd correction
> ##D calcThresholdMRIaggr(MRIaggr.Pat1_red, param = c("TTP_t0","MTT_t0"), threshold = 1:10,
> ##D rm.CSF = TRUE, hemisphere = "lesion", name_newparam = c("TTP.GR_t0","MTT.GR_t0"),
> ##D GRalgo = TRUE, seed = c("MASK_T2_FLAIR_t2","MASK_DWI_t0"), W.range = sqrt(2),
> ##D update.object = TRUE, overwrite = TRUE)
> ##D
> ##D multiplot(MRIaggr.Pat1_red, param = "TTP.GR_t0", main = "TTP.GR_t0 - slice",
> ##D legend = FALSE, palette = rainbow(10), breaks = (0:10) - 10^{-10})
> ##D
> ##D
> ##D #### 2- data.frame function ####
> ##D
> ##D ## raw parameter
> ##D multiplot(MRIaggr.Pat1_red, param = "TTP_t0", legend = FALSE, main = "TTP_t0 - slice ",
> ##D palette=rainbow(10), breaks = seq(0,10) - 10^{-10})
> ##D
> ##D ## thresholded parameter
> ##D data <- selectContrast(MRIaggr.Pat1_red,
> ##D param = c("TTP_t0","MTT_t0","hemisphere","CSF","WM","GM"))
> ##D hypo_Th1_10 <- calcThreshold(data,param = c("TTP_t0","MTT_t0"), threshold = 1:10)
> ##D
> ##D multiplot(selectCoords(MRIaggr.Pat1_red), main = "TTP_t0_th - slice ",
> ##D hypo_Th1_10[,1], legend = FALSE, palette = rainbow(10), breaks = (0:10) - 10^{-10})
> ##D
> ##D ## 1st correction
> ##D data$CSF <- as.numeric(apply(data[,c("CSF","WM","GM")], 1, which.max) == 1)
> ##D
> ##D hypoC_Th1_10 <- calcThreshold(data,param = c("TTP_t0","MTT_t0"), threshold = 1:10,
> ##D hemisphere = "left", rm.CSF = TRUE)
> ##D
> ##D multiplot(selectCoords(MRIaggr.Pat1_red), main = "TTP_t0_thC - slice",
> ##D hypoC_Th1_10[,1], legend = FALSE, palette = rainbow(10), breaks = (0:10) - 10^{-10})
> ##D
> ##D ## 2nd correction
> ##D maskN <- c("MASK_T2_FLAIR_t2","MASK_DWI_t0")
> ##D data[, maskN] <- selectContrast(MRIaggr.Pat1_red, param = maskN)
> ##D W <- calcW(MRIaggr.Pat1_red, range = sqrt(2 * 1.875^2 + 0.001), row.norm = TRUE, upper = NULL,
> ##D spatial_res = c(1.875,1.875,6))$W
> ##D max(spam::rowSums(W > 0))
> ##D
> ##D hypoCC_Th1_10 <- calcThreshold(data, param = c("TTP_t0","MTT_t0"), threshold = 1:10,
> ##D hemisphere = "left", rm.CSF = TRUE,
> ##D GRalgo = TRUE, seed = c("MASK_T2_FLAIR_t2","MASK_DWI_t0"), W = W)
> ##D
> ##D multiplot(selectCoords(MRIaggr.Pat1_red), main = "TTP_t0_thCC - slice",
> ##D hypoCC_Th1_10[,1], legend = FALSE, palette = rainbow(10), breaks = (0:10) - 10^{-10})
> ##D
> ##D
> ## End(Not run)
>
>
>
>
>
> dev.off()
null device
1
>