added optional mask to cv::threshold#26842
Conversation
To avoid code duplication, and keep performance when no mask is used, inner implementation always propagate the const cv::Mat& mask, but they use a template<bool useMask> parameter that let the compiler optimize out unecessary tests when the mask not to be used.
if constexpr(...) requires C++17
the "readParity" is designed to handle the fact that vector operations always read 16 mask values, while data type can represent less pixels
This reverts commit a68db5a.
First fix, but the tests sometimes fail, still investigating...
…e, disabling it for now Still don't understand why unit test randomly fails
…e, disabling it for now Still don't understand why unit test randomly fails prepare mutli-channel handling
When therere were non-vectorized pixels remaining, the mask pointer was not properly reset that was a memory fault (not always triggered), and the test case only hit the case when that last pixel was greater than the threshold
not yet ready for cn>1
not yet ready for cn>1
new strategy to load masks and duplicate bytes to match src.elemSize() instead of complex byte duplication in loaded mask vector elements, use vx_lut() instead with sliding indices
now that cn>1 works, the simplest case src.type() == CV_8UC1 can be a fast path
there was an error in ocl kernel args, it wasn't even run and relied on CPU implementation
|
We need "clear" definition what values should be used as result outside of the mask. Al least, this is why P.S. If your mask is a rectangle - then you should use ROI approach instead. |
Yes, that's what I thought when I started working on the feature. |
|
@chacha21 Could you list use-cases for the PR? |
Ok. First of all, no problem to decline the PR, I won't try to force push it. Here are my two use cases : case 1
case 2
|
|
Hello @chacha21 Sorry for delay. We discussed to the PR on the Core team meeting and we are ready to merge the PR with several fixes:
The fixes are proposed to get rid of undefined behaviour for the case where mask==0 and wrap things to Python, Java, etc correctly. |
|
Please also rebase and fix merge conflicts. |
- do not overload threshold, use thresholdWithMask instead - document required dst if mask is used - do not use HAL implementation for the masked case
I am sorry I have 0 skills in Python |
added accuracy test using a rectangular ROI
- split accuracy tests for different cases (otsu/triangle/fixed) - clean up non existent HAL versions - update reference to author
Proposal for #26777
To avoid code duplication, and keep performance when no mask is used, inner implementation always propagate the const cv::Mat& mask, but they use a template parameter that let the compiler optimize out unecessary tests when the mask is not to be used.
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.