Conversation
dkuegler
left a comment
There was a problem hiding this comment.
We should think about whether we want to move all the formatting changes out of this PR into a separate PR. I also have a number of formatting cleanup things, we should probably put those changes into a formatting PR...
Since they are constrained to the CC module and separate commits, I think it wouldn't make a difference after this PR is merged |
|
Adressed/replied to all coments @dkuegler |
Return MidplaneRefinementResult/MidplaneDebugVolumes dataclasses for named field access. Refine midsagittal LR correction heuristic Create parent directories for CC VTK output
Adds --midplane_method {none,lr_shift,distance_map} argument to
fastsurfer_cc.py to allow comparing all three midplane refinement
conditions in a single codebase without branch switching. Defaults to
'distance_map' (existing behaviour). Debug volume saves are guarded so
they are skipped for non-distance_map methods.
Ignores /scripts/ in .gitignore (local experiment scripts only).
- Fix _prepare_lr_pair_labels: replace incorrect +1000 label offset assumption with an explicit FreeSurfer aseg left/right pair table (_ASEG_LR_PAIRS). The old code only ever matched WM (2,41) via the fallback; now all standard aseg bilateral structures are used. - Fix midline_refine_shift_vox stored as int(): changed to float() so sub-voxel distance_map corrections are not truncated. - Refactor: refine_midline_lr_shift now calls resample_segmentation_to_fsavg instead of duplicating the affine_transform logic. - Add no_baseline flag to lr_shift diagnostics dict. - Change aseg_nib (nibabelImage) parameter to aseg_data (np.ndarray) in both refine_midline_lr_shift and refine_midplane_with_distance_maps; callers extract the array before the call.
New choices (old → new): none → fsaverage (fsaverage alignment only) lr_shift → fsaverage_symmetry (default: fsaverage + LR label-symmetry shift) distance_map → fsaverage_distance_map (fsaverage + distance-map plane fit) [new] center (center slice of input volume, no alignment) The 'center' option skips register_centroids_to_fsavg entirely and uses an identity vox2vox with the volume's own affine, setting the midplane at shape[0]/2 in original image space. Replace hardcoded FSAVERAGE_MIDDLE/vox_size on the fsavg2midslice line with _base_middle_vox so 'center' uses the correct midpoint.
Move register_centroids_to_fsavg, refine_midline_lr_shift, and all
supporting helpers (_ASEG_LR_PAIRS, _prepare_lr_pair_labels,
_score_midline_shift) from fastsurfer_cc.py into midplane_refinement.py.
Add MidplaneTransformResult dataclass and find_midplane_transform(),
a single entry point that dispatches across all four midplane methods
("center", "fsaverage", "fsaverage_symmetry", "fsaverage_distance_map")
and returns a uniform result.
Replace the scattered midplane dispatch block in main() with one call
to find_midplane_transform(). Remove the five debug-output CLI flags
(--midplane_distance_map, --midplane_fit_mask, etc.) and their
corresponding save blocks, which were used only during development.
- Move _ASEG_LR_PAIRS comment to midplane_refinement.py where the constant now lives - Remove [tool.uv.sources] whippersnappy git override from pyproject.toml (conflicts with the >=2.1 release pin kept from HEAD) - Revert Dockerfile whippersnappy dep from libosmesa6 back to libegl1 (HEAD's choice, overriding the no-gpu rendering change from 4a694e3)
0352c0d to
6ec7400
Compare
|
I cleaned up the history a bit. I guess we can merge this now. |
There was a problem hiding this comment.
Pull request overview
This PR adds configurable midsagittal plane refinement options to the Corpus Callosum (CC) pipeline, improving robustness on asymmetric anatomies by refining alignment only near the initially estimated midplane.
Changes:
- Introduces
CorpusCallosum/registration/midsagittal_plane_alignment.pywith multiple midplane strategies (fsaverage-only, symmetry-based LR shift refinement, distance-map plane fitting, and center-based mode). - Adds
--midplane_methodCLI flag infastsurfer_cc.pyand stores refinement diagnostics in output metrics. - Updates documentation and API docs to describe the new midplane extraction/refinement options; adds a small mesh I/O improvement.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
doc/scripts/fastsurfer_cc.rst |
Documents --midplane_method and available midplane refinement modes. |
doc/overview/modules/CC.md |
Updates pipeline overview wording/order related to midsagittal extraction. |
doc/api/index.rst |
Adds CC registration module to API docs index. |
doc/api/CorpusCallosum.registration.rst |
New Sphinx API stub for CorpusCallosum.registration. |
CorpusCallosum/shape/mesh.py |
Ensures parent directory exists before writing VTK meshes. |
CorpusCallosum/registration/midsagittal_plane_alignment.py |
New midplane alignment/refinement implementation and related dataclasses. |
CorpusCallosum/fastsurfer_cc.py |
Wires in new midplane transform selection via --midplane_method and emits diagnostics. |
.gitignore |
Ignores a top-level /scripts/** directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This PR introduces a midplane refinement strategy for asymmetric brains.
The refinement strategy still relies on symmetry between structures but considers only structures close to the initially found mid-sagittal plane. This improves the midplane on previously challenging cases, while not affecting others.
The refinement can be disabled via flag. Also, it is not possible to completely skip midsagittal plane alignment for testing.