Skip to content

Commit 11ddb93

Browse files
author
elenagvo
committed
add HAL for adaptiveThreshold
1 parent c4b158f commit 11ddb93

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

modules/imgproc/include/opencv2/imgproc.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2805,7 +2805,8 @@ The function can process the image in-place.
28052805
@param src Source 8-bit single-channel image.
28062806
@param dst Destination image of the same size and the same type as src.
28072807
@param maxValue Non-zero value assigned to the pixels for which the condition is satisfied
2808-
@param adaptiveMethod Adaptive thresholding algorithm to use, see cv::AdaptiveThresholdTypes
2808+
@param adaptiveMethod Adaptive thresholding algorithm to use, see cv::AdaptiveThresholdTypes.
2809+
The BORDER_REPLICATE | BORDER_ISOLATED is used to process boundaries.
28092810
@param thresholdType Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV,
28102811
see cv::ThresholdTypes.
28112812
@param blockSize Size of a pixel neighborhood that is used to calculate a threshold value for the

modules/imgproc/perf/perf_threshold.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,31 @@ PERF_TEST_P(Size_Only, threshold_otsu, testing::Values(TYPICAL_MAT_SIZES))
6060
CV_ENUM(AdaptThreshType, THRESH_BINARY, THRESH_BINARY_INV)
6161
CV_ENUM(AdaptThreshMethod, ADAPTIVE_THRESH_MEAN_C, ADAPTIVE_THRESH_GAUSSIAN_C)
6262

63-
typedef std::tr1::tuple<Size, AdaptThreshType, AdaptThreshMethod, int> Size_AdaptThreshType_AdaptThreshMethod_BlockSize_t;
64-
typedef perf::TestBaseWithParam<Size_AdaptThreshType_AdaptThreshMethod_BlockSize_t> Size_AdaptThreshType_AdaptThreshMethod_BlockSize;
63+
typedef std::tr1::tuple<Size, AdaptThreshType, AdaptThreshMethod, int, double> Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta_t;
64+
typedef perf::TestBaseWithParam<Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta_t> Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta;
6565

66-
PERF_TEST_P(Size_AdaptThreshType_AdaptThreshMethod_BlockSize, adaptiveThreshold,
66+
PERF_TEST_P(Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta, adaptiveThreshold,
6767
testing::Combine(
6868
testing::Values(TYPICAL_MAT_SIZES),
6969
AdaptThreshType::all(),
7070
AdaptThreshMethod::all(),
71-
testing::Values(3, 5)
71+
testing::Values(3, 5),
72+
testing::Values(0.0, 10.0)
7273
)
7374
)
7475
{
7576
Size sz = get<0>(GetParam());
7677
AdaptThreshType adaptThreshType = get<1>(GetParam());
7778
AdaptThreshMethod adaptThreshMethod = get<2>(GetParam());
7879
int blockSize = get<3>(GetParam());
80+
double C = get<4>(GetParam());
7981

8082
double maxValue = theRNG().uniform(1, 254);
81-
double C = 10.0;
8283

8384
int type = CV_8UC1;
84-
Mat src(sz, type);
85+
86+
Mat src_full(cv::Size(sz.width + 2, sz.height + 2), type);
87+
Mat src = src_full(cv::Rect(1, 1, sz.width, sz.height));
8588
Mat dst(sz, type);
8689

8790
declare.in(src, WARMUP_RNG).out(dst);

modules/imgproc/src/hal_replacement.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,23 @@ inline int hal_ni_medianBlur(const uchar* src_data, size_t src_step, uchar* dst_
630630
#define cv_hal_medianBlur hal_ni_medianBlur
631631
//! @endcond
632632

633+
/**
634+
@brief Calculates adaptive threshold
635+
@param src_data,src_step Source image
636+
@param dst_data,dst_step Destination image
637+
@param width,height Source image dimensions
638+
@param maxValue Value assigned to the pixels for which the condition is satisfied
639+
@param adaptiveMethod Adaptive thresholding algorithm
640+
@param thresholdType Thresholding type
641+
@param blockSize Size of a pixel neighborhood that is used to calculate a threshold value
642+
@param C Constant subtracted from the mean or weighted mean
643+
*/
644+
inline int hal_ni_adaptiveThreshold(const uchar* src_data, size_t src_step, uchar* dst_data, size_t dst_step, int width, int height, double maxValue, int adaptiveMethod, int thresholdType, int blockSize, double C) { return CV_HAL_ERROR_NOT_IMPLEMENTED; }
645+
646+
//! @cond IGNORED
647+
#define cv_hal_adaptiveThreshold hal_ni_adaptiveThreshold
648+
//! @endcond
649+
633650
//! @}
634651

635652
#if defined __GNUC__

modules/imgproc/src/thresh.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,14 +1530,17 @@ void cv::adaptiveThreshold( InputArray _src, OutputArray _dst, double maxValue,
15301530
return;
15311531
}
15321532

1533+
CALL_HAL(adaptiveThreshold, cv_hal_adaptiveThreshold, src.data, src.step, dst.data, dst.step, src.cols, src.rows,
1534+
maxValue, method, type, blockSize, delta);
1535+
15331536
Mat mean;
15341537

15351538
if( src.data != dst.data )
15361539
mean = dst;
15371540

15381541
if (method == ADAPTIVE_THRESH_MEAN_C)
15391542
boxFilter( src, mean, src.type(), Size(blockSize, blockSize),
1540-
Point(-1,-1), true, BORDER_REPLICATE );
1543+
Point(-1,-1), true, BORDER_REPLICATE|BORDER_ISOLATED );
15411544
else if (method == ADAPTIVE_THRESH_GAUSSIAN_C)
15421545
{
15431546
Mat srcfloat,meanfloat;

0 commit comments

Comments
 (0)