For example, I want to set all pixel values of an image to 1 where the current pixel value is >1.
In numpy, this could be done in the following way:
x[x > 1] = 1
However, for Images that does not work:
# x -> SimpleITK.Image x[x > 1] = 1
results in an
IndexError: too many indices for image
But there are the
MaskNegated functions. However, they are a little bit awkward to use.
Because if I want to specify x > 1 = 1, then I would need to use the MaskNegated, which throws me an error:
sitk.MaskNegated(x, x > 1, 1)) RuntimeError: Exception thrown in SimpleITK MaskNegated: /tmp/SimpleITK/Code/Common/include/sitkProcessObject.h:354: sitk::ERROR: Failure to convert SimpleITK image of dimension: 2 and pixel type: "8-bit unsigned integer" to ITK image of dimension: 2 and pixel type: "64-bit float"!
And when using Mask, you need to use the opposite for searching:
sitk.Mask(x, sitk.Not(x > 1), 1))
Is there no other, more convenient way?