[3b2327]: / R / jacobian_lung.R

Download this file

58 lines (50 with data), 1.9 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
#' Calculate Jacobian Determinant Image for the Lungs
#'
#' This function calculates the Jacobian determinant image for the left and right lungs separately.
#'
#' @param right_transformation Transformations for the right lung
#' @param left_transformation Transformations for the left lung
#' @param mask Fixed mask (or standard lung template mask)
#' @param doLog Return the log Jacobian
#' @param geom Use the geometric Jacobian calculation
#' @param relative Returen the relative Jacobian (Jacobian divided by mean Jacobian)
#'
#' @return Jacobian Image
#' @importFrom ANTsR createJacobianDeterminantImage maskImage
#'
#' @export
jacobian_lung = function(
right_transformation,
left_transformation,
mask,
doLog = TRUE,
geom = FALSE,
relative = TRUE
) {
# Create separate left and right masks
right = mask == 1
left = mask == 2
# Create Jacobian Determinant Image
jacob_right <- createJacobianDeterminantImage(domainImg = mask,
tx = right_transformation,
doLog = doLog,
geom = FALSE)
jacob_right <- maskImage(jacob_right, right)
jacob_left <- createJacobianDeterminantImage(domainImg = mask,
tx = left_transformation,
doLog = doLog,
geom = FALSE)
jacob_left <- maskImage(jacob_left, left)
# Put images together
jacob = jacob_right + jacob_left
if(relative){
jacob_right_relative <- jacob_right/mean(jacob_right)
jacob_left_relative <- jacob_left/mean(jacob_left)
jacob_relative <- jacob_right_relative + jacob_left_relative
mylist = list(jacob = jacob,
jacob_relative = jacob_relative)
}else{
mylist = jacob
}
return(mylist)
}