Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
74042bf6
Commit
74042bf6
authored
Jul 08, 2018
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up hysteresis_threshold() code a bit and also removed the hard coded
limit on pixel chain recursion depth.
parent
66faa30e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
60 deletions
+25
-60
thresholding.h
dlib/image_transforms/thresholding.h
+25
-60
No files found.
dlib/image_transforms/thresholding.h
View file @
74042bf6
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
#include "thresholding_abstract.h"
#include "thresholding_abstract.h"
#include "equalize_histogram.h"
#include "equalize_histogram.h"
#include "../enable_if.h"
#include "../enable_if.h"
#include <vector>
namespace
dlib
namespace
dlib
{
{
...
@@ -594,9 +595,8 @@ namespace dlib
...
@@ -594,9 +595,8 @@ namespace dlib
out_img
.
set_size
(
in_img
.
nr
(),
in_img
.
nc
());
out_img
.
set_size
(
in_img
.
nr
(),
in_img
.
nc
());
assign_all_pixels
(
out_img
,
off_pixel
);
assign_all_pixels
(
out_img
,
off_pixel
);
const
long
size
=
1000
;
std
::
vector
<
std
::
pair
<
long
,
long
>>
stack
;
long
rstack
[
size
];
using
std
::
make_pair
;
long
cstack
[
size
];
// now do the thresholding
// now do the thresholding
for
(
long
r
=
0
;
r
<
in_img
.
nr
();
++
r
)
for
(
long
r
=
0
;
r
<
in_img
.
nr
();
++
r
)
...
@@ -609,15 +609,13 @@ namespace dlib
...
@@ -609,15 +609,13 @@ namespace dlib
{
{
// now do line following for pixels >= lower_thresh.
// now do line following for pixels >= lower_thresh.
// set the stack position to 0.
// set the stack position to 0.
long
pos
=
1
;
stack
.
push_back
(
make_pair
(
r
,
c
));
rstack
[
0
]
=
r
;
cstack
[
0
]
=
c
;
while
(
pos
>
0
)
while
(
stack
.
size
()
>
0
)
{
{
--
pos
;
const
long
r
=
stack
.
back
().
first
;
const
long
r
=
rstack
[
pos
]
;
const
long
c
=
stack
.
back
().
second
;
const
long
c
=
cstack
[
pos
]
;
stack
.
pop_back
()
;
// This is the base case of our recursion. We want to stop if we hit a
// This is the base case of our recursion. We want to stop if we hit a
// pixel we have already visited.
// pixel we have already visited.
...
@@ -629,63 +627,30 @@ namespace dlib
...
@@ -629,63 +627,30 @@ namespace dlib
// put the neighbors of this pixel on the stack if they are bright enough
// put the neighbors of this pixel on the stack if they are bright enough
if
(
r
-
1
>=
0
)
if
(
r
-
1
>=
0
)
{
{
if
(
pos
<
size
&&
get_pixel_intensity
(
in_img
[
r
-
1
][
c
])
>=
lower_thresh
)
if
(
get_pixel_intensity
(
in_img
[
r
-
1
][
c
])
>=
lower_thresh
)
{
stack
.
push_back
(
make_pair
(
r
-
1
,
c
));
rstack
[
pos
]
=
r
-
1
;
if
(
c
-
1
>=
0
&&
get_pixel_intensity
(
in_img
[
r
-
1
][
c
-
1
])
>=
lower_thresh
)
cstack
[
pos
]
=
c
;
stack
.
push_back
(
make_pair
(
r
-
1
,
c
-
1
));
++
pos
;
if
(
c
+
1
<
in_img
.
nc
()
&&
get_pixel_intensity
(
in_img
[
r
-
1
][
c
+
1
])
>=
lower_thresh
)
}
stack
.
push_back
(
make_pair
(
r
-
1
,
c
+
1
));
if
(
pos
<
size
&&
c
-
1
>=
0
&&
get_pixel_intensity
(
in_img
[
r
-
1
][
c
-
1
])
>=
lower_thresh
)
{
rstack
[
pos
]
=
r
-
1
;
cstack
[
pos
]
=
c
-
1
;
++
pos
;
}
if
(
pos
<
size
&&
c
+
1
<
in_img
.
nc
()
&&
get_pixel_intensity
(
in_img
[
r
-
1
][
c
+
1
])
>=
lower_thresh
)
{
rstack
[
pos
]
=
r
-
1
;
cstack
[
pos
]
=
c
+
1
;
++
pos
;
}
}
}
if
(
pos
<
size
&&
c
-
1
>=
0
&&
get_pixel_intensity
(
in_img
[
r
][
c
-
1
])
>=
lower_thresh
)
if
(
c
-
1
>=
0
&&
get_pixel_intensity
(
in_img
[
r
][
c
-
1
])
>=
lower_thresh
)
{
stack
.
push_back
(
make_pair
(
r
,
c
-
1
));
rstack
[
pos
]
=
r
;
if
(
c
+
1
<
in_img
.
nc
()
&&
get_pixel_intensity
(
in_img
[
r
][
c
+
1
])
>=
lower_thresh
)
cstack
[
pos
]
=
c
-
1
;
stack
.
push_back
(
make_pair
(
r
,
c
+
1
));
++
pos
;
}
if
(
pos
<
size
&&
c
+
1
<
in_img
.
nc
()
&&
get_pixel_intensity
(
in_img
[
r
][
c
+
1
])
>=
lower_thresh
)
{
rstack
[
pos
]
=
r
;
cstack
[
pos
]
=
c
+
1
;
++
pos
;
}
if
(
r
+
1
<
in_img
.
nr
())
if
(
r
+
1
<
in_img
.
nr
())
{
{
if
(
pos
<
size
&&
get_pixel_intensity
(
in_img
[
r
+
1
][
c
])
>=
lower_thresh
)
if
(
get_pixel_intensity
(
in_img
[
r
+
1
][
c
])
>=
lower_thresh
)
{
stack
.
push_back
(
make_pair
(
r
+
1
,
c
));
rstack
[
pos
]
=
r
+
1
;
if
(
c
-
1
>=
0
&&
get_pixel_intensity
(
in_img
[
r
+
1
][
c
-
1
])
>=
lower_thresh
)
cstack
[
pos
]
=
c
;
stack
.
push_back
(
make_pair
(
r
+
1
,
c
-
1
));
++
pos
;
if
(
c
+
1
<
in_img
.
nc
()
&&
get_pixel_intensity
(
in_img
[
r
+
1
][
c
+
1
])
>=
lower_thresh
)
}
stack
.
push_back
(
make_pair
(
r
+
1
,
c
+
1
));
if
(
pos
<
size
&&
c
-
1
>=
0
&&
get_pixel_intensity
(
in_img
[
r
+
1
][
c
-
1
])
>=
lower_thresh
)
{
rstack
[
pos
]
=
r
+
1
;
cstack
[
pos
]
=
c
-
1
;
++
pos
;
}
if
(
pos
<
size
&&
c
+
1
<
in_img
.
nc
()
&&
get_pixel_intensity
(
in_img
[
r
+
1
][
c
+
1
])
>=
lower_thresh
)
{
rstack
[
pos
]
=
r
+
1
;
cstack
[
pos
]
=
c
+
1
;
++
pos
;
}
}
}
}
// end while (pos >= 0)
}
// end while (stack.size() > 0)
}
}
}
}
}
}
...
...
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