# Negation after mask operation

**URL:** https://discourse.itk.org/t/negation-after-mask-operation/2884
**Category:** Uncategorized
**Created:** [March 31, 2020, 1:47pm UTC](https://discourse.itk.org/t/negation-after-mask-operation/2884 "2020-03-31T13:47:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.itk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.itk.org/u/flaviu2)
#### Post date: [March 31, 2020, 1:47pm UTC](https://discourse.itk.org/t/negation-after-mask-operation/2884/1 "2020-03-31T13:47:11Z")

</div>

I have loaded a CBCT into sitk::Image. And I ran:

```
sitk::Image imgTemp(imgOrg);
sitk::Image threshold = sitk::BinaryThreshold(imgTemp, 2000, 3600); // let only teeth (tough bones)
sitk::MaskImageFilter mask;

```

and I see the teeth only (or tough bones):

```
	imgOut = mask.Execute(imgTemp, threshold);

```

Now I intend to let everything but teeth. For that, I tried:

```
sitk::Image imgMask = mask.Execute(imgTemp, threshold);
imgOut = sitk::NotEqual(imgTemp, imgMask);

```

I see only a diffuse cube, Then I tried

```
sitk::Image imgMask = mask.Execute(imgTemp, threshold);
imgOut = sitk::Not(imgMask);

```

The same diffuse cube. What filter should I choose in order to let everything but teeth from CBCT ? I appreciate any hint/help !

Regards,  
Flaviu.

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [March 31, 2020, 2:33pm UTC](https://discourse.itk.org/t/negation-after-mask-operation/2884/2 "2020-03-31T14:33:22Z")

</div>

The filter you are looking for is [MaskNegatedImageFilter](https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1MaskNegatedImageFilter.html):

```auto
sitk::sitk.MaskNegated(imgTemp, threshold)

```

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.itk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.itk.org/u/flaviu2)
#### Post date: [March 31, 2020, 3:33pm UTC](https://discourse.itk.org/t/negation-after-mask-operation/2884/3 "2020-03-31T15:33:01Z")

</div>

Thank you. I have tried:

```
sitk::MaskNegatedImageFilter mask;
sitk::Image imgMask = mask.Execute(imgTemp, threshold);

```

I got:

`sitk::ERROR: Failure to convert SimpleITK image of dimension: 3 and pixel type: "8-bit unsigned integer" to ITK image of dimension: 3 and pixel type: "16-bit signed integer"!`

Also, I’ve tried:

```
sitk::MaskNegatedImageFilter mask;
sitk::Image imgMask = mask.Execute(imgTemp, sitk::Cast(threshold, imgTemp.GetPixelID()));

```

with the same error. Seem to be conversion error ? Or what ?

---

<div class="post-metadata">

### Author: ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)
#### Post date: [March 31, 2020, 3:36pm UTC](https://discourse.itk.org/t/negation-after-mask-operation/2884/4 "2020-03-31T15:36:41Z")

</div>

You diffuse cube might be all right. The values in that image are only 1’s and 0’s. When put in a volume renderer, it might not display well. You could try multiplying the values by 255 to get intensities better suited for volume rendering.

---

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.itk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.itk.org/u/flaviu2)
#### Post date: [April 2, 2020, 10:40am UTC](https://discourse.itk.org/t/negation-after-mask-operation/2884/6 "2020-04-02T10:40:03Z")

</div>

Thank you Dave, I’ve learned something here !
