|
a |
|
b/R/radiomics_lung.R |
|
|
1 |
#' Radiomic Calculation on Lung CTs |
|
|
2 |
#' |
|
|
3 |
#' Calculate individual radiomic features on the whole 3D lung, left and right lungs separately |
|
|
4 |
#' |
|
|
5 |
#' @param img CT scan in ANTs image file format |
|
|
6 |
#' @param mask Mask of CT scan in ANTs image file format |
|
|
7 |
#' @param sides Choose to calculate radiomic features on the right and/or left lungs. Note: Right lung = 1, left lung = 2, non-lung = 0 |
|
|
8 |
#' @param featuresFirst First level radiomic features to calculate |
|
|
9 |
#' @param featuresSpatial Spatial radiomic features to calculate |
|
|
10 |
#' |
|
|
11 |
#' @return Values from selected features for both left and right lungs |
|
|
12 |
#' @importFrom ANTsR maskImage |
|
|
13 |
#' @export |
|
|
14 |
radiomics_lung <- function(img, |
|
|
15 |
mask, |
|
|
16 |
sides = c("right", "left"), |
|
|
17 |
featuresFirst = c('mean', 'sd', 'skew', 'kurtosis', 'min', 'q1', 'median', 'q3', 'max','energy', 'rms', 'uniformity', 'entropy'), |
|
|
18 |
featuresSpatial = c('mi', 'gc', 'fd')){ |
|
|
19 |
|
|
|
20 |
featuresMask <- lapply(sides, function(side){ |
|
|
21 |
|
|
|
22 |
if(side == "right"){mv = 1} |
|
|
23 |
if(side == "left"){mv = 2} |
|
|
24 |
|
|
|
25 |
# Put image in array format and remove non-mask values |
|
|
26 |
img2 <- as.array(img) |
|
|
27 |
mask2 <- as.array(mask) |
|
|
28 |
img2[mask2 != mv] <- NA |
|
|
29 |
|
|
|
30 |
# Calculate features |
|
|
31 |
features1 <- radiomics_first(img2, featuresFirst) |
|
|
32 |
features2 <- radiomics_spatial(img2, featuresSpatial) |
|
|
33 |
return(c(features1, features2)) |
|
|
34 |
}) |
|
|
35 |
names(featuresMask) <- sides |
|
|
36 |
|
|
|
37 |
return(featuresMask) |
|
|
38 |
} |
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|