Skip to content

Commit 564f47d

Browse files
authored
Merge pull request #859 from ANTsX/io_clone_check
PERF: Only clone on read if needed
2 parents c4433c2 + ee008f1 commit 564f47d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ants/core/ants_image_io.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ def image_read(filename, dimension=None, pixeltype="float", reorient=False):
293293
pixeltype : string
294294
C++ datatype to be used to represent the pixels read. This datatype
295295
need not be the same as the datatype used in the file.
296-
Options: unsigned char, unsigned int, float, double
296+
Options: unsigned char, unsigned int, float, double. Use pixeltype=None
297+
to use the datatype in the file if supported. Unsupported datatypes
298+
will be converted to float.
297299
298300
reorient : boolean | string
299301
if True, the image will be reoriented to RPI if it is 3D
@@ -363,7 +365,7 @@ def image_read(filename, dimension=None, pixeltype="float", reorient=False):
363365

364366
ants_image = ants.from_pointer(itk_pointer)
365367

366-
if pixeltype is not None:
368+
if pixeltype is not None and pixeltype != ptype:
367369
ants_image = ants_image.clone(pixeltype)
368370

369371
if (reorient != False) and (ants_image.dimension == 3):

0 commit comments

Comments
 (0)