Skip to content

CC module bugfix and robustness#791

Merged
m-reuter merged 4 commits intoDeep-MI:devfrom
ClePol:CC_bugfix
Feb 24, 2026
Merged

CC module bugfix and robustness#791
m-reuter merged 4 commits intoDeep-MI:devfrom
ClePol:CC_bugfix

Conversation

@ClePol
Copy link
Member

@ClePol ClePol commented Feb 19, 2026

This PR contains two changes:

  1. The fsaverage header saved as json file was incorrect, leading to faulty .ltas. This did not affect the segmentations, only applying the .lta with e.g. mri_convert.
  2. When the segmentation of the CC was irregular, e.g. due to segmentation failure or (partial) CC agenesis, the morphometry raised errors (as intended). Unfortunately, this meant that the whole FastSurfer pipeline crashed. This update handles morphometry errors more gracefully by still writing the CC segmentation and just reporting "null" for the morphometry of CC slices that could not be processed. Errors are still logged.

I also included an additional check in the SubjectDirectory classes path resolution that prevents writing the full path to the subject folder into the subject folder itself. I have encountered this multiple times when running locally and should not have effects when running in Docker. Feel free to revert if unintended.

@ClePol ClePol marked this pull request as draft February 19, 2026 11:56
@ClePol
Copy link
Member Author

ClePol commented Feb 19, 2026

Converted to draft, because the orient_volume.lta seems to be not limited to inplane rotation

@ClePol ClePol marked this pull request as ready for review February 19, 2026 12:12
@ClePol
Copy link
Member Author

ClePol commented Feb 19, 2026

commited a fix for the orient volume lta, everything seems fine now

@m-reuter
Copy link
Member

please fix all automated checks before marking it as ready for review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the robustness of the Corpus Callosum (CC) module by fixing a critical header bug and implementing graceful error handling for morphometry failures. The PR addresses issues where irregular CC segmentation or CC agenesis would crash the entire FastSurfer pipeline.

Changes:

  • Fixed incorrect fsaverage header values in JSON data file (Mdc direction cosines and Pxyz_c center coordinates were using placeholder values like 10 billion)
  • Added comprehensive error handling in CC morphometry to return None for failed slices instead of crashing
  • Modified functions to gracefully handle and continue processing when individual slices fail

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
CorpusCallosum/data/fsaverage_data.json Fixed incorrect Mdc matrix values and Pxyz_c center coordinates that were causing faulty .lta transformations
CorpusCallosum/shape/thickness.py Added error handling with logging for midline and level path computation failures
CorpusCallosum/shape/postprocessing.py Wrapped recon_cc_surf_measure in try-catch to return (None, None) on errors; updated return types to allow None
CorpusCallosum/fastsurfer_cc.py Moved segmentation saving before morphometry; added error handling around morphometry calls; filtered None results; updated LTA file generation with correct headers
CorpusCallosum/utils/mapping_helpers.py Changed calc_mapping_to_standard_space parameter from orig image to target_shape for clarity; added directory creation before saving
FastSurferCNN/utils/common.py Added path resolution logic to prevent writing full paths into subject folder (though implementation may need refinement)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@dkuegler dkuegler left a comment

Choose a reason for hiding this comment

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

I am also going to bring in a small fix of fastsurfer_cc I did yesterday into this PR.

@ClePol
Copy link
Member Author

ClePol commented Feb 19, 2026

I think quite a few review comments are refactoring and require changing multiple files and then another full testing. @dkuegler If you are adding another change and doing testing, it would be great if you could also address your comments at the same time

@dkuegler
Copy link
Member

I think quite a few review comments are refactoring and require changing multiple files and then another full testing. @dkuegler If you are adding another change and doing testing, it would be great if you could also address your comments at the same time

I am not quite sure that is true... Most of them directly changed that are part of this PR...

The change I added can be seen in my fork in fix/FastSurferCC/errorcode. I do not want to mix my changes with yours though. I'd like to keep the commit history clean.
My changes do not have any overlap with yours as far as I can see.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…this should not affect behavior).

- revert the changes to recon_cc_surf_measures return value
- revert/update changes to SubjectDirectory
- add the number of failed slices as a return value to recon_cc_surf_measures_multi
- Refactor CC metrics and file path handling
- update volume measurement definitions (to cc_num_voxel and cc_volume) -- segmentation-based volume computation is now also fully replaced by (partial) voxel count (so we no longer have two volume metrics, but a voxel count and a volume metric)
- add two additional metrics for json output (voxel_volume and cc_num_failed_slices), with additional QC messages
- cleanup and variable renames for clarity
@m-reuter m-reuter merged commit 4a67181 into Deep-MI:dev Feb 24, 2026
2 checks passed
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.

4 participants