Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
7ae19467
Commit
7ae19467
authored
Nov 30, 2017
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10171 from ElenaGvozdeva:Threshold
parents
fe95d5a7
73ac5321
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
9 deletions
+74
-9
imgproc.hpp
modules/imgproc/include/opencv2/imgproc.hpp
+2
-1
interface.h
modules/imgproc/include/opencv2/imgproc/hal/interface.h
+20
-0
perf_threshold.cpp
modules/imgproc/perf/perf_threshold.cpp
+9
-6
hal_replacement.hpp
modules/imgproc/src/hal_replacement.hpp
+34
-0
thresh.cpp
modules/imgproc/src/thresh.cpp
+9
-2
No files found.
modules/imgproc/include/opencv2/imgproc.hpp
View file @
7ae19467
...
@@ -2805,7 +2805,8 @@ The function can process the image in-place.
...
@@ -2805,7 +2805,8 @@ The function can process the image in-place.
@param src Source 8-bit single-channel image.
@param src Source 8-bit single-channel image.
@param dst Destination image of the same size and the same type as src.
@param dst Destination image of the same size and the same type as src.
@param maxValue Non-zero value assigned to the pixels for which the condition is satisfied
@param maxValue Non-zero value assigned to the pixels for which the condition is satisfied
@param adaptiveMethod Adaptive thresholding algorithm to use, see cv::AdaptiveThresholdTypes
@param adaptiveMethod Adaptive thresholding algorithm to use, see cv::AdaptiveThresholdTypes.
The BORDER_REPLICATE | BORDER_ISOLATED is used to process boundaries.
@param thresholdType Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV,
@param thresholdType Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV,
see cv::ThresholdTypes.
see cv::ThresholdTypes.
@param blockSize Size of a pixel neighborhood that is used to calculate a threshold value for the
@param blockSize Size of a pixel neighborhood that is used to calculate a threshold value for the
...
...
modules/imgproc/include/opencv2/imgproc/hal/interface.h
View file @
7ae19467
...
@@ -21,6 +21,26 @@
...
@@ -21,6 +21,26 @@
#define CV_HAL_MORPH_DILATE 1
#define CV_HAL_MORPH_DILATE 1
//! @}
//! @}
//! @name Threshold types
//! @sa cv::ThresholdTypes
//! @{
#define CV_HAL_THRESH_BINARY 0
#define CV_HAL_THRESH_BINARY_INV 1
#define CV_HAL_THRESH_TRUNC 2
#define CV_HAL_THRESH_TOZERO 3
#define CV_HAL_THRESH_TOZERO_INV 4
#define CV_HAL_THRESH_MASK 7
#define CV_HAL_THRESH_OTSU 8
#define CV_HAL_THRESH_TRIANGLE 16
//! @}
//! @name Adaptive threshold algorithm
//! @sa cv::AdaptiveThresholdTypes
//! @{
#define CV_HAL_ADAPTIVE_THRESH_MEAN_C 0
#define CV_HAL_ADAPTIVE_THRESH_GAUSSIAN_C 1
//! @}
//! @}
//! @}
#endif
#endif
modules/imgproc/perf/perf_threshold.cpp
View file @
7ae19467
...
@@ -60,15 +60,16 @@ PERF_TEST_P(Size_Only, threshold_otsu, testing::Values(TYPICAL_MAT_SIZES))
...
@@ -60,15 +60,16 @@ PERF_TEST_P(Size_Only, threshold_otsu, testing::Values(TYPICAL_MAT_SIZES))
CV_ENUM
(
AdaptThreshType
,
THRESH_BINARY
,
THRESH_BINARY_INV
)
CV_ENUM
(
AdaptThreshType
,
THRESH_BINARY
,
THRESH_BINARY_INV
)
CV_ENUM
(
AdaptThreshMethod
,
ADAPTIVE_THRESH_MEAN_C
,
ADAPTIVE_THRESH_GAUSSIAN_C
)
CV_ENUM
(
AdaptThreshMethod
,
ADAPTIVE_THRESH_MEAN_C
,
ADAPTIVE_THRESH_GAUSSIAN_C
)
typedef
std
::
tr1
::
tuple
<
Size
,
AdaptThreshType
,
AdaptThreshMethod
,
int
>
Size_AdaptThreshType_AdaptThreshMethod_BlockSize
_t
;
typedef
std
::
tr1
::
tuple
<
Size
,
AdaptThreshType
,
AdaptThreshMethod
,
int
,
double
>
Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta
_t
;
typedef
perf
::
TestBaseWithParam
<
Size_AdaptThreshType_AdaptThreshMethod_BlockSize_
t
>
Size_AdaptThreshType_AdaptThreshMethod_BlockSize
;
typedef
perf
::
TestBaseWithParam
<
Size_AdaptThreshType_AdaptThreshMethod_BlockSize_
Delta_t
>
Size_AdaptThreshType_AdaptThreshMethod_BlockSize_Delta
;
PERF_TEST_P
(
Size_AdaptThreshType_AdaptThreshMethod_BlockSize
,
adaptiveThreshold
,
PERF_TEST_P
(
Size_AdaptThreshType_AdaptThreshMethod_BlockSize
_Delta
,
adaptiveThreshold
,
testing
::
Combine
(
testing
::
Combine
(
testing
::
Values
(
TYPICAL_MAT_SIZES
),
testing
::
Values
(
TYPICAL_MAT_SIZES
),
AdaptThreshType
::
all
(),
AdaptThreshType
::
all
(),
AdaptThreshMethod
::
all
(),
AdaptThreshMethod
::
all
(),
testing
::
Values
(
3
,
5
)
testing
::
Values
(
3
,
5
),
testing
::
Values
(
0.0
,
10.0
)
)
)
)
)
{
{
...
@@ -76,12 +77,14 @@ PERF_TEST_P(Size_AdaptThreshType_AdaptThreshMethod_BlockSize, adaptiveThreshold,
...
@@ -76,12 +77,14 @@ PERF_TEST_P(Size_AdaptThreshType_AdaptThreshMethod_BlockSize, adaptiveThreshold,
AdaptThreshType
adaptThreshType
=
get
<
1
>
(
GetParam
());
AdaptThreshType
adaptThreshType
=
get
<
1
>
(
GetParam
());
AdaptThreshMethod
adaptThreshMethod
=
get
<
2
>
(
GetParam
());
AdaptThreshMethod
adaptThreshMethod
=
get
<
2
>
(
GetParam
());
int
blockSize
=
get
<
3
>
(
GetParam
());
int
blockSize
=
get
<
3
>
(
GetParam
());
double
C
=
get
<
4
>
(
GetParam
());
double
maxValue
=
theRNG
().
uniform
(
1
,
254
);
double
maxValue
=
theRNG
().
uniform
(
1
,
254
);
double
C
=
10.0
;
int
type
=
CV_8UC1
;
int
type
=
CV_8UC1
;
Mat
src
(
sz
,
type
);
Mat
src_full
(
cv
::
Size
(
sz
.
width
+
2
,
sz
.
height
+
2
),
type
);
Mat
src
=
src_full
(
cv
::
Rect
(
1
,
1
,
sz
.
width
,
sz
.
height
));
Mat
dst
(
sz
,
type
);
Mat
dst
(
sz
,
type
);
declare
.
in
(
src
,
WARMUP_RNG
).
out
(
dst
);
declare
.
in
(
src
,
WARMUP_RNG
).
out
(
dst
);
...
...
modules/imgproc/src/hal_replacement.hpp
View file @
7ae19467
...
@@ -630,6 +630,40 @@ inline int hal_ni_medianBlur(const uchar* src_data, size_t src_step, uchar* dst_
...
@@ -630,6 +630,40 @@ inline int hal_ni_medianBlur(const uchar* src_data, size_t src_step, uchar* dst_
#define cv_hal_medianBlur hal_ni_medianBlur
#define cv_hal_medianBlur hal_ni_medianBlur
//! @endcond
//! @endcond
/**
@brief Calculates adaptive threshold
@param src_data,src_step Source image
@param dst_data,dst_step Destination image
@param width,height Source image dimensions
@param maxValue Value assigned to the pixels for which the condition is satisfied
@param adaptiveMethod Adaptive thresholding algorithm
@param thresholdType Thresholding type
@param blockSize Size of a pixel neighborhood that is used to calculate a threshold value
@param C Constant subtracted from the mean or weighted mean
*/
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
;
}
//! @cond IGNORED
#define cv_hal_adaptiveThreshold hal_ni_adaptiveThreshold
//! @endcond
/**
@brief Calculates fixed-level threshold to each array element
@param src_data,src_step Source image
@param dst_data,dst_step Destination image
@param width,height Source image dimensions
@param depth Depths of source and destination image
@param cn Number of channels
@param thresh Threshold value
@param maxValue Value assigned to the pixels for which the condition is satisfied
@param thresholdType Thresholding type
*/
inline
int
hal_ni_threshold
(
const
uchar
*
src_data
,
size_t
src_step
,
uchar
*
dst_data
,
size_t
dst_step
,
int
width
,
int
height
,
int
depth
,
int
cn
,
double
thresh
,
double
maxValue
,
int
thresholdType
)
{
return
CV_HAL_ERROR_NOT_IMPLEMENTED
;
}
//! @cond IGNORED
#define cv_hal_threshold hal_ni_threshold
//! @endcond
//! @}
//! @}
#if defined __GNUC__
#if defined __GNUC__
...
...
modules/imgproc/src/thresh.cpp
View file @
7ae19467
...
@@ -1214,6 +1214,10 @@ public:
...
@@ -1214,6 +1214,10 @@ public:
Mat
srcStripe
=
src
.
rowRange
(
row0
,
row1
);
Mat
srcStripe
=
src
.
rowRange
(
row0
,
row1
);
Mat
dstStripe
=
dst
.
rowRange
(
row0
,
row1
);
Mat
dstStripe
=
dst
.
rowRange
(
row0
,
row1
);
CALL_HAL
(
threshold
,
cv_hal_threshold
,
srcStripe
.
data
,
srcStripe
.
step
,
dstStripe
.
data
,
dstStripe
.
step
,
srcStripe
.
cols
,
srcStripe
.
rows
,
srcStripe
.
depth
(),
srcStripe
.
channels
(),
thresh
,
maxval
,
thresholdType
);
if
(
srcStripe
.
depth
()
==
CV_8U
)
if
(
srcStripe
.
depth
()
==
CV_8U
)
{
{
thresh_8u
(
srcStripe
,
dstStripe
,
(
uchar
)
thresh
,
(
uchar
)
maxval
,
thresholdType
);
thresh_8u
(
srcStripe
,
dstStripe
,
(
uchar
)
thresh
,
(
uchar
)
maxval
,
thresholdType
);
...
@@ -1530,6 +1534,9 @@ void cv::adaptiveThreshold( InputArray _src, OutputArray _dst, double maxValue,
...
@@ -1530,6 +1534,9 @@ void cv::adaptiveThreshold( InputArray _src, OutputArray _dst, double maxValue,
return
;
return
;
}
}
CALL_HAL
(
adaptiveThreshold
,
cv_hal_adaptiveThreshold
,
src
.
data
,
src
.
step
,
dst
.
data
,
dst
.
step
,
src
.
cols
,
src
.
rows
,
maxValue
,
method
,
type
,
blockSize
,
delta
);
Mat
mean
;
Mat
mean
;
if
(
src
.
data
!=
dst
.
data
)
if
(
src
.
data
!=
dst
.
data
)
...
@@ -1537,13 +1544,13 @@ void cv::adaptiveThreshold( InputArray _src, OutputArray _dst, double maxValue,
...
@@ -1537,13 +1544,13 @@ void cv::adaptiveThreshold( InputArray _src, OutputArray _dst, double maxValue,
if
(
method
==
ADAPTIVE_THRESH_MEAN_C
)
if
(
method
==
ADAPTIVE_THRESH_MEAN_C
)
boxFilter
(
src
,
mean
,
src
.
type
(),
Size
(
blockSize
,
blockSize
),
boxFilter
(
src
,
mean
,
src
.
type
(),
Size
(
blockSize
,
blockSize
),
Point
(
-
1
,
-
1
),
true
,
BORDER_REPLICATE
);
Point
(
-
1
,
-
1
),
true
,
BORDER_REPLICATE
|
BORDER_ISOLATED
);
else
if
(
method
==
ADAPTIVE_THRESH_GAUSSIAN_C
)
else
if
(
method
==
ADAPTIVE_THRESH_GAUSSIAN_C
)
{
{
Mat
srcfloat
,
meanfloat
;
Mat
srcfloat
,
meanfloat
;
src
.
convertTo
(
srcfloat
,
CV_32F
);
src
.
convertTo
(
srcfloat
,
CV_32F
);
meanfloat
=
srcfloat
;
meanfloat
=
srcfloat
;
GaussianBlur
(
srcfloat
,
meanfloat
,
Size
(
blockSize
,
blockSize
),
0
,
0
,
BORDER_REPLICATE
);
GaussianBlur
(
srcfloat
,
meanfloat
,
Size
(
blockSize
,
blockSize
),
0
,
0
,
BORDER_REPLICATE
|
BORDER_ISOLATED
);
meanfloat
.
convertTo
(
mean
,
src
.
type
());
meanfloat
.
convertTo
(
mean
,
src
.
type
());
}
}
else
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment