ANTsX / ANTs

Advanced Normalization Tools (ANTs)
Apache License 2.0
1.2k stars 381 forks source link

ITK Error in antsBrainExtraction.sh #304

Closed chriscrosscutler closed 8 years ago

chriscrosscutler commented 8 years ago

I've been trying to preprocess my dataset so I can then run JointLabelFusion on each subject. Everything works fine until I try to skull strip the t1 images using antsBrainExtraction.sh. Here is my code I am using:

ACPCDetect Alignment

echo ACPC align for $files /fslhome/ccutle25/apps/art/acpcdetect -M -o $files/acpc.nii -i $files/t1.nii

N4 Bias Field Correction

echo N4 bias for: $files /fslhome/ccutle25/bin/antsbin/bin/N4BiasFieldCorrection -d 3 -i $files/acpc.nii -o [$files/corrected.nii.gz,$files/biasfield.nii.gz] -s 4 -b [200] -c [50x50x50x50,0.000001]

Voxel Resampling to 1x1x1mm Isometric

echo Resampling image from $files to 1x1x1mm.. ~/apps/c3d/bin/c3d -verbose $files/corrected.nii.gz -resample-mm 1x1x1mm -o $files/n4_resampled.nii.gz

Skull Stripping

echo Skull Strip sh /fslhome/ccutle25/bin/antsbin/bin/antsBrainExtraction.sh -d 3 -a $files/n4_resampled.nii.gz -e /fslhome/ccutle25/templates/OASIS/OASIS-30_Atropos_template/T_template0.nii.gz -m /fslhome/ccutle25/templates/OASIS/OASIS-30_Atropos_template/T_template0_BrainCerebellumProbabilityMask.nii.gz -o $files/

When antsBrainExtraction is running the terminal outputs this warning around 22 times:

BEGIN >>>>>>>>>>>>>>>>>>>> /fslhome/ccutle25/bin/antsbin/bin/antsAI -d 3 -v 1 -m MI[/fslhome/ccutle25/compute/ucsd_t1/sd_001--2012-09-20/BrainExtractionInitialAffineFixed.nii.gz,/fslhome/ccutle25/compute/ucsd_t1/sd_001--2012-09-20/BrainExtractionInitialAffineMoving.nii.gz,32,Regular,0.25] -t Affine[0.1] -s [15,0.1] -p 0 -c 10 -o /fslhome/ccutle25/compute/ucsd_t1/sd_001--2012-09-20/BrainExtractionInitialAffine.mat Using the Mattes MI metric (number of bins = 32) WARNING: In /fslhome/ccutle25/bin/antsbin/ITKv4-install/include/ITK-4.9/itkObjectToObjectMetric.hxx, line 529 JointHistogramMutualInformationImageToImageMetricv4 (0x36ab810): No valid points were found during metric evaluation. For image metrics, verify that the images overlap appropriately. For instance, you can align the image centers by translation. For point-set metrics, verify that the fixed points, once transformed into the virtual domain space, actually lie within the virtual domain.

Then there is also this error:

* Running AffineTransform registration *

Exception caught: itk::ExceptionObject (0x3983be0) Location: "unknown" File: /fslhome/ccutle25/bin/antsbin/ITKv4-install/include/ITK-4.9/itkMattesMutualInformationImageToImageMetricv4.hxx Line: 238 Description: itk::ERROR: MattesMutualInformationImageToImageMetricv4(0x39124b0): Too many samples map outside moving image buffer. There are only 397 valid points out of 7686 total points. The images do not sufficiently overlap. They need to be initialized to have more overlap before this metric will work. For instance, you can align the image centers by translation.

The resulting "extracted" brains look exactly like the unextracted images and the mask appears to be so large that it includes the whole head.

Is this a error on my part or something in ANTs?

ntustison commented 8 years ago

Can you post the file $files/n4_resampled.nii.gz?

chriscrosscutler commented 8 years ago

n4_resampled.nii.gz

chriscrosscutler commented 8 years ago

I just tried manually setting the origin of n4_resampled.nii.gz to [0,0,0] and that resulted in the same issue as we had talked about before: https://github.com/stnava/ANTs/issues/278

