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
e340f1cb
Commit
e340f1cb
authored
May 13, 2018
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an overload of partition_pixels() that provides multiple output thresholds.
parent
69a53cc9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
2 deletions
+92
-2
thresholding.h
dlib/image_transforms/thresholding.h
+0
-0
thresholding_abstract.h
dlib/image_transforms/thresholding_abstract.h
+29
-0
image.cpp
dlib/test/image.cpp
+63
-2
No files found.
dlib/image_transforms/thresholding.h
View file @
e340f1cb
This diff is collapsed.
Click to expand it.
dlib/image_transforms/thresholding_abstract.h
View file @
e340f1cb
...
...
@@ -34,6 +34,35 @@ namespace dlib
deviations between each pixel and the mean of its group is minimized.
!*/
template
<
typename
image_type
,
typename
...
T
>
void
partition_pixels
(
const
image_type
&
img
,
typename
pixel_traits
<
typename
image_traits
<
image_type
>::
pixel_type
>::
basic_pixel_type
&
pix_thresh
,
T
&&
...
more_thresholds
);
/*!
requires
- image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
- pixel_traits<typename image_traits<image_type>::pixel_type>::has_alpha == false
- more_thresholds == a bunch of parameters of the same type as pix_thresh.
ensures
- This version of partition_pixels() finds multiple partitions rather than just
one partition. It does this by first partitioning the pixels just as the
above partition_pixels(img) does. Then it forms a new image with only pixels
>= that first partition value and recursively partitions this new image.
However, the recursion is implemented in an efficient way which is faster than
explicitly forming these images and calling partition_pixels(), but the
output is the same as if you did. For example, suppose you called
partition_pixels(img, t1, t2, t3). Then we would have:
- t1 == partition_pixels(img)
- t2 == partition_pixels(an image with only pixels with values >= t1 in it)
- t3 == partition_pixels(an image with only pixels with values >= t2 in it)
!*/
// ----------------------------------------------------------------------------------------
template
<
...
...
dlib/test/image.cpp
View file @
e340f1cb
...
...
@@ -1904,10 +1904,39 @@ namespace
p
=
rnd
.
get_random_8bit_number
();
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
partition_pixels
(
img
));
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
impl
::
partition_pixels_float
(
img
));
unsigned
char
thresh
;
impl
::
partition_pixels_float
(
img
,
thresh
);
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
thresh
);
matrix
<
float
>
fimg
=
matrix_cast
<
float
>
(
img
);
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
partition_pixels
(
fimg
));
std
::
vector
<
unsigned
char
>
tmp
;
for
(
auto
&
v
:
img
)
if
(
v
>=
thresh
)
tmp
.
push_back
(
v
);
matrix
<
unsigned
char
>
img2
=
mat
(
tmp
);
unsigned
char
thresh2
;
impl
::
partition_pixels_float
(
img
,
thresh
,
thresh2
);
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
thresh
);
DLIB_TEST
(
simple_partition_pixels
(
img2
)
==
thresh2
);
partition_pixels
(
img
,
thresh
,
thresh2
);
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
thresh
);
DLIB_TEST
(
simple_partition_pixels
(
img2
)
==
thresh2
);
std
::
vector
<
float
>
ftmp
;
for
(
auto
&
v
:
fimg
)
if
(
v
>=
thresh
)
ftmp
.
push_back
(
v
);
matrix
<
float
>
fimg2
=
mat
(
ftmp
);
float
fthresh
,
fthresh2
;
partition_pixels
(
fimg
,
fthresh
,
fthresh2
);
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
fthresh
);
DLIB_TEST
(
simple_partition_pixels
(
img2
)
==
fthresh2
);
}
...
...
@@ -1919,10 +1948,42 @@ namespace
p
=
rnd
.
get_random_8bit_number
();
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
partition_pixels
(
img
));
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
impl
::
partition_pixels_float
(
img
));
unsigned
char
thresh
;
impl
::
partition_pixels_float
(
img
,
thresh
);
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
thresh
);
matrix
<
float
>
fimg
=
matrix_cast
<
float
>
(
img
);
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
partition_pixels
(
fimg
));
std
::
vector
<
unsigned
char
>
tmp
;
for
(
auto
&
v
:
img
)
if
(
v
>=
thresh
)
tmp
.
push_back
(
v
);
matrix
<
unsigned
char
>
img2
=
mat
(
tmp
);
unsigned
char
thresh2
;
impl
::
partition_pixels_float
(
img
,
thresh
,
thresh2
);
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
thresh
);
DLIB_TEST
(
simple_partition_pixels
(
img2
)
==
thresh2
);
partition_pixels
(
img
,
thresh
,
thresh2
);
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
thresh
);
DLIB_TEST
(
simple_partition_pixels
(
img2
)
==
thresh2
);
std
::
vector
<
float
>
ftmp
;
for
(
auto
&
v
:
fimg
)
if
(
v
>=
thresh
)
ftmp
.
push_back
(
v
);
matrix
<
float
>
fimg2
=
mat
(
ftmp
);
float
fthresh
,
fthresh2
;
partition_pixels
(
fimg
,
fthresh
,
fthresh2
);
DLIB_TEST
(
simple_partition_pixels
(
img
)
==
fthresh
);
DLIB_TEST
(
simple_partition_pixels
(
img2
)
==
fthresh2
);
}
}
...
...
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