# MHD segmentation coloring

**URL:** <https://discourse.slicer.org/t/mhd-segmentation-coloring/34765>\
**Category:** Feature requests\
**Tags:** registration, segmentation, dicom, python, 3d-model\
**Created:** [March 7, 2024, 1:22pm UTC](https://discourse.slicer.org/t/mhd-segmentation-coloring/34765 "2024-03-07T13:22:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gokce\_Guven](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gokce_guven/32/66833_2.png) [@Gokce\_Guven](https://discourse.slicer.org/u/Gokce_Guven)\
**Post date:** [March 7, 2024, 1:22pm UTC](https://discourse.slicer.org/t/mhd-segmentation-coloring/34765/1 "2024-03-07T13:22:51Z")

</div>

Hi,

I have segmented body parts using totalsegmentator from dicom files. I have segmentation files as nii.gz files. I have created mhd files from dicom files without resampling. To explain what I would like to do with an example: Let’s assume I want to use clavicula\_right.nii.gz file to recolor the clavicula right bone in the corresponding mhd file. I would like to change the inside of the bone to 3000 HU value and outside of the bone to -1024 . How can I do that? Would you show me the way to do that?

Thanks in advance  
Operating system: Ubuntu 22.04  
Slicer version: 5.3.0  
Expected behavior: Recolor specific region in mhd using nii.gz segmentations  
Actual behavior: none

---

<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:** [March 7, 2024, 1:44pm UTC](https://discourse.slicer.org/t/mhd-segmentation-coloring/34765/2 "2024-03-07T13:44:15Z")

</div>

It sounds like you could use the ColorizeVolume module. It creates an rgba volume for you and you can toggle the visibility of individual segments.

[https://github.com/Slicer/VTK/pull/43#issuecomment-1752104540](https://github.com/Slicer/VTK/pull/43#issuecomment-1752104540)

[https://github.com/Slicer/VTK/pull/43](https://github.com/Slicer/VTK/pull/43)

[https://discourse.slicer.org/t/new-colorize-volume-module/32254](https://discourse.slicer.org/t/new-colorize-volume-module/32254)

---

<div class="post-metadata">

**Author:** ![Gokce\_Guven](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gokce_guven/32/66833_2.png) [@Gokce\_Guven](https://discourse.slicer.org/u/Gokce_Guven)\
**Post date:** [March 7, 2024, 2:15pm UTC](https://discourse.slicer.org/t/mhd-segmentation-coloring/34765/4 "2024-03-07T14:15:16Z")

</div>

Hi Steve,  
thanks a lot for the fast response. I would like to use HU values as coloring, not want to use RGBA values. I will ask the same question in the links you have mentioned. Do you have any suggestion for the HU value change for segmentations?

Thanks in advance

---

<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:** [March 7, 2024, 2:27pm UTC](https://discourse.slicer.org/t/mhd-segmentation-coloring/34765/5 "2024-03-07T14:27:58Z")

</div>

> [@Gokce\_Guven](#):
>
> HU values as coloring

Maybe you can explain what you mean here. It still sounds a lot like ColorizeVolume to me. Maybe you also want to try the Mask effect i the Segment Editor.

---

<div class="post-metadata">

**Author:** ![Gokce\_Guven](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gokce_guven/32/66833_2.png) [@Gokce\_Guven](https://discourse.slicer.org/u/Gokce_Guven)\
**Post date:** [March 7, 2024, 3:49pm UTC](https://discourse.slicer.org/t/mhd-segmentation-coloring/34765/6 "2024-03-07T15:49:40Z")

</div>

I believe the issue may be related to the mask effect. Currently, I’m working with an MHD file alongside its corresponding segmentation file in NII.GZ format. My objective is to preserve the HU values (pixel values) within the MHD file for the regions delineated by the bone segmentation, while setting the values outside of this segmentation to approximate air, which is around -1024 HU for pixels. I’m seeking assistance to accomplish this using the SimpleITK and Python libraries.

Any guidance on this matter would be greatly appreciated. Thank you in advance for your help.

---

<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:** [March 7, 2024, 6:49pm UTC](https://discourse.slicer.org/t/mhd-segmentation-coloring/34765/7 "2024-03-07T18:49:49Z")

</div>

This example shows how to get the coordinates in the CT for all voxels of a given label value.

[https://slicer.readthedocs.io/en/latest/developer\_guide/script\_repository.html#get-the-values-of-all-voxels-for-a-label-value](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#get-the-values-of-all-voxels-for-a-label-value)

Between this operation and regular numpy array assignments you should have no problem emulating the mask operation. There are other script examples showing how to do these operations.
