Fix ITK displacement field metadata for EasyReg and SynthMorph - #1345
Open
Mojackhak wants to merge 1 commit into
Open
Fix ITK displacement field metadata for EasyReg and SynthMorph#1345Mojackhak wants to merge 1 commit into
Mojackhak wants to merge 1 commit into
Conversation
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.
Summary
Fix ITK displacement-field metadata written during EasyReg and SynthMorph FreeSurfer-to-ITK h5 conversion.
This adds a shared helper for deriving ITK fixed parameters from the actual NIfTI displacement-field grid, and uses it in both EasyReg and SynthMorph conversion paths. EasyReg also keeps the
load_untouch_niihandling needed for affected oblique fields.Background
EasyReg and SynthMorph produce FreeSurfer-style displacement fields that Lead-DBS converts to ITK/Slicer-compatible
.h5transforms. During this conversion, the h5TransformFixedParametersmust describe the physical grid on which the displacement vectors live: image size, origin, spacing, and direction matrix.The previous implementation built these fixed parameters inline in both EasyReg and SynthMorph. The direction part was assembled from NIfTI affine rows and voxel sizes.
Problem
The old direction-matrix construction is correct for simple cases such as isotropic grids or axis-aligned grids, but can be wrong when the displacement field reference grid is both anisotropic and oblique.
Lead-DBS usually reduces this risk by reslicing the pre-op anchor to an isotropic
0.7^3 mmgrid, but this is not guaranteed. Two relevant cases are:ea_autocoordskips the anchor reslice step. If post-op CT is added later, the existing preprocessed anchor can remain on its native anisotropic oblique grid.ea_resliceanatonly resamples when at least one voxel dimension is larger than 0.7 mm. High-resolution anisotropic anchors, for example0.5 x 0.5 x 0.6 mm, are therefore not resampled to0.7^3 mm.For anisotropic oblique grids, normalizing affine rows by one spacing component per row does not produce the ITK direction matrix. The direction should be derived from voxel-axis columns, normalized by the corresponding spacing, and converted from RAS to LPS. If the wrong direction is written into the h5 transform, ITK/Slicer/ANTs can interpret the displacement field on the wrong physical grid, causing mm-scale mismatch between normalized anatomy, CT artifacts, and reconstructed electrode coordinates.
In EasyReg, affected fields may also fail earlier because
load_niirejects non-orthogonal or sheared NIfTI affines. These displacement-field files should be read without applying affine reorientation, while preserving standard NIfTIscl_slope/scl_interscaling before displacement values are used.Changes
ea_field_ref2itk(reference_image)to construct the 18-value ITK displacement-field fixed-parameter vector from a NIfTI grid:TransformFixedParametersconstruction in:load_untouch_niifor FreeSurfer displacement fields and preserve standard NIfTIscl_slope/scl_interscaling before computingfield - voxel_mm.Validation
Local validation performed before opening this draft: