Repository navigation
Ignore MGH geometry when goodRASflag is negative - #92
Merged
Merged
Conversation
MGHArrayIO.load read the goodRASflag as an unsigned short and trusted the stored voxel sizes, direction cosines and centre whenever it was non-zero. The flag is a signed short, and FreeSurfer writes -1 when the geometry is not valid, so surfa read such files with the stored geometry while FreeSurfer did not. FreeSurfer's mghRead (utils/mriio.cpp, v8.2.0) reads the geometry only if the flag is > 0. Otherwise it keeps the default 1 mm voxels and sets coronal (LIA) direction cosines with c_ras = 0. mghWrite always stores the geometry and writes the flag as 1 or -1. surfa now reads the flag as a signed short and uses the stored geometry only when it is > 0, which matches mghRead for -1, 0 and 1. Saving is unchanged: surfa writes flag 1 with the geometry it holds, so a loaded file keeps that geometry on a round trip. The new test builds files with flags -1, 0 and 1 that store 0.5 x 0.5 x 2 mm voxels. It checks voxel sizes, orientation and vox2ras against values from FreeSurfer's rule, checks a save/load round trip, and compares with `mri_info --res` and `--vox2ras` when $FREESURFER_HOME/bin/mri_info exists. Against mri_info 8.2.0 all cases agree. Before this change the flag -1 case reported 0.5 x 0.5 x 2 mm LSP, where mri_info gives 1 mm LIA. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
MGHArrayIO.load read the goodRASflag as an unsigned short and trusted the stored voxel sizes, direction cosines and centre whenever it was non-zero. The flag is a signed short, and FreeSurfer writes -1 when the geometry is not valid, so surfa read such files with the stored geometry while FreeSurfer did not.
FreeSurfer's mghRead (utils/mriio.cpp, v8.2.0) reads the geometry only if the flag is > 0. Otherwise it keeps the default 1 mm voxels and sets coronal (LIA) direction cosines with c_ras = 0. mghWrite always stores the geometry and writes the flag as 1 or -1. surfa now reads the flag as a signed short and uses the stored geometry only when it is > 0, which matches mghRead for -1, 0 and 1. Saving is unchanged: surfa writes flag 1 with the geometry it holds, so a loaded file keeps that geometry on a round trip.
The new test builds files with flags -1, 0 and 1 that store 0.5 x 0.5 x 2 mm voxels. It checks voxel sizes, orientation and vox2ras against values from FreeSurfer's rule, checks a save/load round trip, and compares with
mri_info --resand--vox2raswhen $FREESURFER_HOME/bin/mri_info exists. Against mri_info 8.2.0 all cases agree. Before this change the flag -1 case reported 0.5 x 0.5 x 2 mm LSP, where mri_info gives 1 mm LIA.