# Subtracting two dicom images

**URL:** <https://discourse.slicer.org/t/subtracting-two-dicom-images/8682>\
**Category:** Support\
**Created:** [October 5, 2019, 12:32pm UTC](https://discourse.slicer.org/t/subtracting-two-dicom-images/8682 "2019-10-05T12:32:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![prencekhan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/prencekhan/32/4879_2.png) [@prencekhan](https://discourse.slicer.org/u/prencekhan)\
**Post date:** [October 5, 2019, 12:32pm UTC](https://discourse.slicer.org/t/subtracting-two-dicom-images/8682/1 "2019-10-05T12:32:19Z")

</div>

Operating system: Windows  
Slicer version: 4.10.2  
Expected behavior: Subtract two DICOM images  
Actual behavior:

I just started using the 3D Slicer. I want to ask if I can subtract two DICOM images from each other using a user-defined equation. Specifically, to subtract the CT number (Hounsfield unit) If yes what and where should I start?

Can you help me, please?

---

<div class="post-metadata">

**Author:** ![Amine](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/amine/32/4844_2.png) [@Amine](https://discourse.slicer.org/u/Amine)\
**Post date:** [October 5, 2019, 2:06pm UTC](https://discourse.slicer.org/t/subtracting-two-dicom-images/8682/2 "2019-10-05T14:06:45Z")

</div>

Hi, you can do this via the Subtract Image filter ( Module list\>All modules\> Simple Filters\> SubtractImageFilter), there is also an AddImageFilter, MultiplyImageFilter , DivideImageFilter(and DivideFloor)

---

<div class="post-metadata">

**Author:** ![prencekhan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/prencekhan/32/4879_2.png) [@prencekhan](https://discourse.slicer.org/u/prencekhan)\
**Post date:** [October 11, 2019, 9:06am UTC](https://discourse.slicer.org/t/subtracting-two-dicom-images/8682/3 "2019-10-11T09:06:32Z")

</div>

Thank you very much Amine Azami.

But still it does not work with my case because I need to use a formula in subtracting not a simple case of subtraction like A-B. What I want is to subtract Ax-Bx where A and B are the HU values and x is a constant value. Hope you can help me again. Thank you

---

<div class="post-metadata">

**Author:** ![prencekhan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/prencekhan/32/4879_2.png) [@prencekhan](https://discourse.slicer.org/u/prencekhan)\
**Post date:** [October 11, 2019, 9:21am UTC](https://discourse.slicer.org/t/subtracting-two-dicom-images/8682/4 "2019-10-11T09:21:39Z")

</div>

Hi Amine Azami,

Can you help me with how can I subtract two Dicom images, specifically to subtract their HU values or CT number? But before subtracting, I need to multiply constant value to the HU value of each image. For image 1 I need to multiply constant x while for image 2 I need to multiply constant y.

Thank you very much.

---

<div class="post-metadata">

**Author:** ![Hamburgerfinger](https://avatars.discourse-cdn.com/v4/letter/h/eb9ed0/32.png) [@Hamburgerfinger](https://discourse.slicer.org/u/Hamburgerfinger)\
**Post date:** [October 11, 2019, 10:36am UTC](https://discourse.slicer.org/t/subtracting-two-dicom-images/8682/5 "2019-10-11T10:36:50Z")

</div>

In the itk Simple Filters module, you could use the ShiftScaleImage filter on each of your images, and the scale factor would be x or y in your case, and shift would be zero. (This multiplies all voxels by constant value). Then you can use the subtract image  
filter with the output images.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 11, 2019, 11:23am UTC](https://discourse.slicer.org/t/subtracting-two-dicom-images/8682/6 "2019-10-11T11:23:34Z")

</div>

You can combine volumes with arbitrary mathematical formula using numpy. See for example this post: [Is it possible to view more than two image volumes at the same time in slice viewers?](https://discourse.slicer.org/t/is-it-possible-to-view-more-than-two-image-volumes-at-the-same-time-in-slice-viewers/8738/2)

---

<div class="post-metadata">

**Author:** ![prencekhan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/prencekhan/32/4879_2.png) [@prencekhan](https://discourse.slicer.org/u/prencekhan)\
**Post date:** [October 11, 2019, 12:04pm UTC](https://discourse.slicer.org/t/subtracting-two-dicom-images/8682/7 "2019-10-11T12:04:24Z")

</div>

Hi!

Thank you very much for your help. I will reply to you as soon as I can execute it.

Until next time. Thanks again.
