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
43b9a096
Commit
43b9a096
authored
May 16, 2018
by
Davis King
Browse files
Added encode_8_pixel_neighbors() and find_line_endpoints().
parent
b2f6071a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
138 additions
and
0 deletions
+138
-0
dlib/image_transforms/morphological_operations.h
dlib/image_transforms/morphological_operations.h
+84
-0
dlib/image_transforms/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
...
@@ -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
[
0b00000001
]
=
true
;
line_ending_patterns
[
0b00000010
]
=
true
;
line_ending_patterns
[
0b00000100
]
=
true
;
line_ending_patterns
[
0b00001000
]
=
true
;
line_ending_patterns
[
0b00010000
]
=
true
;
line_ending_patterns
[
0b00100000
]
=
true
;
line_ending_patterns
[
0b01000000
]
=
true
;
line_ending_patterns
[
0b10000000
]
=
true
;
line_ending_patterns
[
0b00000011
]
=
true
;
line_ending_patterns
[
0b00000110
]
=
true
;
line_ending_patterns
[
0b00001100
]
=
true
;
line_ending_patterns
[
0b00011000
]
=
true
;
line_ending_patterns
[
0b00110000
]
=
true
;
line_ending_patterns
[
0b01100000
]
=
true
;
line_ending_patterns
[
0b11000000
]
=
true
;
line_ending_patterns
[
0b10000001
]
=
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
...
@@ -307,6 +307,60 @@ namespace dlib
- #img.nr() == img.nr()
- #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