# Threshold scalar volume error

**URL:** <https://discourse.slicer.org/t/threshold-scalar-volume-error/4753>\
**Category:** Support\
**Created:** [November 13, 2018, 10:04pm UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753 "2018-11-13T22:04:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![kayarre](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kayarre/32/3606_2.png) [@kayarre](https://discourse.slicer.org/u/kayarre)\
**Post date:** [November 13, 2018, 10:04pm UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753/1 "2018-11-13T22:04:02Z")

</div>

I have a signed distance field that I am thresholding to a label map volume, everything below zero should be identified as the segmentation that I am interested in, however when I do this the returned mask is larger than expected.

Thresholding with **below** and **-0.01** values one can see that the data probe (arrow missing in screenshot) is on the blue edge next to pink region is segmented but the levelset background image is positive. So somehow the region is growing by a layer of voxels?

Is there something I am doing wrong, or is this a bug? the levetset is of type float.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/6/0600f10f6386c9ba35ea26dc15b60ce16b50d681.png)

---

<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:** [November 14, 2018, 5:39am UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753/2 "2018-11-14T05:39:22Z")

</div>

How did you threshold the distance field to a labelmap?  
Does the labelmap, the distance map, the segmentation master volume, and the segmentation’s internal binary labelmap representation has the same geometry (origin, spacing, axis directions)?

---

<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:** [November 14, 2018, 3:15pm UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753/3 "2018-11-14T15:15:56Z")

</div>

@kayarre to facilitate investigation it would help if you can provide a sample dataset and sequence of steps to replicate where you see the inconsistency.

---

<div class="post-metadata">

**Author:** ![kayarre](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kayarre/32/3606_2.png) [@kayarre](https://discourse.slicer.org/u/kayarre)\
**Post date:** [November 15, 2018, 12:17am UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753/4 "2018-11-15T00:17:47Z")

</div>

@lassoan threshold scalar volume, same origin, spacing and directions)

@pieper: see steps below, also give me a place to upload the image data and I will.

1. load levelset image (same origin, spacing, and directions as source image. type float)
2. threshold scalar volume
  - input volume: 1.
  - output volume: set to label map (create new)
  - Type: Below, Threshold Value: -0.01, Outside Value: 1.0
  - Apply

3. observe weird behavior described above where the label map covers positive values of the levelset

---

<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:** [November 15, 2018, 12:48am UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753/5 "2018-11-15T00:48:55Z")

</div>

I’ve tested thresholding of a distance map IN Segment Editor and it worked perfectly. Have you tried that?

Could you share a scene where you can reproduce your problem?

---

<div class="post-metadata">

**Author:** ![kayarre](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kayarre/32/3606_2.png) [@kayarre](https://discourse.slicer.org/u/kayarre)\
**Post date:** [November 15, 2018, 6:20pm UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753/6 "2018-11-15T18:20:07Z")

</div>

@lassoan Yep that works, 🤦‍♂️  
is the scene the xml file that slicer always is wanting me to save?

---

<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:** [November 15, 2018, 6:34pm UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753/7 "2018-11-15T18:34:54Z")

</div>

> [@kayarre](#):
>
> is the scene the xml file that slicer always is wanting me to save?

Yes, the .mrml file stores the scene (state of all MRML nodes).

---

<div class="post-metadata">

**Author:** ![kayarre](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kayarre/32/3606_2.png) [@kayarre](https://discourse.slicer.org/u/kayarre)\
**Post date:** [November 15, 2018, 7:03pm UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753/8 "2018-11-15T19:03:35Z")

</div>

@lassoan here is the scene  
[https://gist.github.com/kayarre/1889a1be1a1b65d5f93548eb3be77381](https://gist.github.com/kayarre/1889a1be1a1b65d5f93548eb3be77381)

---

<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:** [November 15, 2018, 7:16pm UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753/9 "2018-11-15T19:16:09Z")

</div>

The scene file does not contain any bulk data (images, etc.). To share a scene with someone, the easiest is to click on the small “giftbox” icon to create a .mrb file that saves the scene file and all data in a single file.

---

<div class="post-metadata">

**Author:** ![kayarre](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kayarre/32/3606_2.png) [@kayarre](https://discourse.slicer.org/u/kayarre)\
**Post date:** [November 15, 2018, 10:15pm UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753/10 "2018-11-15T22:15:15Z")

</div>

That is fancy!

[shared file from googel drive](https://drive.google.com/file/d/1o5lUg39ZLmI2dimYRKtwavGZgbd_30Mp/view?usp=sharing)

---

<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:** [November 16, 2018, 4:02am UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753/11 "2018-11-16T04:02:43Z")

</div>

I’ve tested “Threshold Scalar Volume” module with your data set and it works as intended.

You might have though that thresholding binarizes the image, while it is not. It changes values below/above/outside the specified range and leaves other values unchanged. You see the “band” because you’ve created a labelmap volume for storing the output, which discretizes the output to integer values.

To get a binary volume, you can do it by running thresholding twice (once with “Negate threshold” disabled, then enabled) as shown below. However, you can binarize the image much more easily by using Segment Editor’s Threshold effect or Simple Filter module’s BinaryThresholdImageFilter.

Binarizing an image using Threshold Scalar Volume effect:

**Step 1:**

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/4/b40933e59ee36caaf835c6118a6e6b8ef673dfd1.png)

**Step 2:**

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/d/dd793b102a7d9ad82e9b8f9a4fcea515e0a04440.png)

---

<div class="post-metadata">

**Author:** ![kayarre](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kayarre/32/3606_2.png) [@kayarre](https://discourse.slicer.org/u/kayarre)\
**Post date:** [November 16, 2018, 7:57pm UTC](https://discourse.slicer.org/t/threshold-scalar-volume-error/4753/12 "2018-11-16T19:57:24Z")

</div>

That makes a lot more sense. thank you.