chriscrosscutler commented 8 years ago

Resetting the origin also got rid of the error I mentioned but now it won't even run.

ntustison commented 8 years ago

It would seem as though your errors are specific to your system. I have no problem running antsBrainExtraction.sh on your data.

screen shot 2016-04-12 at 3 31 06 pm

chriscrosscutler commented 8 years ago

Interesting. What settings did you use for BrainExtraction if you don't mind me asking?

ntustison commented 8 years ago

Same as the command line you posted originally.

chriscrosscutler commented 8 years ago

Ok, thanks. Hopefully I'll be able to figure this one out.

ntustison commented 8 years ago

Did you ever resolve the previous gcc version issue?

chriscrosscutler commented 8 years ago

I tried finding the gcc version that my macbook uses on our supercomputer but they didn’t have any available versions of gcc to load that were as old as 4.2.1. I requested them to install 4.2.1 but they said that it would most likely cause more problems than it would solve. The guys that manage our supercomputer said that the seg fault caused by the brain extract script was probably caused by a error in the code and not the compiler. That was after I mentioned that the program ran fine on my mac but doesn’t work on the supercomputer. So I have yet to figure that out. I actually had to use BET to get skull strip so I could run JointLabelFusion. I would rather use all ANTs through…

Chris

stnava commented 8 years ago

as a point of reference, i've been using gcc4.4.7 without problem ... what, again, version of gcc caused trouble?

brian

On Tue, Apr 12, 2016 at 7:59 PM, Chris Cutler notifications@github.com wrote:

I tried finding the gcc version that my macbook uses on our supercomputer but they didn’t have any available versions of gcc to load that were as old as 4.2.1. I requested them to install 4.2.1 but they said that it would most likely cause more problems than it would solve. The guys that manage our supercomputer said that the seg fault caused by the brain extract script was probably caused by a error in the code and not the compiler. That was after I mentioned that the program ran fine on my mac but doesn’t work on the supercomputer. So I have yet to figure that out. I actually had to use BET to get skull strip so I could run JointLabelFusion. I would rather use all ANTs through…

Chris

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/stnava/ANTs/issues/304#issuecomment-209156372

chriscrosscutler commented 8 years ago

I am currently using 4.9.2. I don’t remember what I was using when I posted the original issue though. I’m sure it was the same because I haven’t changed it.

chriscrosscutler commented 8 years ago

We only have 4.4 available. Is that suitable?

stnava commented 8 years ago

4.4 should be fine ... i have been processing plenty of data with no issues based on 4.4.7.

brian

On Tue, Apr 12, 2016 at 9:03 PM, Chris Cutler notifications@github.com wrote:

Reopened #304 https://github.com/stnava/ANTs/issues/304.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/stnava/ANTs/issues/304#event-625034415

ntustison commented 8 years ago

Most of the programs compile fine on 4.8 although there are some unfamiliar warnings that, if I remember correctly, extend all the way down to the ITK base. I'll put that on my to-do list to see if I can modernize the ANTs code a bit.

chriscrosscutler commented 8 years ago

I know that to get the latest version of ANTs to compile on our supercomputer we had to change a flag In the cmake module. The gcc exe linker flag was changed to -fuse-ld=bfd under advanced options. Would that flag play into this at all? Without that flag we were running on a much older version of ANTs.

chriscrosscutler commented 8 years ago

After compiling ANTs with gcc 4.4 antsBrainExtraction.sh now runs without any ITK error. However, It appears that it is consistantly cutting off the frontal lobe? screen shot 2016-04-13 at 22 08 14

What would be causing this? It's pretty consistent across multiple subjects.

ntustison commented 8 years ago

As we discuss in this paper, you need a brain extraction template which is similar to the images in your cohort. I'm guessing that this is not the case with your data based on the earlier image you posted and since you're seeing similar results across subjects.

njhunsak commented 8 years ago

