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