# Is there a way to perform simple mathematics on voxel values and then generate an image based on them? 

**URL:** <https://discourse.slicer.org/t/is-there-a-way-to-perform-simple-mathematics-on-voxel-values-and-then-generate-an-image-based-on-them/25479>\
**Category:** Support\
**Tags:** segmentation, dicom\
**Created:** [September 29, 2022, 5:10am UTC](https://discourse.slicer.org/t/is-there-a-way-to-perform-simple-mathematics-on-voxel-values-and-then-generate-an-image-based-on-them/25479 "2022-09-29T05:10:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mmirzaa1](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@Mmirzaa1](https://discourse.slicer.org/u/Mmirzaa1)\
**Post date:** [September 29, 2022, 5:10am UTC](https://discourse.slicer.org/t/is-there-a-way-to-perform-simple-mathematics-on-voxel-values-and-then-generate-an-image-based-on-them/25479/1 "2022-09-29T05:10:37Z")

</div>

Hello everyone!  
I was having trouble performing a task at 3Dslicer. I wanted to do some simple mathematics on the voxel values on 3d slicer ( to be exact I wanted to subtract the In-phase voxel intensity values of an abdominal MR scan from an out of phase scan (same case and no need of registration) and then divide it by in phase voxel values multiplied by 2. I would like to generate a new set of images based on the obtained values ( to be concise : (Inphase-Outphase)/inphase X 2) ).  
FYI our aim is to see if it would be possible to generate a quantification heat map of the liver.  
Thank you very much for everything

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 29, 2022, 12:27pm UTC](https://discourse.slicer.org/t/is-there-a-way-to-perform-simple-mathematics-on-voxel-values-and-then-generate-an-image-based-on-them/25479/2 "2022-09-29T12:27:38Z")

</div>

It sounds like what you are trying to do can all be done efficiently by accessing the volumes as numpy arrays.

[https://slicer.readthedocs.io/en/latest/developer\_guide/script\_repository.html#modify-voxels-in-a-volume](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#modify-voxels-in-a-volume)

---

<div class="post-metadata">

**Author:** ![Mmirzaa1](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@Mmirzaa1](https://discourse.slicer.org/u/Mmirzaa1)\
**Post date:** [November 1, 2022, 6:37pm UTC](https://discourse.slicer.org/t/is-there-a-way-to-perform-simple-mathematics-on-voxel-values-and-then-generate-an-image-based-on-them/25479/3 "2022-11-01T18:37:22Z")

</div>

Thank you very much for the suggestion

---

<div class="post-metadata">

**Author:** ![NikhilM](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@NikhilM](https://discourse.slicer.org/u/NikhilM)\
**Post date:** [January 24, 2024, 2:41am UTC](https://discourse.slicer.org/t/is-there-a-way-to-perform-simple-mathematics-on-voxel-values-and-then-generate-an-image-based-on-them/25479/4 "2024-01-24T02:41:42Z")

</div>

Hi, I’m looking to do something quite similiar on 3d slicer but not having much luck getting the Python scripts working on my data set. Did you manage to figure it out? Thanks
