Skip to content

Conversation

@oesteban
Copy link
Member

Replaces the template's binary mask with a probabilistic map.

The workflow for EPI brain-extraction utilizes an atlas-based approach in its initialization. Before this PR, the template's mask is binary. The intention is to minimize numerical instability of edge voxels due to the resampling of the binary mask (i.e., when moving the atlas' brain mask on to the subject space). With this PR, the binarization occurs later and the risk of having a voxel whose value varies between runs (due to the minimal but existing variability introduced by the ants registration process) is much lower.

See #476

@oesteban oesteban added this to the 1.2.0 milestone Mar 21, 2020
@pull-assistant
Copy link

pull-assistant bot commented Mar 21, 2020

@oesteban oesteban force-pushed the masks/476-epi-brainmask-probseg branch 3 times, most recently from 7ef66a2 to e569fca Compare March 21, 2020 18:29
@codecov
Copy link

codecov bot commented Mar 21, 2020

Codecov Report

Merging #485 into master will decrease coverage by 4.78%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #485      +/-   ##
==========================================
- Coverage   64.17%   59.38%   -4.79%     
==========================================
  Files          43       42       -1     
  Lines        5290     5326      +36     
  Branches      770      774       +4     
==========================================
- Hits         3395     3163     -232     
- Misses       1750     2036     +286     
+ Partials      145      127      -18     
Flag Coverage Δ
#documentation ?
#reportlettests ?
#travis 59.38% <0.00%> (+0.07%) ⬆️
#unittests ?
Impacted Files Coverage Δ
niworkflows/func/util.py 24.32% <0.00%> (-63.18%) ⬇️
niworkflows/anat/ants.py 12.15% <0.00%> (-57.46%) ⬇️
niworkflows/anat/freesurfer.py 39.13% <0.00%> (-52.18%) ⬇️
niworkflows/anat/skullstrip.py 30.00% <0.00%> (-50.00%) ⬇️
niworkflows/interfaces/itk.py 26.92% <0.00%> (-12.31%) ⬇️
niworkflows/interfaces/fixes.py 41.17% <0.00%> (-11.77%) ⬇️
niworkflows/interfaces/bids.py 87.45% <0.00%> (-9.06%) ⬇️
niworkflows/interfaces/ants.py 57.81% <0.00%> (-7.82%) ⬇️
niworkflows/utils/images.py 82.75% <0.00%> (-5.25%) ⬇️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a6a328f...ef680de. Read the comment docs.

@oesteban oesteban force-pushed the masks/476-epi-brainmask-probseg branch from e569fca to 7cf097f Compare March 21, 2020 21:16
@oesteban oesteban requested a review from effigies March 22, 2020 00:19
@oesteban
Copy link
Member Author

Waiting on #488 so that I can run some validation tests on TACC.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the argument. Two small comments.

Copy link
Contributor

@mgxd mgxd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oesteban anything else you wanted to address here?

@oesteban
Copy link
Member Author

oesteban commented Apr 7, 2020

I haven't tested this yet on TACC on a larger scale but it should be ready to go. One little detail I might have overseen from @effigies comment is that the desc-brain_probseg is not valid, it should be label-brain_probseg. I probably did not understand his comment at the moment. Do we want to address that detail?

@mgxd
Copy link
Contributor

mgxd commented Apr 7, 2020

yup - would you have time to get that in today? I'm planning on cutting a new rc today

@oesteban
Copy link
Member Author

oesteban commented Apr 7, 2020

okay, doing it right now

@oesteban oesteban force-pushed the masks/476-epi-brainmask-probseg branch 3 times, most recently from 5358c98 to b038cb8 Compare April 8, 2020 01:34
@oesteban
Copy link
Member Author

I'm finding it impossible to test this separately before merging. Should we just go ahead or keep waiting until I can do this (or someone else)?

@effigies
Copy link
Member

Do we have an fMRIPrep branch pinned against this to at least get one CI run we can look at artifacts?

