Skip to content

Conversation

@dkuegler
Copy link
Member

This PR is a work in progress PR to address the issue of MGH Headers using Pxyz_c (which is not the center of the image, but offset by half a voxel).
This is also a bug in mri_convert as documented in freesurfer/freesurfer#1358

Todo:

  • test whether the current solution fixes all issues with re-orientation and RAS consistency of images

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 work-in-progress PR addresses off-by-one errors in MGH header handling related to the Pxyz_c calculation, which represents the center of the image but is offset by half a voxel. The fix introduces two feature flags to optionally correct the affine calculation bug in nibabel's MGHHeader.get_affine() method.

Changes:

  • Introduces two feature flags (FIX_MGH_AFFINE_CALCULATION and FIX_CENTER_NOT_CENTER) to control the fix behavior
  • Adds helper functions get_affine_from_mgh() and get_affine_from_any() to provide corrected affine calculations
  • Modifies offset calculation in map_image() to account for off-by-one errors when flipping orientation
  • Updates center calculation logic in prepare_mgh_header() with conditional fix based on feature flags

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

@dkuegler dkuegler force-pushed the fix/conform-reorient branch from b059c18 to d8b8d42 Compare January 19, 2026 19:21
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.

1 participant