Skip to content

Commit

Permalink
Merge pull request #25509 from savuor:rv/hal_otsu
Browse files Browse the repository at this point in the history
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
  • Loading branch information
savuor committed May 2, 2024
1 parent ce642e9 commit bc95f27
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
19 changes: 19 additions & 0 deletions modules/imgproc/src/hal_replacement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,25 @@ inline int hal_ni_threshold(const uchar* src_data, size_t src_step, uchar* dst_d
#define cv_hal_threshold hal_ni_threshold
//! @endcond

/**
@brief Performs threshold filtering using threshold estimated by Otsu algorithm
@param src_data Source image data
@param src_step Source image step
@param dst_data Destination image data
@param dst_step Destination image step
@param width Source image width
@param height Source image height
@param depth Depths of source and destination image
@param maxValue Value assigned to the pixels for which the condition is satisfied
@param thresholdType Thresholding type
@param thresh Calculated threshold value
*/
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; }

//! @cond IGNORED
#define cv_hal_threshold_otsu hal_ni_threshold_otsu
//! @endcond

/**
@brief Calculate box filter
@param src_data Source image data
Expand Down
11 changes: 8 additions & 3 deletions modules/imgproc/src/thresh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,10 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
ocl_threshold(_src, _dst, thresh, maxval, type), thresh)

Mat src = _src.getMat();

_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();

int automatic_thresh = (type & ~cv::THRESH_MASK);
type &= THRESH_MASK;

Expand All @@ -1553,6 +1557,10 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
{
int src_type = src.type();
CV_CheckType(src_type, src_type == CV_8UC1 || src_type == CV_16UC1, "THRESH_OTSU mode");

CALL_HAL_RET(thresholdOtsu, cv_hal_threshold_otsu, thresh, src.data, src.step, dst.data, dst.step,
src.cols, src.rows, src_type, maxval, type);

thresh = src.type() == CV_8UC1 ? getThreshVal_Otsu_8u( src )
: getThreshVal_Otsu_16u( src );
}
Expand All @@ -1562,9 +1570,6 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
thresh = getThreshVal_Triangle_8u( src );
}

_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();

if( src.depth() == CV_8U )
{
int ithresh = cvFloor(thresh);
Expand Down

0 comments on commit bc95f27

Please sign in to comment.