Discussion:
[ITK-users] Python SimpleITK DivideReal always returns double image
Addison Elliott
2017-10-11 03:21:51 UTC
Permalink
Hey guys,

When using Python 3.0+, the operator / utilizes __truediv__ instead of
__div__. For itk.Image, truediv uses DivideReal and div uses Divide. This
is relevant because DivideReal returns an image with double datatype and
Divide uses the datatype of the input image.

Since I am using 32-bit floats for my images, this requires me to cast to a
32-bit float each time. It would be more convenient if it mimicked the
datatype of the input image OR you could specify the desired datatype.

Here is a test case to show what I mean:

image = sitk.Image(50, 50, 50, sitk.sitkFloat32)
image2 = sitk.DivideReal(image, 4.0)
print(image) # <---- Type is float
print(image2) # <---- Type is double

image = sitk.Image(50, 50, 50, sitk.sitkFloat32)
image2 = sitk.Divide(image, 4.0)
print(image) # <---- Type is float
print(image2) # <---- Type is float

I've been using ITK for a few weeks and SimpleITK for about a week. I've
have SimpleITK built from source.

- Is this a feature/bug worthy of fixing?
- Can someone point me in the right direction as to where I should start
for fixing the issue?
- Any other tips and comments are welcome!


Addison

Loading...