I've been trying to help Chris with this issue as well and I'm beginning to think there might be something we are missing. I recently generated a template for another project I'm working on (actually for David Tate) and when I run the template image through antsBrainExtraction.sh or antsCorticalThickness.sh I get the same issue where the front of the brain is cut off! I used the OASIS template.

DATA_DIR=/U1/hunsakern/templates/iScore
TEMPLATE_DIR=/U1/hunsakern/templates/OASIS
OUT_DIR=${DATA_DIR}/output
INPUT_TEMPLATE=${DATA_DIR}/iScore_template.nii.gz

${ANTSPATH}antsCorticalThickness.sh -d 3 \
  -a $INPUT_TEMPLATE \
  -e ${TEMPLATE_DIR}/T_template0.nii.gz \
  -m ${TEMPLATE_DIR}/T_template0_BrainCerebellumProbabilityMask.nii.gz \
  -p ${TEMPLATE_DIR}/Priors2/priors%d.nii.gz \
  -o ${OUT_DIR}/ \
  -q 1 \
  -u 1

screen shot 2016-04-18 at 7 54 46 am

I did a fresh install of ANTs on 2016-04-04 with no installation problems (running GCC 4.4.7), do you think I should try to update ANTs again? Here's the template imaging I am trying to run through antsCorticalThickness.sh.

https://www.dropbox.com/s/m7sghvnqqmhxzwe/iScore_template.nii.gz?dl=0

stnava commented 8 years ago

I agree that there is an issue and I know what it is related to .... will talk to @nustiston about this later today after he finishes the Boston Marathon, hopefully in record time.

On Monday, April 18, 2016, Naomi H. notifications@github.com wrote:

I've been trying to help Chris with this issue as well and I'm beginning to think there might be something we are missing. I recently generated a template for another project I'm working on (actually for David Tate) and when I run the template image through antsBrainExtraction.sh or antsCorticalThickness.sh I get the same issue where the front of the brain is cut off! I used the OASIS template https://figshare.com/articles/ANTs_ANTsR_Brain_Templates/915436.

DATA_DIR=/U1/hunsakern/templates/iScore TEMPLATE_DIR=/U1/hunsakern/templates/OASIS OUT_DIR=${DATA_DIR}/output INPUT_TEMPLATE=${DATA_DIR}/iScore_template.nii.gz ${ANTSPATH}antsCorticalThickness.sh -d 3 \ -a $INPUT_TEMPLATE \ -e ${TEMPLATE_DIR}/T_template0.nii.gz \ -m ${TEMPLATE_DIR}/T_template0_BrainCerebellumProbabilityMask.nii.gz \ -p ${TEMPLATE_DIR}/Priors2/priors%d.nii.gz \ -o ${OUT_DIR}/ \ -q 1 \ -u 1

[image: screen shot 2016-04-18 at 7 54 46 am] https://cloud.githubusercontent.com/assets/4333838/14606529/e7361db6-053a-11e6-98a8-47b34d0be85b.png

I did a fresh install of ANTs on 2016-04-04 with no installation problems (running GCC 4.4.7), do you think I should try to update ANTs again? Here's the template imaging I am trying to run through antsCorticalThickness.sh.

https://www.dropbox.com/s/m7sghvnqqmhxzwe/iScore_template.nii.gz?dl=0

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/stnava/ANTs/issues/304#issuecomment-211397470

brian

cookpa commented 8 years ago

The OASIS template has no facial structures, they are cut off in the input images to protect patient identity.

It will likely have problems matching input data with the face intact. Try including

-f T_template0_BrainCerebellumRegistrationMask.nii.gz

Masking the registration can cause its own problems but it is often necessary when some images have missing features.

njhunsak commented 8 years ago

@cookpa Giving that a try right now to see if it improves the results! Thanks.

ntustison commented 8 years ago

Yeah, I would definitely try Phil's suggestion and it's what I was getting at in my earlier suggestion---you need a template which matches the features of your cohort. The OASIS data is "defaced" whereas your data is not. Another possibility would be to use the Kirby or IXI template which are also not defaced.

chriscrosscutler commented 8 years ago

Using the -f flag in antsBrainExtraction.sh solved the error. Thank you guys for your help.