diff --git a/modules/imgproc/src/thresh.cpp b/modules/imgproc/src/thresh.cpp index 2e6690e55b..c3799d83a1 100644 --- a/modules/imgproc/src/thresh.cpp +++ b/modules/imgproc/src/thresh.cpp @@ -774,16 +774,14 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type ) } setIppErrorStatus(); break; -#if 0 // details: https://github.com/opencv/opencv/pull/16085 case THRESH_TOZERO: - if (0 <= CV_INSTRUMENT_FUN_IPP(ippiThreshold_LTVal_32f_C1R, src, (int)src_step*sizeof(src[0]), dst, (int)dst_step*sizeof(dst[0]), sz, thresh + FLT_EPSILON, 0)) + if (0 <= CV_INSTRUMENT_FUN_IPP(ippiThreshold_LTVal_32f_C1R, src, (int)src_step*sizeof(src[0]), dst, (int)dst_step*sizeof(dst[0]), sz, nextafterf(thresh, std::numeric_limits::infinity()), 0)) { CV_IMPL_ADD(CV_IMPL_IPP); return; } setIppErrorStatus(); break; -#endif case THRESH_TOZERO_INV: if (0 <= CV_INSTRUMENT_FUN_IPP(ippiThreshold_GTVal_32f_C1R, src, (int)src_step*sizeof(src[0]), dst, (int)dst_step*sizeof(dst[0]), sz, thresh, 0)) { diff --git a/modules/imgproc/test/test_thresh.cpp b/modules/imgproc/test/test_thresh.cpp index a8e961675d..f51afa12bd 100644 --- a/modules/imgproc/test/test_thresh.cpp +++ b/modules/imgproc/test/test_thresh.cpp @@ -443,4 +443,34 @@ TEST(Imgproc_Threshold, regression_THRESH_TOZERO_IPP_16085) EXPECT_EQ(0, cv::norm(result, NORM_INF)); } +TEST(Imgproc_Threshold, regression_THRESH_TOZERO_IPP_21258) +{ + Size sz(16, 16); + float val = nextafterf(16.0f, 0.0f); // 0x417fffff, all bits in mantissa are 1 + Mat input(sz, CV_32F, Scalar::all(val)); + Mat result; + cv::threshold(input, result, val, 0.0, THRESH_TOZERO); + EXPECT_EQ(0, cv::norm(result, NORM_INF)); +} + +TEST(Imgproc_Threshold, regression_THRESH_TOZERO_IPP_21258_Min) +{ + Size sz(16, 16); + float min_val = -std::numeric_limits::max(); + Mat input(sz, CV_32F, Scalar::all(min_val)); + Mat result; + cv::threshold(input, result, min_val, 0.0, THRESH_TOZERO); + EXPECT_EQ(0, cv::norm(result, NORM_INF)); +} + +TEST(Imgproc_Threshold, regression_THRESH_TOZERO_IPP_21258_Max) +{ + Size sz(16, 16); + float max_val = std::numeric_limits::max(); + Mat input(sz, CV_32F, Scalar::all(max_val)); + Mat result; + cv::threshold(input, result, max_val, 0.0, THRESH_TOZERO); + EXPECT_EQ(0, cv::norm(result, NORM_INF)); +} + }} // namespace