Skip to content

ENH: N4 reorganization. - #62

Merged
ntustison merged 1 commit into
mainfrom
n4_interface
Sep 24, 2026
Merged

ntustison merged 1 commit into
mainfrom
n4_interface

Conversation

@ntustison

Copy link
Copy Markdown
Member

Rename N4 functions: ANTsImage interface becomes n4_bias_field_correction

Add an ANTsImage interface to ANTsTorch's differentiable N4 so it can be called like ants.n4_bias_field_correction():

antstorch.n4_bias_field_correction(image, mask, shrink_factor=4, ...)

The interface converts ANTs images to tensors on the requested device, runs the tensor engine, and returns an ANTsImage in the input geometry.

Rename the tensor engine to avoid a name clash at the antstorch level (bspline_flows is imported after utilities and would otherwise shadow the new interface):

bspline_flows.n4_bias_field_correction
    -> bspline_flows.n4_bias_field_correction_tensor

N4BiasFieldCorrection (nn.Module) and module filenames are unchanged.

  • utilities/n4_bias_field_correction.py: new ANTsImage interface
  • utilities/init.py: export n4_bias_field_correction
  • bspline_flows/{init,n4_bias_field_correction}.py: rename engine
  • benchmark/data.py, docs tutorial, bspline_scattered_data docstring: use n4_bias_field_correction_tensor
  • tools/benchmarks/compare_n4_bias_field_correction.py: call the ANTsImage interface; drop the local ants<->torch conversion helpers
  • tests: update the bspline_flows N4 tests; add tests/utilities for the interface (geometry preservation, bias return, mask mismatch)

Rename N4 functions: ANTsImage interface becomes n4_bias_field_correction

Add an ANTsImage interface to ANTsTorch's differentiable N4 so it can be
called like ants.n4_bias_field_correction():

    antstorch.n4_bias_field_correction(image, mask, shrink_factor=4, ...)

The interface converts ANTs images to tensors on the requested device,
runs the tensor engine, and returns an ANTsImage in the input geometry.

Rename the tensor engine to avoid a name clash at the antstorch level
(bspline_flows is imported after utilities and would otherwise shadow
the new interface):

    bspline_flows.n4_bias_field_correction
        -> bspline_flows.n4_bias_field_correction_tensor

N4BiasFieldCorrection (nn.Module) and module filenames are unchanged.

- utilities/n4_bias_field_correction.py: new ANTsImage interface
- utilities/__init__.py: export n4_bias_field_correction
- bspline_flows/{__init__,n4_bias_field_correction}.py: rename engine
- benchmark/data.py, docs tutorial, bspline_scattered_data docstring:
  use n4_bias_field_correction_tensor
- tools/benchmarks/compare_n4_bias_field_correction.py: call the
  ANTsImage interface; drop the local ants<->torch conversion helpers
- tests: update the bspline_flows N4 tests; add tests/utilities for the
  interface (geometry preservation, bias return, mask mismatch)
@ntustison
ntustison merged commit 1249a23 into main Sep 24, 2026
3 checks passed
@ntustison
ntustison deleted the n4_interface branch September 24, 2026 22:09
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