thresholding a mask

Hello!

I have a mask corresponding to an image patch and I would like to further modify the mask to exclude from the mask all voxels that correspond to image voxels outside a range of intensities. What is the best way to accomplish this?

Thanks!
Tia

You can use iterators to go through the input image and mask, and set appropriate values to pixels in the output image. An example which uses iterators.

If you don’t want to do that, you can threshold your input again, then do some operations on the two masks (multiply or subtract) to get the desired output. An example which uses a mask. A list of intensity-based filters.

1 Like

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

A new option with ITKv5 is to use the BinaryGeneratorImageFilter to us a white a little lambda function to place run inside a filter:

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

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; });
1 Like