# Issues with the deprecation of vtkImageThreshold

**URL:** https://discourse.vtk.org/t/issues-with-the-deprecation-of-vtkimagethreshold/16298
**Category:** Development
**Created:** [February 22, 2026, 5:11am UTC](https://discourse.vtk.org/t/issues-with-the-deprecation-of-vtkimagethreshold/16298 "2026-02-22T05:11:13Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [February 22, 2026, 5:11am UTC](https://discourse.vtk.org/t/issues-with-the-deprecation-of-vtkimagethreshold/16298/1 "2026-02-22T05:11:13Z")

</div>

The first issue is that `vtkImageBinaryThreshold` does not seem to be wrapped in Python. I would expect it to be in `vtkmodules.vtkImagingCore` like the deprecated `vtkImageThreshold`.

The second issue relates to HybridMedianComparision.cxx. See the current code with the image here [HybridMedianComparison](https://examples.vtk.org/site/Cxx/ImageProcessing/HybridMedianComparison/).

If we use `vtkImageBinaryThreshold` we get this image where there seems to be no noise:

 ![Using_vtkImageBinaryThreshold.PNG](https://discourse.vtk.org/uploads/default/original/2X/6/66ee517829b74d1c89d35731f1a00274d760788a.jpeg)

Here is the code I used:  
[HybridMedianComparison.cxx](https://discourse.vtk.org/uploads/short-url/ez8L8Axl0k0yXVI6xmhNMGzMd59.cxx) (8.1 KB)

I don’t know what I am missing here. Line 27, if uncommented, uses `vtkImageThreshold.h` instead of `vtkImageBinaryThreshold`.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [February 23, 2026, 2:20am UTC](https://discourse.vtk.org/t/issues-with-the-deprecation-of-vtkimagethreshold/16298/2 "2026-02-23T02:20:40Z")

</div>

`vtkImageBinaryThreshold` was added after 9.6, so it will first show up in (non-pre-release) 9.7 wheels.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [February 23, 2026, 8:47am UTC](https://discourse.vtk.org/t/issues-with-the-deprecation-of-vtkimagethreshold/16298/3 "2026-02-23T08:47:54Z")

</div>

> [@amaclean](#):
>
> The first issue is that `vtkImageBinaryThreshold` does not seem to be wrapped in Python. I would expect it to be in `vtkmodules.vtkImagingCore` like the deprecated `vtkImageThreshold`.

It definitely should, check the weekly wheel when its available.

Regarding the usage, I defer to Mathurin 🙂

---

<div class="post-metadata">

### Author: ![MathurinLemarie](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mathurinlemarie/32/10532_2.png) [@MathurinLemarie](https://discourse.vtk.org/u/MathurinLemarie)
#### Post date: [February 23, 2026, 9:57am UTC](https://discourse.vtk.org/t/issues-with-the-deprecation-of-vtkimagethreshold/16298/4 "2026-02-23T09:57:25Z")

</div>

Hello @amaclean ,

The `SetThresholdFunction` method call is missing in the script. This new attribute is an enum value. In this case, you need to call `imageThershold→SetThresholdFunction(vtkImageBinaryThreshold::THRESHOLD_UPPER);`. please note that its default value is `vtkImageBinaryThreshold::THRESHOLD_BETWEEN`.

To follow the logic that was in place before, in the case of “threshold by lower“, the UpperThreshold has to be set, and the other way around for `THRESHOLD_UPPER`case.

Finally, to comply with the VTK logic, the ReplaceIn and ReplaceOut now have to be set manually during the filter configuration, otherwise the InValue and OutValue will not have effect on the filter output. You can call `ReplaceInOn()` and `ReplaceOutOn()` on all filter configuration if you are using InValue and OutValue.

I tested locally by adding these lines and it works on my side.

Please let me know if you have any further questions.

Regards

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [February 23, 2026, 10:29pm UTC](https://discourse.vtk.org/t/issues-with-the-deprecation-of-vtkimagethreshold/16298/5 "2026-02-23T22:29:23Z")

</div>

It is wrapped for Python it is just that PyCharm is flagging it as `Cannot find reference 'vtkImageBinaryThreshold' in 'vtkmodules.vtkImagingCore' `, sorry my bad.

I am using the master (most recent). If you look at [vtkImageBinaryThreshold](https://vtk.org/doc/nightly/html/classvtkImageBinaryThreshold.html), all the Python tests are using `vtkImageThreshold` not `vtkImageBinaryThreshold`. There are no C++ tests. Should there be specific tests for `vtkImageBinaryThreshold`? Testing was the first place I looked in order to get ideas.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [February 23, 2026, 10:30pm UTC](https://discourse.vtk.org/t/issues-with-the-deprecation-of-vtkimagethreshold/16298/6 "2026-02-23T22:30:18Z")

</div>

Thankyou for your comments, they clarified my understanding a lot. I now have it working.

---

<div class="post-metadata">

### Author: ![MathurinLemarie](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mathurinlemarie/32/10532_2.png) [@MathurinLemarie](https://discourse.vtk.org/u/MathurinLemarie)
#### Post date: [February 24, 2026, 8:22am UTC](https://discourse.vtk.org/t/issues-with-the-deprecation-of-vtkimagethreshold/16298/7 "2026-02-24T08:22:55Z")

</div>

The documentation is not updated correctly and points to old file versions.

If you check master on [this file](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Filters/Core/Testing/Python/clipArt.py) for example, you’ll see that it is actually using `vtkImageBinaryThreshold`.

This filter is only tested in python, so there is no C++ test using it indeed.

Hope his can help.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [March 16, 2026, 3:58am UTC](https://discourse.vtk.org/t/issues-with-the-deprecation-of-vtkimagethreshold/16298/8 "2026-03-16T03:58:12Z")

</div>

Have a look at this [MR](https://gitlab.kitware.com/vtk/vtk-examples/-/merge_requests/444). I have updated the code to use `vtkImageBinaryThreshold` in the C++, Python and PythonicAPI examples.

In the case of the C++ examples, I have kept, for the moment, the deprecated `vtkImageThreshold` along with the replacement: `vtkImageBinaryThreshold` just to give people an indication of what needs to be done.

If there are no issues, I will probably merge some time tomorrow.
