# thresholding a mask

**URL:** <https://discourse.itk.org/t/thresholding-a-mask/1270>\
**Category:** Beginner Questions\
**Created:** [September 11, 2018, 4:32pm UTC](https://discourse.itk.org/t/thresholding-a-mask/1270 "2018-09-11T16:32:57Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [September 11, 2018, 5:52pm UTC](https://discourse.itk.org/t/thresholding-a-mask/1270/3 "2018-09-11T17:52:21Z")

</div>

There are not a shortage of ways to do this in ITK.

A new option with ITKv5 is to use the [BinaryGeneratorImageFilter](https://itk.org/Doxygen/html/classitk_1_1BinaryGeneratorImageFilter.html) to us a white a little lambda function to place run inside a filter:

> [@New Functor Filter with lambda support](https://discourse.itk.org/t/new-functor-filter-with-lambda-support/899):
>
> This is in regards to the following topic: [http://review.source.kitware.com/#/c/23352/](http://review.source.kitware.com/#/c/23352/) This patch introduces the UnaryGeneratorImageFilter BinaryGeneratorImageFilters, as replacements for the UnaryFunctorImageFilter and the BinaryFunctorImageFilters. The two big advantages are: Support for C++ lambda’s Removed class’s template parameter for functor, which enables reuse of a parent class. These new classes enable the setting for the functor with a “SetFunctor” method, where the type of functo…

I haven’t compiled this code, but it should be something like this:

```auto
using FilterType = itk::BinaryGeneratorImageFilter<InputImageType, MaskImageType OutputImageType>;
auto filter = FilterType::New();
filter->SetFunctor([](const InputPixelType &p1, const MaskPixelType &mask)->OutputPixelType
 { return mask!=1 || p1 > threshold; });

```

---

_[View the full topic](https://discourse.itk.org/t/thresholding-a-mask/1270)._
