mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge pull request #26836 from chacha21:thresholding_compute_threshold_only
Add cv::THRESH_DRYRUN flag to get adaptive threshold values without thresholding #26836 A first proposal for #26777 Adds a `cv::THRESH_DRYRUN` flag to let cv::threshold() compute the threshold (useful for OTSU/TRIANGLE), but without actually running the thresholding. This flags is a proposal instead of a new function cv::computeThreshold() - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [X] The PR is proposed to the proper branch - [X] There is a reference to the original bug report and related work - [X] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -386,6 +386,40 @@ OCL_TEST_P(Threshold, Mat)
|
||||
}
|
||||
}
|
||||
|
||||
struct Threshold_Dryrun :
|
||||
public ImgprocTestBase
|
||||
{
|
||||
int thresholdType;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
thresholdType = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(Threshold_Dryrun, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
double maxVal = randomDouble(20.0, 127.0);
|
||||
double thresh = randomDouble(0.0, maxVal);
|
||||
|
||||
const int _thresholdType = thresholdType | THRESH_DRYRUN;
|
||||
|
||||
src_roi.copyTo(dst_roi);
|
||||
usrc_roi.copyTo(udst_roi);
|
||||
|
||||
OCL_OFF(cv::threshold(src_roi, dst_roi, thresh, maxVal, _thresholdType));
|
||||
OCL_ON(cv::threshold(usrc_roi, udst_roi, thresh, maxVal, _thresholdType));
|
||||
|
||||
OCL_EXPECT_MATS_NEAR(dst, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////// CLAHE //////////////////////////////////////////////////
|
||||
|
||||
PARAM_TEST_CASE(CLAHETest, Size, double, bool)
|
||||
@@ -483,6 +517,16 @@ OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Threshold, Combine(
|
||||
ThreshOp(THRESH_TOZERO), ThreshOp(THRESH_TOZERO_INV)),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Threshold_Dryrun, Combine(
|
||||
Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4,
|
||||
CV_16SC1, CV_16SC2, CV_16SC3, CV_16SC4,
|
||||
CV_32FC1, CV_32FC2, CV_32FC3, CV_32FC4),
|
||||
Values(0),
|
||||
Values(ThreshOp(THRESH_BINARY),
|
||||
ThreshOp(THRESH_BINARY_INV), ThreshOp(THRESH_TRUNC),
|
||||
ThreshOp(THRESH_TOZERO), ThreshOp(THRESH_TOZERO_INV)),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CLAHETest, Combine(
|
||||
Values(Size(4, 4), Size(32, 8), Size(8, 64)),
|
||||
Values(0.0, 10.0, 62.0, 300.0),
|
||||
|
||||
@@ -502,6 +502,25 @@ BIGDATA_TEST(Imgproc_Threshold, huge)
|
||||
ASSERT_EQ((uint64)nz, n / 2);
|
||||
}
|
||||
|
||||
TEST(Imgproc_Threshold, threshold_dryrun)
|
||||
{
|
||||
Size sz(16, 16);
|
||||
Mat input_original(sz, CV_8U, Scalar::all(2));
|
||||
Mat input = input_original.clone();
|
||||
std::vector<int> threshTypes = {THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV};
|
||||
std::vector<int> threshFlags = {0, THRESH_OTSU, THRESH_TRIANGLE};
|
||||
for(int threshType : threshTypes)
|
||||
{
|
||||
for(int threshFlag : threshFlags)
|
||||
{
|
||||
const int _threshType = threshType | threshFlag | THRESH_DRYRUN;
|
||||
cv::threshold(input, input, 2.0, 0.0, _threshType);
|
||||
EXPECT_MAT_NEAR(input, input_original, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_Threshold, regression_THRESH_TOZERO_IPP_16085)
|
||||
{
|
||||
Size sz(16, 16);
|
||||
|
||||
Reference in New Issue
Block a user