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
3dafdd6a
Commit
3dafdd6a
authored
Nov 22, 2011
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added 16s support to cv::threshold.
parent
7fb5b5f2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
22 deletions
+119
-22
thresh.cpp
modules/imgproc/src/thresh.cpp
+0
-0
test_thresh.cpp
modules/imgproc/test/test_thresh.cpp
+119
-22
No files found.
modules/imgproc/src/thresh.cpp
View file @
3dafdd6a
This diff is collapsed.
Click to expand it.
modules/imgproc/test/test_thresh.cpp
View file @
3dafdd6a
...
@@ -75,9 +75,9 @@ void CV_ThreshTest::get_test_array_types_and_sizes( int test_case_idx,
...
@@ -75,9 +75,9 @@ void CV_ThreshTest::get_test_array_types_and_sizes( int test_case_idx,
vector
<
vector
<
Size
>
>&
sizes
,
vector
<
vector
<
int
>
>&
types
)
vector
<
vector
<
Size
>
>&
sizes
,
vector
<
vector
<
int
>
>&
types
)
{
{
RNG
&
rng
=
ts
->
get_rng
();
RNG
&
rng
=
ts
->
get_rng
();
int
depth
=
cvtest
::
randInt
(
rng
)
%
2
,
cn
=
cvtest
::
randInt
(
rng
)
%
4
+
1
;
int
depth
=
cvtest
::
randInt
(
rng
)
%
3
,
cn
=
cvtest
::
randInt
(
rng
)
%
4
+
1
;
cvtest
::
ArrayTest
::
get_test_array_types_and_sizes
(
test_case_idx
,
sizes
,
types
);
cvtest
::
ArrayTest
::
get_test_array_types_and_sizes
(
test_case_idx
,
sizes
,
types
);
depth
=
depth
==
0
?
CV_8U
:
CV_32F
;
depth
=
depth
==
0
?
CV_8U
:
depth
==
1
?
CV_16S
:
CV_32F
;
types
[
INPUT
][
0
]
=
types
[
OUTPUT
][
0
]
=
types
[
REF_OUTPUT
][
0
]
=
CV_MAKETYPE
(
depth
,
cn
);
types
[
INPUT
][
0
]
=
types
[
OUTPUT
][
0
]
=
types
[
REF_OUTPUT
][
0
]
=
CV_MAKETYPE
(
depth
,
cn
);
thresh_type
=
cvtest
::
randInt
(
rng
)
%
5
;
thresh_type
=
cvtest
::
randInt
(
rng
)
%
5
;
...
@@ -87,7 +87,15 @@ void CV_ThreshTest::get_test_array_types_and_sizes( int test_case_idx,
...
@@ -87,7 +87,15 @@ void CV_ThreshTest::get_test_array_types_and_sizes( int test_case_idx,
thresh_val
=
(
float
)(
cvtest
::
randReal
(
rng
)
*
350.
-
50.
);
thresh_val
=
(
float
)(
cvtest
::
randReal
(
rng
)
*
350.
-
50.
);
max_val
=
(
float
)(
cvtest
::
randReal
(
rng
)
*
350.
-
50.
);
max_val
=
(
float
)(
cvtest
::
randReal
(
rng
)
*
350.
-
50.
);
if
(
cvtest
::
randInt
(
rng
)
%
4
==
0
)
if
(
cvtest
::
randInt
(
rng
)
%
4
==
0
)
max_val
=
255
;
max_val
=
255.
f
;
}
else
if
(
depth
==
CV_16S
)
{
float
min_val
=
SHRT_MIN
-
100.
f
,
max_val
=
SHRT_MAX
+
100.
f
;
thresh_val
=
(
float
)(
cvtest
::
randReal
(
rng
)
*
(
max_val
-
min_val
)
+
min_val
);
max_val
=
(
float
)(
cvtest
::
randReal
(
rng
)
*
(
max_val
-
min_val
)
+
min_val
);
if
(
cvtest
::
randInt
(
rng
)
%
4
==
0
)
max_val
=
(
float
)
SHRT_MAX
;
}
}
else
else
{
{
...
@@ -117,88 +125,177 @@ static void test_threshold( const Mat& _src, Mat& _dst,
...
@@ -117,88 +125,177 @@ static void test_threshold( const Mat& _src, Mat& _dst,
int
depth
=
_src
.
depth
(),
cn
=
_src
.
channels
();
int
depth
=
_src
.
depth
(),
cn
=
_src
.
channels
();
int
width_n
=
_src
.
cols
*
cn
,
height
=
_src
.
rows
;
int
width_n
=
_src
.
cols
*
cn
,
height
=
_src
.
rows
;
int
ithresh
=
cvFloor
(
thresh
),
ithresh2
,
imaxval
=
cvRound
(
maxval
);
int
ithresh
=
cvFloor
(
thresh
),
ithresh2
,
imaxval
=
cvRound
(
maxval
);
const
uchar
*
src
=
_src
.
data
;
uchar
*
dst
=
_dst
.
data
;
size_t
srcstep
=
_src
.
step
,
dststep
=
_dst
.
step
;
ithresh2
=
saturate_cast
<
uchar
>
(
ithresh
);
if
(
depth
==
CV_8U
)
imaxval
=
saturate_cast
<
uchar
>
(
imaxval
);
{
ithresh2
=
saturate_cast
<
uchar
>
(
ithresh
);
imaxval
=
saturate_cast
<
uchar
>
(
imaxval
);
}
else
if
(
depth
==
CV_16S
)
{
ithresh2
=
saturate_cast
<
short
>
(
ithresh
);
imaxval
=
saturate_cast
<
short
>
(
imaxval
);
}
assert
(
depth
==
CV_8U
||
depth
==
CV_32F
);
assert
(
depth
==
CV_8U
||
depth
==
CV_
16S
||
depth
==
CV_
32F
);
switch
(
thresh_type
)
switch
(
thresh_type
)
{
{
case
CV_THRESH_BINARY
:
case
CV_THRESH_BINARY
:
for
(
i
=
0
;
i
<
height
;
i
++
,
src
+=
srcstep
,
dst
+=
dststep
)
for
(
i
=
0
;
i
<
height
;
i
++
)
{
{
if
(
depth
==
CV_8U
)
if
(
depth
==
CV_8U
)
{
const
uchar
*
src
=
_src
.
ptr
<
uchar
>
(
i
);
uchar
*
dst
=
_dst
.
ptr
<
uchar
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
for
(
j
=
0
;
j
<
width_n
;
j
++
)
dst
[
j
]
=
(
uchar
)(
src
[
j
]
>
ithresh
?
imaxval
:
0
);
dst
[
j
]
=
(
uchar
)(
src
[
j
]
>
ithresh
?
imaxval
:
0
);
}
else
if
(
depth
==
CV_16S
)
{
const
short
*
src
=
_src
.
ptr
<
short
>
(
i
);
short
*
dst
=
_dst
.
ptr
<
short
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
dst
[
j
]
=
(
short
)(
src
[
j
]
>
ithresh
?
imaxval
:
0
);
}
else
else
{
const
float
*
src
=
_src
.
ptr
<
float
>
(
i
);
float
*
dst
=
_dst
.
ptr
<
float
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
for
(
j
=
0
;
j
<
width_n
;
j
++
)
((
float
*
)
dst
)[
j
]
=
((
const
float
*
)
src
)[
j
]
>
thresh
?
maxval
:
0.
f
;
dst
[
j
]
=
src
[
j
]
>
thresh
?
maxval
:
0.
f
;
}
}
}
break
;
break
;
case
CV_THRESH_BINARY_INV
:
case
CV_THRESH_BINARY_INV
:
for
(
i
=
0
;
i
<
height
;
i
++
,
src
+=
srcstep
,
dst
+=
dststep
)
for
(
i
=
0
;
i
<
height
;
i
++
)
{
{
if
(
depth
==
CV_8U
)
if
(
depth
==
CV_8U
)
{
const
uchar
*
src
=
_src
.
ptr
<
uchar
>
(
i
);
uchar
*
dst
=
_dst
.
ptr
<
uchar
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
for
(
j
=
0
;
j
<
width_n
;
j
++
)
dst
[
j
]
=
(
uchar
)(
src
[
j
]
>
ithresh
?
0
:
imaxval
);
dst
[
j
]
=
(
uchar
)(
src
[
j
]
>
ithresh
?
0
:
imaxval
);
}
else
if
(
depth
==
CV_16S
)
{
const
short
*
src
=
_src
.
ptr
<
short
>
(
i
);
short
*
dst
=
_dst
.
ptr
<
short
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
dst
[
j
]
=
(
short
)(
src
[
j
]
>
ithresh
?
0
:
imaxval
);
}
else
else
{
const
float
*
src
=
_src
.
ptr
<
float
>
(
i
);
float
*
dst
=
_dst
.
ptr
<
float
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
for
(
j
=
0
;
j
<
width_n
;
j
++
)
((
float
*
)
dst
)[
j
]
=
((
const
float
*
)
src
)[
j
]
>
thresh
?
0.
f
:
maxval
;
dst
[
j
]
=
src
[
j
]
>
thresh
?
0.
f
:
maxval
;
}
}
}
break
;
break
;
case
CV_THRESH_TRUNC
:
case
CV_THRESH_TRUNC
:
for
(
i
=
0
;
i
<
height
;
i
++
,
src
+=
srcstep
,
dst
+=
dststep
)
for
(
i
=
0
;
i
<
height
;
i
++
)
{
{
if
(
depth
==
CV_8U
)
if
(
depth
==
CV_8U
)
{
const
uchar
*
src
=
_src
.
ptr
<
uchar
>
(
i
);
uchar
*
dst
=
_dst
.
ptr
<
uchar
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
for
(
j
=
0
;
j
<
width_n
;
j
++
)
{
{
int
s
=
src
[
j
];
int
s
=
src
[
j
];
dst
[
j
]
=
(
uchar
)(
s
>
ithresh
?
ithresh2
:
s
);
dst
[
j
]
=
(
uchar
)(
s
>
ithresh
?
ithresh2
:
s
);
}
}
}
else
if
(
depth
==
CV_16S
)
{
const
short
*
src
=
_src
.
ptr
<
short
>
(
i
);
short
*
dst
=
_dst
.
ptr
<
short
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
{
int
s
=
src
[
j
];
dst
[
j
]
=
(
short
)(
s
>
ithresh
?
ithresh2
:
s
);
}
}
else
else
{
const
float
*
src
=
_src
.
ptr
<
float
>
(
i
);
float
*
dst
=
_dst
.
ptr
<
float
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
for
(
j
=
0
;
j
<
width_n
;
j
++
)
{
{
float
s
=
((
const
float
*
)
src
)
[
j
];
float
s
=
src
[
j
];
((
float
*
)
dst
)
[
j
]
=
s
>
thresh
?
thresh
:
s
;
dst
[
j
]
=
s
>
thresh
?
thresh
:
s
;
}
}
}
}
}
break
;
break
;
case
CV_THRESH_TOZERO
:
case
CV_THRESH_TOZERO
:
for
(
i
=
0
;
i
<
height
;
i
++
,
src
+=
srcstep
,
dst
+=
dststep
)
for
(
i
=
0
;
i
<
height
;
i
++
)
{
{
if
(
depth
==
CV_8U
)
if
(
depth
==
CV_8U
)
{
const
uchar
*
src
=
_src
.
ptr
<
uchar
>
(
i
);
uchar
*
dst
=
_dst
.
ptr
<
uchar
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
for
(
j
=
0
;
j
<
width_n
;
j
++
)
{
{
int
s
=
src
[
j
];
int
s
=
src
[
j
];
dst
[
j
]
=
(
uchar
)(
s
>
ithresh
?
s
:
0
);
dst
[
j
]
=
(
uchar
)(
s
>
ithresh
?
s
:
0
);
}
}
}
else
if
(
depth
==
CV_16S
)
{
const
short
*
src
=
_src
.
ptr
<
short
>
(
i
);
short
*
dst
=
_dst
.
ptr
<
short
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
{
int
s
=
src
[
j
];
dst
[
j
]
=
(
short
)(
s
>
ithresh
?
s
:
0
);
}
}
else
else
{
const
float
*
src
=
_src
.
ptr
<
float
>
(
i
);
float
*
dst
=
_dst
.
ptr
<
float
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
for
(
j
=
0
;
j
<
width_n
;
j
++
)
{
{
float
s
=
((
const
float
*
)
src
)
[
j
];
float
s
=
src
[
j
];
((
float
*
)
dst
)
[
j
]
=
s
>
thresh
?
s
:
0.
f
;
dst
[
j
]
=
s
>
thresh
?
s
:
0.
f
;
}
}
}
}
}
break
;
break
;
case
CV_THRESH_TOZERO_INV
:
case
CV_THRESH_TOZERO_INV
:
for
(
i
=
0
;
i
<
height
;
i
++
,
src
+=
srcstep
,
dst
+=
dststep
)
for
(
i
=
0
;
i
<
height
;
i
++
)
{
{
if
(
depth
==
CV_8U
)
if
(
depth
==
CV_8U
)
{
const
uchar
*
src
=
_src
.
ptr
<
uchar
>
(
i
);
uchar
*
dst
=
_dst
.
ptr
<
uchar
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
for
(
j
=
0
;
j
<
width_n
;
j
++
)
{
{
int
s
=
src
[
j
];
int
s
=
src
[
j
];
dst
[
j
]
=
(
uchar
)(
s
>
ithresh
?
0
:
s
);
dst
[
j
]
=
(
uchar
)(
s
>
ithresh
?
0
:
s
);
}
}
}
else
if
(
depth
==
CV_16S
)
{
const
short
*
src
=
_src
.
ptr
<
short
>
(
i
);
short
*
dst
=
_dst
.
ptr
<
short
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
{
int
s
=
src
[
j
];
dst
[
j
]
=
(
short
)(
s
>
ithresh
?
0
:
s
);
}
}
else
else
{
const
float
*
src
=
_src
.
ptr
<
float
>
(
i
);
float
*
dst
=
_dst
.
ptr
<
float
>
(
i
);
for
(
j
=
0
;
j
<
width_n
;
j
++
)
for
(
j
=
0
;
j
<
width_n
;
j
++
)
{
{
float
s
=
((
const
float
*
)
src
)
[
j
];
float
s
=
src
[
j
];
((
float
*
)
dst
)
[
j
]
=
s
>
thresh
?
0.
f
:
s
;
dst
[
j
]
=
s
>
thresh
?
0.
f
:
s
;
}
}
}
}
}
break
;
break
;
default
:
default
:
...
...
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