Skip to content

Commit f5db913

Browse files
evertdemanEvert de Man
and
Evert de Man
authored
ENH: Make precision (--float) configurable for registration (#741)
ENH: Add single precision to registration Default is float21 (singleprecision=True) as before --------- Co-authored-by: Evert de Man <e.deman@mediaire.de>
1 parent 6945c6f commit f5db913

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ants/registration/registration.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def registration(
4242
multivariate_extras=None,
4343
restrict_transformation=None,
4444
smoothing_in_mm=False,
45+
singleprecision=True,
4546
**kwargs
4647
):
4748
"""
@@ -152,6 +153,10 @@ def registration(
152153
153154
smoothing_in_mm : boolean ; currently only impacts low dimensional registration
154155
156+
singleprecision : boolean
157+
if True, use float32 for computations. This is useful for reducing memory
158+
usage for large datasets, at the cost of precision.
159+
155160
kwargs : keyword args
156161
extra arguments
157162
@@ -351,6 +356,8 @@ def registration(
351356
synits = "x".join([str(ri) for ri in reg_iterations])
352357

353358
inpixeltype = fixed.pixeltype
359+
output_pixel_type = 'float' if singleprecision else 'double'
360+
354361
tvTypes = [
355362
"TV[1]",
356363
"TV[2]",
@@ -409,8 +416,8 @@ def registration(
409416
# initx = invertAntsrTransform( initx )
410417
# writeAntsrTransform( initx, tempTXfilename )
411418
# initx = tempTXfilename
412-
moving = moving.clone("float")
413-
fixed = fixed.clone("float")
419+
moving = moving.clone(output_pixel_type)
420+
fixed = fixed.clone(output_pixel_type)
414421
# NOTE: this may be better for general purpose applications: TBD
415422
# moving = ants.iMath( moving.clone("float"), "Normalize" )
416423
# fixed = ants.iMath( fixed.clone("float"), "Normalize" )
@@ -1349,7 +1356,7 @@ def registration(
13491356
args.append(restrict_transformationchar)
13501357

13511358
args.append("--float")
1352-
args.append("1")
1359+
args.append(str(int(singleprecision)))
13531360
args.append("--write-composite-transform")
13541361
args.append(write_composite_transform * 1)
13551362
if verbose:

0 commit comments

Comments
 (0)