Speed-up BA exvivo labels projection with python #183
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Replace
recon-all -balabels
with our own python code (except for themris_anatomical_stats
)In FreeSurfer BA exvivo (and other labels) are mapped from fsaverage to the current subject within the
recon-all -balabels
call. This is very slow as each label is mapped independently, requiring a nearest neighbour search. This PR adds python code (needing scikit-learn nearest neighbor search, KDTree) to compute correspondence one time per hemisphere and then map all labels as a batch and directly combine sets of labels into the corresponding annotation, which is far more efficient.mris_anatomical_stats
is not yet ported. It is still called from FreeSurfer to generate stats files for BA_exvivo labels and is the slowest part in the new pipeline (maybe it makes sense to port this in the future).The whole thing for both hemispheres takes now 33 seconds only! Compared to
recon-all -balabels
taking 7-8 mins on my machine.Note, while the label mapping is almost identical to FreeSurfer (at least visually), the merging for the annotation shows some small difference when resolving overlapping labels. Here - when label values agree - we select the label listed later to be the winner. When label values disagree, the one with the larger value wins. This is what FreeSurfer should be doing, but looks like it is not. Stats file, therefore, differ slightly. It is probably caused by noise in small decimal digits in the label values in FreeSurfer.