Skip to content

Ignore MGH geometry when goodRASflag is negative - #92

Merged
jnolan14 merged 1 commit into
freesurfer:masterfrom
inhuszar:fix/mgh-ras-good-signed
Nov 12, 2026
Merged

jnolan14 merged 1 commit into
freesurfer:masterfrom
inhuszar:fix/mgh-ras-good-signed

Conversation

@inhuszar

Copy link
Copy Markdown
Contributor

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.

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>
@jnolan14
jnolan14 merged commit c5687c4 into freesurfer:master Nov 12, 2026
12 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants