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
30e073d6
Commit
30e073d6
authored
Dec 29, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reworked the scan_image() routine to make it run faster. Also added
a new function called sum_filter().
parent
6c0f5980
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
0 deletions
+104
-0
scan_image.h
dlib/image_processing/scan_image.h
+0
-0
scan_image_abstract.h
dlib/image_processing/scan_image_abstract.h
+25
-0
scan_image.cpp
dlib/test/scan_image.cpp
+79
-0
No files found.
dlib/image_processing/scan_image.h
View file @
30e073d6
This diff is collapsed.
Click to expand it.
dlib/image_processing/scan_image_abstract.h
View file @
30e073d6
...
...
@@ -10,6 +10,31 @@
namespace
dlib
{
// ----------------------------------------------------------------------------------------
template
<
typename
image_type1
,
typename
image_type2
>
void
sum_filter
(
const
image_type1
&
img
,
image_type2
&
out
,
const
rectangle
&
rect
)
/*!
requires
- out.nr() == img.nr()
- out.nc() == img.nc()
- image_type1 == an implementation of array2d/array2d_kernel_abstract.h
and it must contain a scalar type
- image_type2 == an implementation of array2d/array2d_kernel_abstract.h
and it must contain a scalar type
ensures
- for all valid r and c:
- let SUM(r,c) == sum of pixels inside the rectangle translate_rect(rect, point(c,r))
- #out[r][c] == out[r][c] + SUM(r,c)
!*/
// ----------------------------------------------------------------------------------------
template
<
...
...
dlib/test/scan_image.cpp
View file @
30e073d6
...
...
@@ -28,6 +28,30 @@ namespace
// should start with "test."
logger
dlog
(
"test.scan_image"
);
// ----------------------------------------------------------------------------------------
template
<
typename
image_type1
,
typename
image_type2
>
void
sum_filter_i
(
const
image_type1
&
img
,
image_type2
&
out
,
const
rectangle
&
rect
)
{
typedef
typename
image_type1
::
type
pixel_type
;
typedef
typename
promote
<
pixel_type
>::
type
ptype
;
integral_image_generic
<
ptype
>
iimg
;
iimg
.
load
(
img
);
for
(
long
r
=
0
;
r
<
img
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
img
.
nc
();
++
c
)
{
const
rectangle
temp
=
translate_rect
(
rect
,
point
(
c
,
r
)).
intersect
(
get_rect
(
iimg
));
if
(
temp
.
is_empty
()
==
false
)
out
[
r
][
c
]
+=
iimg
.
get_sum_of_area
(
temp
);
}
}
}
// ----------------------------------------------------------------------------------------
...
...
@@ -364,6 +388,58 @@ namespace
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
pixel_type
>
void
test_sum_filter
(
)
{
dlib
::
rand
rnd
;
for
(
int
k
=
0
;
k
<
20
;
++
k
)
{
print_spinner
();
array2d
<
pixel_type
>
img
(
1
+
rnd
.
get_random_32bit_number
()
%
100
,
1
+
rnd
.
get_random_32bit_number
()
%
100
);
for
(
long
r
=
0
;
r
<
img
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
img
.
nc
();
++
c
)
{
img
[
r
][
c
]
=
100
*
(
rnd
.
get_random_double
()
-
0.5
);
}
}
array2d
<
long
>
test1
(
img
.
nr
(),
img
.
nc
());
array2d
<
double
>
test2
(
img
.
nr
(),
img
.
nc
());
array2d
<
long
>
test1_i
(
img
.
nr
(),
img
.
nc
());
array2d
<
double
>
test2_i
(
img
.
nr
(),
img
.
nc
());
assign_all_pixels
(
test1
,
0
);
assign_all_pixels
(
test2
,
0
);
assign_all_pixels
(
test1_i
,
0
);
assign_all_pixels
(
test2_i
,
0
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
const
long
width
=
rnd
.
get_random_32bit_number
()
%
10
+
1
;
const
long
height
=
rnd
.
get_random_32bit_number
()
%
10
+
1
;
const
point
p
(
rnd
.
get_random_32bit_number
()
%
img
.
nc
(),
rnd
.
get_random_32bit_number
()
%
img
.
nr
());
const
rectangle
rect
=
centered_rect
(
p
,
width
,
height
);
sum_filter
(
img
,
test1
,
rect
);
sum_filter
(
img
,
test2
,
rect
);
sum_filter
(
img
,
test1_i
,
rect
);
sum_filter
(
img
,
test2_i
,
rect
);
DLIB_TEST
(
array_to_matrix
(
test1
)
==
array_to_matrix
(
test1_i
));
DLIB_TEST
(
array_to_matrix
(
test2
)
==
array_to_matrix
(
test2_i
));
}
}
}
// ----------------------------------------------------------------------------------------
class
scan_image_tester
:
public
tester
...
...
@@ -384,6 +460,9 @@ namespace
run_test3
<
unsigned
char
>
(
-
1
);
run_test3
<
double
>
(
1
);
run_test3
<
double
>
(
-
1
);
test_sum_filter
<
unsigned
char
>
();
test_sum_filter
<
double
>
();
}
}
a
;
...
...
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