[BUG]: compute_brain_mask fails to find Warp object #394
No reviewers
Labels
No labels
CRITICAL
Stale
WIP
bug
concept
coordinate
dataset
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
maintenance
maps
marker
mask
on hold
parcellation
preprocess
question
ready
storage
template-space
triage
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
juaml/junifer!394
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/compute-brain-mask"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Is there an existing issue for this?
Current Behavior
An error occurs when using a spacewarper and then a confound remover preprocessor that uses the
compute_brain_maskfunction.Basically, it complains that the
Warpobject was not passedExpected Behavior
I would expect the MNI2009c.... mask to be warped to the native space.
Steps To Reproduce
--element 100206Environment
Relevant log output
Anything else?
No response
Issue seems to be originating from here:
github.com/juaml/junifer@8c2de7518c/junifer/data/masks/_masks.py (L467)gh-pagesat 2024-11-13 15:33 UTCThis will fix the error, but I think we have a logic issue/bug.
Right after "computing the brain mask", we resample the brain mask to the image and apply the threshold:
github.com/juaml/junifer@a0f883bbfb/junifer/data/masks/_masks.py (L109-L115)The order made sense when we implemented: we resample and then threshold, as these are probability maps.
When we added the multi-MNI space and "warping" to masks, we now need to do the warping BEFORE thresholding. What we actually want to warp is the probability map and then apply the threshold.
In short, compute_brain_mask should already give you the mask in the required space, even if this is "native" space.
We should also be able to combine
compute_brain_maskandcompute_epi_maskin native space, why not?I think the whole
getfunction is flawed in this sense as we started adding features like combining, interescting, computing and using pre-defined masks.The logic should be:
While this might be inefficient at some point (warping many images from the same MNI to native separately), it is a rare use case in which one might want to "merge" two or more masks that are in standard space to be used in native space. Usually (except for HCP), one has the subject-specific probseg files and can use the compute_brain_mask without warping.
A possible optimization would be: in the case that all masks are non-computed and the target space is native, warp to the intermediate required standard space and delay warping to native space at the end, after intersection/union/etc. Will not be numerically equal but would be conceptually the same in case of union/intersection (threshold 0 or 1)
Codecov Report
All modified and coverable lines are covered by tests ✅
Additional details and impacted files
100.00% <ø> (ø)Flags with carried forward coverage won't be shown. Click here to find out more.
84.35% <ø> (+1.02%)Moved this logical refactor to #395
@fraimondo If this solves the specific issue, let's get this merged and take care of the logical rework in #395 ?
As it is right now, this fixes an error in the code. The problem is that the bug from #395 is still there (and this will even enable users to obtain values which are not correct).
This bug lead to the discovery of an even more important bug (#395). I think that fixing #395 is more important, as likely this one gets solved on the way.
Resolved as part of #395
Pull request closed