Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc95f27

Browse files
authored
Merge pull request #25509 from savuor:rv/hal_otsu
HAL added for Otsu threshold #25509 fixes #25393 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [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. - [x] The feature is well documented and sample code can be built with the project CMake
1 parent ce642e9 commit bc95f27

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

modules/imgproc/src/hal_replacement.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,25 @@ inline int hal_ni_threshold(const uchar* src_data, size_t src_step, uchar* dst_d
856856
#define cv_hal_threshold hal_ni_threshold
857857
//! @endcond
858858

859+
/**
860+
@brief Performs threshold filtering using threshold estimated by Otsu algorithm
861+
@param src_data Source image data
862+
@param src_step Source image step
863+
@param dst_data Destination image data
864+
@param dst_step Destination image step
865+
@param width Source image width
866+
@param height Source image height
867+
@param depth Depths of source and destination image
868+
@param maxValue Value assigned to the pixels for which the condition is satisfied
869+
@param thresholdType Thresholding type
870+
@param thresh Calculated threshold value
871+
*/
872+
inline int hal_ni_threshold_otsu(const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, int depth, double maxValue, int thresholdType, double* thresh) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
873+
874+
//! @cond IGNORED
875+
#define cv_hal_threshold_otsu hal_ni_threshold_otsu
876+
//! @endcond
877+
859878
/**
860879
@brief Calculate box filter
861880
@param src_data Source image data

modules/imgproc/src/thresh.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,10 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
15451545
ocl_threshold(_src, _dst, thresh, maxval, type), thresh)
15461546

15471547
Mat src = _src.getMat();
1548+
1549+
_dst.create( src.size(), src.type() );
1550+
Mat dst = _dst.getMat();
1551+
15481552
int automatic_thresh = (type & ~cv::THRESH_MASK);
15491553
type &= THRESH_MASK;
15501554

@@ -1553,6 +1557,10 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
15531557
{
15541558
int src_type = src.type();
15551559
CV_CheckType(src_type, src_type == CV_8UC1 || src_type == CV_16UC1, "THRESH_OTSU mode");
1560+
1561+
CALL_HAL_RET(thresholdOtsu, cv_hal_threshold_otsu, thresh, src.data, src.step, dst.data, dst.step,
1562+
src.cols, src.rows, src_type, maxval, type);
1563+
15561564
thresh = src.type() == CV_8UC1 ? getThreshVal_Otsu_8u( src )
15571565
: getThreshVal_Otsu_16u( src );
15581566
}
@@ -1562,9 +1570,6 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
15621570
thresh = getThreshVal_Triangle_8u( src );
15631571
}
15641572

1565-
_dst.create( src.size(), src.type() );
1566-
Mat dst = _dst.getMat();
1567-
15681573
if( src.depth() == CV_8U )
15691574
{
15701575
int ithresh = cvFloor(thresh);

0 commit comments

Comments
 (0)