Skip to content

ENH: Support writing displacement field transforms with write_transform - #930

Merged
cookpa merged 2 commits into
mainfrom
write_transforms
Oct 21, 2026
Merged

cookpa merged 2 commits into
mainfrom
write_transforms

Conversation

@cookpa

@cookpa cookpa commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

write_transform previously rejected displacement-field transforms at the native binding. This change supports saving them directly as .nii/.nii.gz images or as single-component composite transforms in .h5/.hdf5 files.

ENH: Deprecate transform_to_displacement_field "ref" argument

  • Make transform_to_displacement_field’s ref argument optional, using the stored field’s geometry and region by default.
  • Deprecate explicit references while preserving their existing behavior.

I don't understand the point of 'ref'. It doesn't resample the deformation field if given a ref of a different shape or orientation. It also doesn't do any bounds checking. Seems like it should just use the transform's own metadata, ref is only correct if it's the same.

Other changes:

  • Reject NIfTI output for affine and composite transforms with a clear error.
  • Document supported formats and the composite representation used for displacement-field HDF5 output. Validation: passing 2D/3D tests cover affine round trips through TXT, MAT, and HDF5; displacement-field round trips through NIfTI and HDF5; and mixed affine/displacement composite HDF5 round trips. Tests check point mappings, field values and geometry, and compatibility with explicit references.

Fixes #929.

write_transform previously rejected displacement-field transforms at the native binding. This change supports saving them directly as .nii/.nii.gz images or as single-component composite transforms in .h5/.hdf5 files.

ENH: Deprecate write_transform "ref" argument

- Make transform_to_displacement_field’s ref argument optional, using the stored field’s geometry and region by default.
- Deprecate explicit references while preserving their existing behavior.

I don't understand the point of 'ref'. It doesn't resample the deformation field if given a ref of a different shape or orientation. It also doesn't do any bounds checking. Seems like it should just use the transform's own metadata, ref is only correct if it's the same.

Other changes:

- Reject NIfTI output for affine and composite transforms with a clear error.
- Document supported formats and the composite representation used for displacement-field HDF5 output.
Validation: passing 2D/3D tests cover affine round trips through TXT, MAT, and HDF5; displacement-field round trips through NIfTI and HDF5; and mixed affine/displacement composite HDF5 round trips. Tests check point mappings, field values and geometry, and compatibility with explicit references.

Fixes #929.
Not sure why that was imported instead of just warnings
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 77.56% (+0.05%) from 77.511% — write_transforms into main

@cookpa cookpa changed the title ENH: Support writing displacement field transforms with write_transfomr ENH: Support writing displacement field transforms with write_transform Oct 20, 2026
@cookpa
cookpa merged commit 61a8f2a into main Oct 21, 2026
2 checks passed
@cookpa
cookpa deleted the write_transforms branch October 21, 2026 15:46
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.

Saving AntsTransformDF2 fails

2 participants