@oesteban oesteban force-pushed the masks/476-epi-brainmask-probseg branch 2 times, most recently from d4c8e26 to 4f38379 Compare May 8, 2020 01:23
@mgxd mgxd modified the milestones: 1.2.0, 1.3.0 May 21, 2020
@oesteban oesteban force-pushed the masks/476-epi-brainmask-probseg branch 2 times, most recently from 4db6a60 to cbe4022 Compare May 22, 2020 23:59
oesteban and others added 6 commits May 28, 2020 13:10
make sure that the new masks are uploaded to the artifacts
Co-Authored-By: Chris Markiewicz <[email protected]>
Taking advantage of the new auto-update. This commit also removes the
requirements.txt file that was used exclusively by the Docker image
distribution: pyntcloud now is in Pypi and we can safely pin
templateflow to >=0.6.0 since the autoupdate was implemented.
@oesteban oesteban force-pushed the masks/476-epi-brainmask-probseg branch from cbe4022 to 66c37d4 Compare May 28, 2020 20:11
@oesteban oesteban force-pushed the masks/476-epi-brainmask-probseg branch from d0bdb2b to 2af5e71 Compare June 2, 2020 15:51
@oesteban oesteban force-pushed the masks/476-epi-brainmask-probseg branch from 5c166e2 to 294a867 Compare June 3, 2020 00:12
@oesteban
Copy link
Member Author

oesteban commented Jun 5, 2020

I think we can go ahead with this one - we probably will need to revise the brain mask down the line, but that's more of a TemplateFlow's problem. WDYT?

@oesteban
Copy link
Member Author

oesteban commented Jun 5, 2020

@effigies @mgxd any issues with merging this one?

