Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abpBrainExtraction fails #315

Closed
vnckppl opened this issue May 11, 2020 · 13 comments
Closed

abpBrainExtraction fails #315

vnckppl opened this issue May 11, 2020 · 13 comments

Comments

@vnckppl
Copy link

vnckppl commented May 11, 2020

Issue
I am running abpBrainExtraction on a T1-weighted image that has previously been processed with abpN4. I use OASIS-30 data as template and mask.

I run the following code:

# Load template image and mask
tem <- antsImageRead(
  "/software/templates/OASIS-30/T_template0.nii.gz"
)
temmask <- antsImageRead(
  "/software/templates/OASIS-30/T_template0_BrainCerebellumMask.nii.gz"
)

# Load T1w data
myT1 <- antsImageRead("/data/in/T1w_n4.nii.gz")

# Build brain mask
mask <- abpBrainExtraction(
  img = myT1,
  tem = tem,
  temmask = temmask,
  tdir = "/data/in"
)

This results in:

source("example.R")
 bad det -1 v 1 u -1
 bad det -1 v 1 u -1 new 1
 bad det -1 v 1 u -1
 bad det -1 v 1 u -1 new 1

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: antsImageHeaderInfo(filename)
 2: doTryCatch(return(expr), name, parentenv, handler)
 3: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 4: tryCatchList(expr, classes, parentenv, handlers)
 5: tryCatch(antsImageHeaderInfo(filename), error = function(e) return(NA))
 6: antsImageRead(x, ...)
 7: FUN(X[[i]], ...)
 8: FUN(X[[i]], ...)
 9: lapply(x, check_ants, ... = ...)
10: FUN(X[[i]], ...)
11: FUN(X[[i]], ...)
12: lapply(x, check_ants, ... = ...)
13: check_ants(image)
14: check_ants(image)
15: antsImageWrite(mask, "/data/in/mymask.nii.gz")
16: eval(ei, envir)
17: eval(ei, envir)
18: withVisible(eval(ei, envir))
19: source("example.R")

OS and Software versions:

  • OS: Debian GNU/Linux bullseye/sid"
  • R: R version 3.6.3
  • ITKR_0.5.3
  • ANTsR_0.5.4.2
  • ANTsRCore_0.7.4
@dorianps
Copy link
Collaborator

dorianps commented May 11, 2020 via email

@vnckppl
Copy link
Author

vnckppl commented May 11, 2020

I run R in a Docker container on OSX. The system itself has 16gb of ram, with 10gb allocated to Docker and 1Gb Swap. I think this should be sufficient, but correct me if I am wrong. I even upped the swap to 2gb and re-ran the script, but I get the exact same errors.

@dorianps
Copy link
Collaborator

dorianps commented May 11, 2020 via email

@vnckppl
Copy link
Author

vnckppl commented May 11, 2020

I think I have. When I manually enter the container with docker run -it -v /some/local/folder:/data/in --entrypoint=/bin/bash someContainerID I can read and write to the local folder without any issues.
Also, when I run R from within the container, I have no issues reading and writing images.
Moreover, apbN4, antsRegistration, and ants_brain_extract (ANTsRNet) all run fine from within the container.

@muschellij2
Copy link
Collaborator

muschellij2 commented May 11, 2020 via email

@vnckppl
Copy link
Author

vnckppl commented May 11, 2020

Starting the container with:

docker run -it \
       -v /some/local/input/folder:/data/in:ro \
       -v /some/local/output/folder:/data/out \
       --entrypoint=/bin/bash \
       someContainerID

and then running R, sourcing the following code:

## * Load Library
library("ANTsR")


## * Load data
base <- "/data/in"

myt1w <- antsImageRead(
  file.path(base, "T1w_n4.nii.gz")
)
myt1w_mask <- antsImageRead(
  file.path(base, "T1w_n4_mask.nii.gz")
)


## * Run N4 correction on entire image
# Ouptut folder
out_dir <- "/data/out/N4_noMask"
dir.create(out_dir)
# Run N4
output_image <- n4BiasFieldCorrection(myt1w, verbose = TRUE)
# Save output file
outfile <- file.path(out_dir, "N4_noMask.nii.gz")
antsImageWrite(output_image, outfile)



## * Run N4 correction within brain mask
# Ouptut folder
out_dir <- "/data/out/N4_withinMask"
dir.create(out_dir)
# Run N4
output_image <- n4BiasFieldCorrection(myt1w, myt1w_mask, verbose = TRUE)
# Save output file
outfile <- file.path(out_dir, "N4_withinMask.nii.gz")
antsImageWrite(output_image, outfile)

runs fine and produces the two expected N4 corrected images.

@muschellij2
Copy link
Collaborator

muschellij2 commented May 11, 2020 via email

@vnckppl
Copy link
Author

vnckppl commented May 11, 2020

Hi John,
I did (and have updated my previous post).
Same results, i.e., this runs smoothly.

@muschellij2
Copy link
Collaborator

muschellij2 commented May 11, 2020 via email

@vnckppl
Copy link
Author

vnckppl commented May 11, 2020

I am getting the same error with a default template that comes with FSL, so I guess the image itself is not the problem. I am further investigating the issue. I am building a virtual environment with ANTsR using Packrat so that I can try and see if a different setup produces the same error. However, I am running into some other issues with install_github("stnava/ANTsR") for which I have opened another thread here.

@vnckppl
Copy link
Author

vnckppl commented May 12, 2020

I figured out what went wrong. I was expecting abpBrainExtraction to write out an antsImage, but it is writing out a list. When I tried to write out the list as an antsImage, R throws the memory error:

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Everything works now, and the masks look good. For some image, I do see this warning/error in the terminal though:

 bad det -1 v -1 u 1
 bad det -1 v -1 u 1 new 1
 bad det -1 v -1 u 1
 bad det -1 v -1 u 1 new 1

Should I be worried about that?

@vnckppl vnckppl closed this as completed May 12, 2020
@dorianps
Copy link
Collaborator

dorianps commented May 12, 2020 via email

@cookpa
Copy link
Member

cookpa commented May 12, 2020

Those errors come from antsAI. It is a multi-start optimizer that tries a bunch of rotations and translations to initialize registrations. Some of them will be so far off from the right solution that they fail. If you see hundreds of them, it might be a problem, but a few are expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants