Issues with the deprecation of vtkImageThreshold

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.

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

Here is the code I used:
HybridMedianComparison.cxx (8.1 KB)

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

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

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

Regarding the usage, I defer to Mathurin :slight_smile:

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_UPPERcase.

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

1 Like

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, 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.

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

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

If you check master on this file 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.

1 Like