[242173]: / R / biometric_mask.R

Download this file

70 lines (60 with data), 1.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#' @title Estimate Biometric Masks
#' @description Estimates biometric masks for anonymization, such as the face and
#' ears.
#'
#' @param file Filename (or nifti) of image
#' @param type character of \code{ct} for CT images or \code{mri} for magnetic
#' resonance images
#' @param ... arguments to pass to \code{ct/mri_ear_mask} and
#' \code{ct/mri_face_mask}
#'
#' @return Object of class nifti
#' @export
#' @examples \dontrun{
#' file = "~/Desktop/Desktop/scratch/100-318_20070723_0957_CT_3_CT_Head-.nii.gz"
#' mask = NULL
#' robust = FALSE
#' mask = ct_biometric_mask(
#' file = file,
#' robust = FALSE
#' )
#' img = readnii(file)
#' rimg = randomize_mask(img, mask = face)
#' }
#'
biometric_mask = function(
file,
type = c("ct", "mri"),
...) {
type = match.arg(type)
args = list(...)
args$file = file
func = paste0(type, "_ear_mask")
ears = do.call(what = func, args = args)
func = paste0(type, "_face_mask")
face = do.call(what = func, args = args)
mask = ears | face
return(mask)
}
#' @export
#' @rdname biometric_mask
ct_biometric_mask = function(
file,
...) {
args = list(...)
args$type = "ct"
args$file = file
mask = do.call("biometric_mask", args = args)
return(mask)
}
#' @export
#' @rdname biometric_mask
mri_biometric_mask = function(
file,
...) {
args = list(...)
args$type = "mri"
args$file = file
mask = do.call("biometric_mask", args = args)
return(mask)
}