[ITK-users] Python SimpleITK DivideReal always returns double image

Addison Elliott <[email protected]> Tue, 10 Oct 2017 22:21:51 -0500
Newsgroups gmane.comp.lib.itk.user
Message-ID <CAM=S0SB96o0=VTJV0WwfQrY9GR_8O1N2TzHPer+Tr7PN+vSLcg@mail.gmail.com>
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

The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there!
________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users