# Assign a CT intensity value within a segment

**URL:** <https://discourse.slicer.org/t/assign-a-ct-intensity-value-within-a-segment/7066>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [June 6, 2019, 8:59pm UTC](https://discourse.slicer.org/t/assign-a-ct-intensity-value-within-a-segment/7066 "2019-06-06T20:59:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmalexander](https://avatars.discourse-cdn.com/v4/letter/k/bc79bd/32.png) [@kmalexander](https://discourse.slicer.org/u/kmalexander)\
**Post date:** [June 6, 2019, 8:59pm UTC](https://discourse.slicer.org/t/assign-a-ct-intensity-value-within-a-segment/7066/1 "2019-06-06T20:59:08Z")

</div>

Hi -

I’m looking to assign an intensity value to a CT image for every voxel within a segment, and the voxels outside that segment should stay the same. I imagine there is a filter for this, but there are so many to choose! Anyone able to point me in the right direction?

Thanks,  
Kevin

---

<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:** [June 6, 2019, 9:17pm UTC](https://discourse.slicer.org/t/assign-a-ct-intensity-value-within-a-segment/7066/2 "2019-06-06T21:17:16Z")

</div>

Hi -

A direct way to do this is to use numpy. [This example](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_the_values_of_all_voxels_for_a_label_value) shows how to get the coordinates of all voxels corresponding to a particular label value and [this example](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Modify_voxels_in_a_volume) shows how to modify the values. You’d just need to export the segmentation as a labelmap to use these.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [June 7, 2019, 5:51pm UTC](https://discourse.slicer.org/t/assign-a-ct-intensity-value-within-a-segment/7066/3 "2019-06-07T17:51:33Z")

</div>

Hi Kevin,

The Mask volume effect in Segment Editor is just for this. You’ll need to install the SegmentEditorExtraEffects extension to have that.

I just tested it in 4.10.2, and it does not work.

> **Summary**
>
> I’m getting this error:
> 
> ```
> Traceback (most recent call last):
> File "C:/Users/pinter/AppData/Roaming/NA-MIC/Extensions-28257/SegmentEditorExtraEffects/lib/Slicer-4.10/qt-scripted-modules/SegmentEditorMaskVolumeLib/SegmentEditorEffect.py", line 347, in onApply
> self.maskVolumeWithSegment(segmentationNode, segmentID, operationMode, fillValues, inputVolume, outputVolume)
> TypeError: maskVolumeWithSegment() takes at least 7 arguments (6 given)
> 
> ```

There are even more errors in the nightly. @lassoan I see that you have worked on this effect, could you look at this? Maybe it’s something trivial.

@kmalexander please stand by. Thanks!

---

<div class="post-metadata">

**Author:** ![kmalexander](https://avatars.discourse-cdn.com/v4/letter/k/bc79bd/32.png) [@kmalexander](https://discourse.slicer.org/u/kmalexander)\
**Post date:** [June 7, 2019, 5:52pm UTC](https://discourse.slicer.org/t/assign-a-ct-intensity-value-within-a-segment/7066/4 "2019-06-07T17:52:35Z")

</div>

In an older version, it works well. Nightly wasn’t working - as you reported.

Thanks for the advice!

Kevin

---

<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:** [June 7, 2019, 6:29pm UTC](https://discourse.slicer.org/t/assign-a-ct-intensity-value-within-a-segment/7066/5 "2019-06-07T18:29:13Z")

</div>

Sorry, I broke this yesterday when added a new effect (Split volume). I’ve fixed the issues now, all effects in SegmentEditorExtraEffects work in both Slicer-4.10 and Slicer-4.11 in releases downloaded tomorrow or later.

---

<div class="post-metadata">

**Author:** ![kmalexander](https://avatars.discourse-cdn.com/v4/letter/k/bc79bd/32.png) [@kmalexander](https://discourse.slicer.org/u/kmalexander)\
**Post date:** [June 19, 2019, 2:53pm UTC](https://discourse.slicer.org/t/assign-a-ct-intensity-value-within-a-segment/7066/6 "2019-06-19T14:53:45Z")

</div>

Awesome - thanks, Andras!
