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
f1b5fc97
Commit
f1b5fc97
authored
Sep 21, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed the suppress_non_maximum_edges() routine so that it is more robust
to a wider range of pixel types.
parent
0ae28101
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
32 deletions
+46
-32
edge_detector.h
dlib/image_transforms/edge_detector.h
+35
-26
edge_detector_abstract.h
dlib/image_transforms/edge_detector_abstract.h
+11
-6
No files found.
dlib/image_transforms/edge_detector.h
View file @
f1b5fc97
...
...
@@ -12,29 +12,38 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
inline
char
edge_orientation
(
long
x
,
long
y
const
T
&
x_
,
const
T
&
y_
)
{
// if this is a perfectly horizontal gradient then return right away
if
(
x
==
0
)
if
(
x
_
==
0
)
{
return
'|'
;
}
else
if
(
y
==
0
)
// if this is a perfectly vertical gradient then return right away
else
if
(
y
_
==
0
)
// if this is a perfectly vertical gradient then return right away
{
return
'-'
;
}
// Promote x so that when we multiply by 128 later we know overflow won't happen.
typedef
typename
promote
<
T
>::
type
type
;
type
x
=
x_
;
type
y
=
y_
;
if
(
x
<
0
)
{
x
=
-
x
;
if
(
y
<
0
)
{
y
=
-
y
;
x
<<=
7
;
const
long
temp
=
x
/
y
;
x
*=
128
;
const
type
temp
=
x
/
y
;
if
(
temp
>
309
)
return
'-'
;
else
if
(
temp
>
53
)
...
...
@@ -44,8 +53,8 @@ namespace dlib
}
else
{
x
<<=
7
;
const
long
temp
=
x
/
y
;
x
*=
128
;
const
type
temp
=
x
/
y
;
if
(
temp
>
309
)
return
'-'
;
else
if
(
temp
>
53
)
...
...
@@ -59,9 +68,9 @@ namespace dlib
if
(
y
<
0
)
{
y
=
-
y
;
x
<<=
7
;
x
*=
128
;
const
long
temp
=
x
/
y
;
const
type
temp
=
x
/
y
;
if
(
temp
>
309
)
return
'-'
;
else
if
(
temp
>
53
)
...
...
@@ -71,9 +80,9 @@ namespace dlib
}
else
{
x
<<=
7
;
x
*=
128
;
const
long
temp
=
x
/
y
;
const
type
temp
=
x
/
y
;
if
(
temp
>
309
)
return
'-'
;
else
if
(
temp
>
53
)
...
...
@@ -98,12 +107,13 @@ namespace dlib
)
{
COMPILE_TIME_ASSERT
(
pixel_traits
<
typename
out_image_type
::
type
>::
is_unsigned
==
false
);
DLIB_ASSERT
(
(((
void
*
)
&
in_img
!=
(
void
*
)
&
horz
)
&&
((
void
*
)
&
in_img
!=
(
void
*
)
&
vert
)
&&
((
void
*
)
&
vert
!=
(
void
*
)
&
horz
)),
DLIB_ASSERT
(
!
is_same_object
(
in_img
,
horz
)
&&
!
is_same_object
(
in_img
,
vert
)
&&
!
is_same_object
(
horz
,
vert
),
"
\t
void sobel_edge_detector(in_img, horz, vert)"
<<
"
\n\t
You can't give the same image as more than one argument"
<<
"
\n\t
&in_img: "
<<
&
in_img
<<
"
\n\t
&horz: "
<<
&
horz
<<
"
\n\t
&vert: "
<<
&
vert
<<
"
\n\t
You can't give the same image as more than one argument"
<<
"
\n\t
is_same_object(in_img,horz): "
<<
is_same_object
(
in_img
,
horz
)
<<
"
\n\t
is_same_object(in_img,vert): "
<<
is_same_object
(
in_img
,
vert
)
<<
"
\n\t
is_same_object(horz,vert): "
<<
is_same_object
(
horz
,
vert
)
);
...
...
@@ -180,18 +190,16 @@ namespace dlib
<<
"
\n\t
vert.nr(): "
<<
vert
.
nr
()
<<
"
\n\t
vert.nc(): "
<<
vert
.
nc
()
);
DLIB_ASSERT
(
((
void
*
)
&
out_img
!=
(
void
*
)
&
horz
)
&&
((
void
*
)
&
out_img
!=
(
void
*
)
&
vert
),
DLIB_ASSERT
(
!
is_same_object
(
out_img
,
horz
)
&&
!
is_same_object
(
out_img
,
vert
),
"
\t
void suppress_non_maximum_edges(horz, vert, out_img)"
<<
"
\n\t
You can't give the same image as more than one argument"
<<
"
\n\t
&horz: "
<<
&
horz
<<
"
\n\t
&vert: "
<<
&
vert
<<
"
\n\t
&out_img: "
<<
&
out_img
<<
"
\n\t
out_img can't be the same as one of the input images."
<<
"
\n\t
is_same_object(out_img,horz): "
<<
is_same_object
(
out_img
,
horz
)
<<
"
\n\t
is_same_object(out_img,vert): "
<<
is_same_object
(
out_img
,
vert
)
);
using
std
::
min
;
using
std
::
abs
;
typedef
typename
out_image_type
::
type
pixel_type
;
// if there isn't any input image then don't do anything
if
(
horz
.
size
()
==
0
)
...
...
@@ -220,10 +228,11 @@ namespace dlib
{
for
(
long
c
=
first_col
;
c
<
last_col
;
++
c
)
{
const
long
y
=
horz
[
r
][
c
];
const
long
x
=
vert
[
r
][
c
];
typedef
typename
in_image_type
::
type
T
;
const
T
y
=
horz
[
r
][
c
];
const
T
x
=
vert
[
r
][
c
];
const
long
val
=
abs
(
horz
[
r
][
c
])
+
abs
(
vert
[
r
][
c
]);
const
T
val
=
abs
(
horz
[
r
][
c
])
+
abs
(
vert
[
r
][
c
]);
const
char
ori
=
edge_orientation
(
x
,
y
);
const
unsigned
char
zero
=
0
;
...
...
dlib/image_transforms/edge_detector_abstract.h
View file @
f1b5fc97
...
...
@@ -10,9 +10,12 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
inline
char
edge_orientation
(
long
x
,
long
y
const
T
&
x
,
const
T
&
y
);
/*!
ensures
...
...
@@ -46,8 +49,9 @@ namespace dlib
- out_image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename in_image_type::type> must be defined
- pixel_traits<typename out_image_type::type>::is_unsigned == false
- (&in_img != &horz) && (&in_img != &vert) && (&vert != &horz)
(i.e. all three images are different image objects)
- is_same_object(in_img,horz) == false
- is_same_object(in_img,vert) == false
- is_same_object(horz,vert) == false
ensures
- Applies the sobel edge detector to the given input image and stores the resulting
edge detections in the horz and vert images
...
...
@@ -80,8 +84,9 @@ namespace dlib
- pixel_traits<typename out_image_type::type> must be defined
- horz.nr() == vert.nr()
- horz.nc() == vert.nc()
- (&out_img != &horz) && (&out_img != &vert)
- in_image_type::type == a signed integral type
- is_same_object(out_img, horz) == false
- is_same_object(out_img, vert) == false
- in_image_type::type == A signed scalar type (e.g. int, double, etc.)
ensures
- #out_img.nr() = horz.nr()
- #out_img.nc() = horz.nc()
...
...
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