ledigchr / MALPEM

MALPEM whole-brain segmentation framework
Other
20 stars 10 forks source link

N4 bias correction fails due to invalid region #12

Closed prasadvagdargi closed 2 years ago

prasadvagdargi commented 2 years ago

Dear Christian Ledig,

The N4 bias correction fails and exits in a few cases where the skull extends beyond the image and is truncated, causing a missing correction file and failed segmentation. The exception reported by ITK is due to an invalid requested region as listed in the log file below. Note that this is different from #7 where the output directory is entirely missing. Here, the bias correction pipeline exits abruptly, causing a missing file.

The image is MPRAGE sagittal sequence of dimensions 512x512x208 with 0.4297 x 0.4297 x 0.9000 mm voxel size. Any suggestions on how to proceed would be appreciated.

$ malpem-proot -i FO-628328595471209848.nii.gz -o . -t 16 --field_strength 3T WARNING: Didn't find libGL library in /usr/lib/nvid*, offscreen rendering won't work (only relevant for pdf report) Copying file FO-628328595471209848.nii.gz to input directory: cp FO-628328595471209848.nii.gz ~/malpem-1.3/bin/../lib/care//rootfs/tmp//input//tmp.MWGFTsAhr4/

Command in CARE environment: malpem -i /tmp/input/tmp.MWGFTsAhr4/FO-628328595471209848.nii.gz -o /tmp/output/tmp.MWGFTsAhr4/ -t 16 --field_strength 3T

Input file: /tmp/input/tmp.MWGFTsAhr4/FO-628328595471209848.nii.gz Output directory: /tmp/output/tmp.MWGFTsAhr4/ Field strength: 3T Max. threads: 16 Using input mask: False Using input segmentation: False Using transformation to initialise MNI alignment: False Performing initial bias correction: True Stopping after brain extraction: False Perform another N4 bias correction after the brain extraction: True Create a subdirectory for output: True Create final pdf report: True Will clean up once finished: False

--- STARTED Whole-brain segmentation pipeline (MALPEM) --- Creating artificial 'full image mask' to perform bias correction on complete image domain --- STARTED getting mask for full image --- --- FINISHED getting mask for full image in 0:00:11 --- --- STARTED N4 bias correction ---

--- ERROR: File does not exist (/tmp/output/tmp.MWGFTsAhr4/FO-628328595471209848_28-09-21_18-25-03/FO-628328595471209848_N4.nii.gz): --- Moving results to output directory: . Cleaning up input directory: ~/malpem-1.3/bin/../lib/care//rootfs/tmp//input//tmp.MWGFTsAhr4

N4 Correction Log file:

/malpem/lib/itk/N4 -d 3 -i /tmp/input/tmp.MWGFTsAhr4/FO-628328595471209848.nii.gz -x /tmp/output/tmp.MWGFTsAhr4/FO-628328595471209848_28-09-21_18-25-03/FO-628328595471209848_mask_full_image.nii.gz -o /tmp/output/tmp.MWGFTsAhr4/FO-628328595471209848_28-09-21_18-25-03/FO-628328595471209848_N4.nii.gz -s 2 -c [50x40x30x20,0.0000001] -b [75,3,0.0,0.5] -t [0.15,0.01,200] >> /tmp/output/tmp.MWGFTsAhr4/FO-628328595471209848_28-09-21_18-25-03/log/N4-FO-628328595471209848.log 2>&1

Running N4 for 3-dimensional images.

Current level = 1 Iteration 1 (of 50). Current convergence value = 0.00105363 (threshold = 1e-07) Iteration 2 (of 50). Current convergence value = 0.0010723 (threshold = 1e-07) Iteration 3 (of 50). Current convergence value = 0.000911894 (threshold = 1e-07) ... Current level = 2 Iteration 1 (of 40). Current convergence value = 0.00114808 (threshold = 1e-07) Iteration 2 (of 40). Current convergence value = 0.00109599 (threshold = 1e-07) Iteration 3 (of 40). Current convergence value = 0.0010747 (threshold = 1e-07) Iteration 4 (of 40). Current convergence value = 0.00104282 (threshold = 1e-07) Iteration 5 (of 40). Current convergence value = 0.00101691 (threshold = 1e-07) Iteration 6 (of 40). Current convergence value = 0.00100544 (threshold = 1e-07) Iteration 7 (of 40). Current convergence value = 0.000994155 (threshold = 1e-07) Exception caught: itk::InvalidRequestedRegionError (0x7f6a756fa2a0) Location: "virtual void itk::DataObject::PropagateRequestedRegion()" File: /usr/local/plugins/libraries/advants/build/ITKv4/Modules/Core/Common/src/itkDataObject.cxx Line: 411 Description: Requested region is (at least partially) outside the largest possible region.

ledigchr commented 2 years ago

Hi, I think this problem is related to an issue in the N4 binary itself (see this discussion).

I have (rarely) observed this problem when processing some high resolution images in the past. One workaround is resampling the images that cause problems to a coarser resolution, e.g. 1mm x 1mm x 1mm.

Hope this helps.

prasadvagdargi commented 2 years ago

Thank you. I used MIPAV to resample the image to 0.9mm (and coarser resolutions) and it seems to work for those cases as a workaround.