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
43b9a096
Commit
43b9a096
authored
May 17, 2018
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added encode_8_pixel_neighbors() and find_line_endpoints().
parent
b2f6071a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
138 additions
and
0 deletions
+138
-0
morphological_operations.h
dlib/image_transforms/morphological_operations.h
+84
-0
morphological_operations_abstract.h
dlib/image_transforms/morphological_operations_abstract.h
+54
-0
No files found.
dlib/image_transforms/morphological_operations.h
View file @
43b9a096
...
...
@@ -837,6 +837,90 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
>
unsigned
char
encode_8_pixel_neighbors
(
const
const_image_view
<
image_type
>&
img
,
const
point
&
p
)
{
unsigned
char
ch
=
0
;
const
rectangle
area
=
get_rect
(
img
);
auto
check
=
[
&
](
long
r
,
long
c
)
{
ch
<<=
1
;
if
(
area
.
contains
(
c
,
r
)
&&
img
[
r
][
c
])
ch
|=
1
;
};
long
r
=
p
.
y
();
long
c
=
p
.
x
();
check
(
r
-
1
,
c
-
1
);
check
(
r
-
1
,
c
);
check
(
r
-
1
,
c
+
1
);
check
(
r
,
c
+
1
);
check
(
r
+
1
,
c
+
1
);
check
(
r
+
1
,
c
);
check
(
r
+
1
,
c
-
1
);
check
(
r
,
c
-
1
);
return
ch
;
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
>
std
::
vector
<
point
>
find_line_endpoints
(
const
image_type
&
img_
)
{
const_image_view
<
image_type
>
img
(
img_
);
std
::
array
<
bool
,
256
>
line_ending_patterns
;
line_ending_patterns
.
fill
(
false
);
line_ending_patterns
[
0
b00000001
]
=
true
;
line_ending_patterns
[
0
b00000010
]
=
true
;
line_ending_patterns
[
0
b00000100
]
=
true
;
line_ending_patterns
[
0
b00001000
]
=
true
;
line_ending_patterns
[
0
b00010000
]
=
true
;
line_ending_patterns
[
0
b00100000
]
=
true
;
line_ending_patterns
[
0
b01000000
]
=
true
;
line_ending_patterns
[
0
b10000000
]
=
true
;
line_ending_patterns
[
0
b00000011
]
=
true
;
line_ending_patterns
[
0
b00000110
]
=
true
;
line_ending_patterns
[
0
b00001100
]
=
true
;
line_ending_patterns
[
0
b00011000
]
=
true
;
line_ending_patterns
[
0
b00110000
]
=
true
;
line_ending_patterns
[
0
b01100000
]
=
true
;
line_ending_patterns
[
0
b11000000
]
=
true
;
line_ending_patterns
[
0
b10000001
]
=
true
;
std
::
vector
<
point
>
results
;
for
(
long
r
=
0
;
r
<
img
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
img
.
nc
();
++
c
)
{
if
(
img
[
r
][
c
]
&&
line_ending_patterns
[
encode_8_pixel_neighbors
(
img
,
point
(
c
,
r
))])
{
results
.
emplace_back
(
c
,
r
);
}
}
}
return
results
;
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
dlib/image_transforms/morphological_operations_abstract.h
View file @
43b9a096
...
...
@@ -307,6 +307,60 @@ namespace dlib
- #img.nr() == img.nr()
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
>
unsigned
char
encode_8_pixel_neighbors
(
const
const_image_view
<
image_type
>&
img
,
const
point
&
p
);
/*!
requires
- image_type is an object that implement the interface defined in
dlib/image_processing/generic_image.h
- img must contain a grayscale pixel type.
- all pixels in img are set to either on_pixel or off_pixel.
(i.e. it must be a binary image)
- get_rect(img).contains(p) == true
ensures
- This routine looks at the 8 pixels immediately surrounding the pixel
img[p.y()][p.x()] and encodes their on/off pattern into the bits of an
unsigned char and returns it. To be specific, the neighbors are read
clockwise starting from the upper left and written to the unsigned char
starting with the high order bits. Therefore, the mapping between
neighboring pixels to bits is:
7 6 5
0 4
1 2 3
Where 0 refers to the lowest order bit in the unsigned char and 7 to the
highest order bit. Finally, a bit in the unsigned char is 1 if and only if
the corresponding pixel is on_pixel.
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
>
std
::
vector
<
point
>
find_line_endpoints
(
const
image_type
&
img
);
/*!
requires
- image_type is an object that implement the interface defined in
dlib/image_processing/generic_image.h
- img must contain a grayscale pixel type.
- all pixels in img are set to either on_pixel or off_pixel.
(i.e. it must be a binary image)
ensures
- This routine finds endpoints of lines in a thinned binary image. For
example, if the image was produced by skeleton() or something like a canny
edge detector then you can use find_line_endpoints() to find the pixels
sitting on the ends of lines.
!*/
// ----------------------------------------------------------------------------------------
}
...
...
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