a b/R/quick_lung_mask.R
1
#' @rdname segment_lung
2
#' @export
3
#' @importFrom ANTsR connectedThreshold maskImage
4
#' @importFrom ANTsRCore iMath
5
quick_lung_mask = function(img,
6
                           lthresh = -300) {
7
  img = check_ants(img)
8
9
  # just get rid of the standard background just in case
10
  bg_mask = iMath(img < -950, "GetLargestComponent")
11
  mask = maskImage(img > -1023 & img < -900, 1 - bg_mask)
12
  ind = which(as.array(mask) > 0, arr.ind = TRUE)
13
  seed = floor(colMeans(ind))
14
  d = colMeans((t(ind) - seed)^2)
15
  seed = ind[which.min(d),]
16
17
  simg = connectedThreshold(img, seed = seed, upper = lthresh, lower = -1023)
18
19
}