Skip to content

Commit

Permalink
ENH: Make precision (--float) configurable for registration (#741)
Browse files Browse the repository at this point in the history
ENH: Add single precision to registration

Default is float21 (singleprecision=True) as before

---------

Co-authored-by: Evert de Man <e.deman@mediaire.de>
  • Loading branch information
evertdeman and Evert de Man authored Nov 25, 2024
1 parent 6945c6f commit f5db913
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ants/registration/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def registration(
multivariate_extras=None,
restrict_transformation=None,
smoothing_in_mm=False,
singleprecision=True,
**kwargs
):
"""
Expand Down Expand Up @@ -152,6 +153,10 @@ def registration(
smoothing_in_mm : boolean ; currently only impacts low dimensional registration
singleprecision : boolean
if True, use float32 for computations. This is useful for reducing memory
usage for large datasets, at the cost of precision.
kwargs : keyword args
extra arguments
Expand Down Expand Up @@ -351,6 +356,8 @@ def registration(
synits = "x".join([str(ri) for ri in reg_iterations])

inpixeltype = fixed.pixeltype
output_pixel_type = 'float' if singleprecision else 'double'

tvTypes = [
"TV[1]",
"TV[2]",
Expand Down Expand Up @@ -409,8 +416,8 @@ def registration(
# initx = invertAntsrTransform( initx )
# writeAntsrTransform( initx, tempTXfilename )
# initx = tempTXfilename
moving = moving.clone("float")
fixed = fixed.clone("float")
moving = moving.clone(output_pixel_type)
fixed = fixed.clone(output_pixel_type)
# NOTE: this may be better for general purpose applications: TBD
# moving = ants.iMath( moving.clone("float"), "Normalize" )
# fixed = ants.iMath( fixed.clone("float"), "Normalize" )
Expand Down Expand Up @@ -1349,7 +1356,7 @@ def registration(
args.append(restrict_transformationchar)

args.append("--float")
args.append("1")
args.append(str(int(singleprecision)))
args.append("--write-composite-transform")
args.append(write_composite_transform * 1)
if verbose:
Expand Down

0 comments on commit f5db913

Please sign in to comment.