Diff of /R/jacobian_lung.R [000000] .. [3b2327]

Switch to unified view

a b/R/jacobian_lung.R
1
#' Calculate Jacobian Determinant Image for the Lungs
2
#'
3
#' This function calculates the Jacobian determinant image for the left and right lungs separately.
4
#'
5
#' @param right_transformation Transformations for the right lung
6
#' @param left_transformation Transformations for the left lung
7
#' @param mask Fixed mask (or standard lung template mask)
8
#' @param doLog Return the log Jacobian
9
#' @param geom Use the geometric Jacobian calculation
10
#' @param relative Returen the relative Jacobian (Jacobian divided by mean Jacobian)
11
#'
12
#' @return Jacobian Image
13
#' @importFrom ANTsR createJacobianDeterminantImage maskImage
14
#'
15
#' @export
16
jacobian_lung = function(
17
  right_transformation,
18
  left_transformation,
19
  mask,
20
  doLog = TRUE,
21
  geom = FALSE,
22
  relative = TRUE
23
) {
24
25
  # Create separate left and right masks
26
  right = mask == 1
27
  left = mask == 2
28
29
  # Create Jacobian Determinant Image
30
  jacob_right <- createJacobianDeterminantImage(domainImg = mask,
31
                                          tx = right_transformation,
32
                                          doLog = doLog,
33
                                          geom = FALSE)
34
  jacob_right <- maskImage(jacob_right, right)
35
36
  jacob_left <- createJacobianDeterminantImage(domainImg = mask,
37
                                                tx = left_transformation,
38
                                                doLog = doLog,
39
                                                geom = FALSE)
40
  jacob_left <- maskImage(jacob_left, left)
41
42
  # Put images together
43
  jacob = jacob_right + jacob_left
44
45
  if(relative){
46
47
    jacob_right_relative <- jacob_right/mean(jacob_right)
48
    jacob_left_relative <- jacob_left/mean(jacob_left)
49
    jacob_relative <- jacob_right_relative + jacob_left_relative
50
51
    mylist = list(jacob = jacob,
52
                  jacob_relative = jacob_relative)
53
  }else{
54
    mylist = jacob
55
  }
56
57
  return(mylist)
58
}