Scalar subtraction

Hello. I am subtracting two images to track changes in contrast between them. I am interested in both the positive and negative change.

However I can’t seem to get any values below 0 after subtraction. Is there something I can do to get around this issue?

If you are using the Subtract Scalar Volumes module, then the issue is that the module sets the output type to match the type of the first input volume. If your first input has a unsigned type, then the output type will also be unsigned, and all negative values will be clamped to 0. The simplest fix is to use the Cast Scalar Volumes module to change the input type to something with sufficient range (signed int or float are typically a good choice, but you need to know your data).

Alternatively you could write a script in Python to do this for you, there are several relevant examples in the repository about doing math on image voxels:

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository

1 Like

Thank you! I ran the Cast Scalar Volumes to change input to int, after that I got the results that I had expected :).

1 Like