Bottom line is: unless we want to spend more time in generating a really probabilistic brainmask of MNI152NLin2009cAsym, this will not improve (we can move things around a little playing with the threshold, that doesn't give a lot of search space).

I think this is sufficient as is to address the problem, and setting the threshold at .85 or a bit higher seems to yield results very very close to those of the original binary mask.

If at some point we embark in generating probabilistic masks, I would basically extract the brain mask for many OpenNeuro datasets with OASIS (default sMRIPrep), keep using sMRIPrep to calculate the normalization to MNI152NLin2009cAsym, and finally average the resulting masks after projection back to MNI152NLin2009cAsym. This probabilistic mask would be interesting for two reasons:

  1. The potential improvement here (BOLD masking)
  2. Potential for T1w masking (e.g., https://github.com/poldracklab/smriprep/wiki/Brain-Extraction-from-T1w---very-hard-cases) and for switching the default template of brain extraction to the MNI. This would give the whole workflow a better consistency, and initialization from brain extraction could be reused to shave off some minutes of runtime.

(point 2 would be of an extremely low priority and I don't even have any expectation that it will be ever done).

@oesteban
Copy link
Member Author

oesteban commented Jun 5, 2020

----------
brainmask_thresh: :obj:`float`
Lower threshold for the probabilistic brainmask to obtain
the final binary mask (default: 0.5).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setting the threshold at .85 or a bit higher seems to yield results very very close to those of the original binary mask

shouldn't this be .85 by default then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no problem

@effigies
Copy link
Member

effigies commented Jun 5, 2020

On ds210, the mask is calculated on a pre-masked brain, and really doesn't match the boundary. It's hard to tell whether it would fit better if the underlying brain were unmasked.

https://14340-53175327-gh.circle-artifacts.com/0/tmp/ds210/derivatives/fmriprep/sub-02.html#datatype-figures_desc-summary_echo-None_run-1_suffix-bold_task-cuedSGT

@oesteban
Copy link
Member Author

oesteban commented Jun 5, 2020

On ds210, the mask is calculated on a pre-masked brain, and really doesn't match the boundary. It's hard to tell whether it would fit better if the underlying brain were unmasked.

Maybe not the best issue tittle I have chosen: nipreps/fmriprep#2162

Because of that difficulty, I have opened the reportlet before (older than the ME-EPI PR that started to show masked brains) and after this PR and checked visually the contour. Except for minimal deviations, with 0.85 the contour is almost always matched.

@oesteban oesteban changed the title ENH: Improve run-to-run reliability of EPI brain-masks ENH: Numerical stability of EPI brain-masks using probabilistic prior Jun 5, 2020
@oesteban oesteban merged commit f963b2c into nipreps:master Jun 5, 2020
@oesteban oesteban deleted the masks/476-epi-brainmask-probseg branch June 5, 2020 18:38
oesteban added a commit to nipreps/fmriprep that referenced this pull request Jun 5, 2020
to easily test new code on those (e.g., nipreps/niworkflows#485 in this particular commit)
effigies pushed a commit to nipreps/fmriprep-rodents that referenced this pull request Jul 9, 2020
to easily test new code on those (e.g., nipreps/niworkflows#485 in this particular commit)
oesteban added a commit that referenced this pull request Aug 14, 2020
First release in the 1.3.x series. This release includes enhancements and bug-fixes
towards the release of the first LTS version of fMRIPrep.
PyBIDS has been revised to use more recent versions, a series of ANTs' interfaces
have been deemed ready to upstream into Nipype, and several improvements regarding
multi-echo EPI are included.
With thanks to Basile Pinsard for contributions.

  * FIX: Patch ``ApplyTransforms`` spec to permit identity in a chain (#554)
  * FIX: Add dots to extensions in PyBIDS' config file (#548)
  * FIX: Segmentation plots aligned with cardinal axes (#544)
  * FIX: Skip T1w file existence check if ``anat_derivatives`` are provided (#545)
  * FIX: Avoid diverting CIFTI dtype from original BOLD (#532)
  * ENH: Add ``smooth`` input to ``RegridToZooms`` (#549)
  * ENH: Enable ``DerivativesDataSink`` to take multiple source files to derive entities (#547)
  * ENH: Allow ``bold_reference_wf`` to accept multiple EPIs/SBRefs (#408)
  * ENH: Numerical stability of EPI brain-masks using probabilistic prior (#485)
  * ENH: Add a pure-Python interface to resample to specific resolutions (#511)
  * MAINT: Finalize upstreaming of ANTs' interfaces to Nipype (#550)
  * MAINT: Update to Python +3.6 (#541)
HippocampusGirl added a commit to HippocampusGirl/niworkflows that referenced this pull request Sep 29, 2020
1.3.0rc3

First release in the 1.3.x series. This release includes enhancements and bug-fixes
towards the release of the first LTS version of fMRIPrep.
PyBIDS has been revised to use more recent versions, a series of ANTs' interfaces
have been deemed ready to upstream into Nipype, and several improvements regarding
multi-echo EPI are included.
With thanks to Basile Pinsard for contributions.

* FIX: Patch ``ApplyTransforms`` spec to permit identity in a chain (nipreps#554)
* FIX: Add dots to extensions in PyBIDS' config file (nipreps#548)
* FIX: Segmentation plots aligned with cardinal axes (nipreps#544)
* FIX: Skip T1w file existence check if ``anat_derivatives`` are provided (nipreps#545)
* FIX: Avoid diverting CIFTI dtype from original BOLD (nipreps#532)
* ENH: Add ``smooth`` input to ``RegridToZooms`` (nipreps#549)
* ENH: Enable ``DerivativesDataSink`` to take multiple source files to derive entities (nipreps#547)
* ENH: Allow ``bold_reference_wf`` to accept multiple EPIs/SBRefs (nipreps#408)
* ENH: Numerical stability of EPI brain-masks using probabilistic prior (nipreps#485)
* ENH: Add a pure-Python interface to resample to specific resolutions (nipreps#511)
* MAINT: Finalize upstreaming of ANTs' interfaces to Nipype (nipreps#550)
* MAINT: Update to Python +3.6 (nipreps#541)
HippocampusGirl added a commit to HippocampusGirl/niworkflows that referenced this pull request Sep 29, 2020
1.3.0

First release in the 1.3.x series.
This release includes enhancements and bug-fixes towards the release of the first
LTS (*long-term support*) version of *fMRIPrep*.
*PyBIDS* has been revised to use more recent versions, a series of ANTs' interfaces
have been deemed ready to upstream into *Nipype*, and several improvements regarding
multi-echo EPI are included.
With thanks to Basile Pinsard for contributions.

* FIX: Patch ``ApplyTransforms`` spec to permit identity in a chain (nipreps#554)
* FIX: Add dots to extensions in PyBIDS' config file (nipreps#548)
* FIX: Segmentation plots aligned with cardinal axes (nipreps#544)
* FIX: Skip T1w file existence check if ``anat_derivatives`` are provided (nipreps#545)
* FIX: Avoid diverting CIFTI dtype from original BOLD (nipreps#532)
* ENH: Add ``smooth`` input to ``RegridToZooms`` (nipreps#549)
* ENH: Enable ``DerivativesDataSink`` to take multiple source files to derive entities (nipreps#547)
* ENH: Allow ``bold_reference_wf`` to accept multiple EPIs/SBRefs (nipreps#408)
* ENH: Numerical stability of EPI brain-masks using probabilistic prior (nipreps#485)
* ENH: Add a pure-Python interface to resample to specific resolutions (nipreps#511)
* MAINT: Upstream all bug-fixes in the 1.2.9 release
* MAINT: Finalize upstreaming of ANTs' interfaces to Nipype (nipreps#550)
* MAINT: Update to Python +3.6 (nipreps#541)
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

Successfully merging this pull request may close these issues.

3 participants