I have a Python script which reads two DICOM images. I want to subtract one image from the other, and then divide the resulting difference by a scalar. In other words:
output_image = (input_image2 - input_image1) / some_float
I am trying to use vtkImageMathematics to accomplish this, but I am running in to problems.
First, some cells in input_image1 contain values that are larger than input_image2. When I use vtkImageMathematics.SetOperationToSubtract(), the values of these cells in the output_image appears to have overflowed the maximum allowable value the cell’s data type. I think the cell data type must be unsigned short, because, for example, 30 - 40 results in 65525. Is there a way to control the behavior of vtkImageMathematics.SetOperationToSubtract() such that negative values become 0?
Second, how to I apply another arithmetic operation to the output_image?
Here is the subtraction:
imageMath = vtk.vtkImageMathematics()
How do I apply division by a scalar? the vtkImageMathematics object doesn’t seem to operate on itself, it seems to require an input from some other object. Also, there is no “SetOperationToDivisionByK” or anything similar. Here is what I unsuccessfully tried:
K = -0.89 # for example
Thanks in advance for any feedback.