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
93121255
Commit
93121255
authored
Aug 17, 2011
by
Davis King
Browse files
Made the integral_image more general by making it templated on the
type of scalar used to store the sums.
parent
2d0d3c9e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
22 deletions
+45
-22
dlib/image_transforms/integral_image.h
dlib/image_transforms/integral_image.h
+15
-8
dlib/image_transforms/integral_image_abstract.h
dlib/image_transforms/integral_image_abstract.h
+19
-7
dlib/test/image.cpp
dlib/test/image.cpp
+11
-7
No files found.
dlib/image_transforms/integral_image.h
View file @
93121255
...
...
@@ -18,10 +18,13 @@ namespace dlib
// ----------------------------------------------------------------------------------------
class
integral_image
:
noncopyable
template
<
typename
T
>
class
integral_image_generic
:
noncopyable
{
public:
typedef
long
value_type
;
typedef
T
value_type
;
long
nr
()
const
{
return
int_img
.
nr
();
}
long
nc
()
const
{
return
int_img
.
nc
();
}
...
...
@@ -31,11 +34,11 @@ namespace dlib
const
image_type
&
img
)
{
long
pixel
;
T
pixel
;
int_img
.
set_size
(
img
.
nr
(),
img
.
nc
());
// compute the first row of the integral image
long
temp
=
0
;
T
temp
=
0
;
for
(
long
c
=
0
;
c
<
img
.
nc
();
++
c
)
{
assign_pixel
(
pixel
,
img
[
0
][
c
]);
...
...
@@ -57,12 +60,12 @@ namespace dlib
}
long
get_sum_of_area
(
value_type
get_sum_of_area
(
const
rectangle
&
rect
)
const
{
DLIB_ASSERT
(
get_rect
(
*
this
).
contains
(
rect
)
==
true
&&
rect
.
is_empty
()
==
false
,
"
\t
long
get_sum_of_area(rect)"
"
\t
value_type
get_sum_of_area(rect)"
<<
"
\n\t
You have given a rectangle that goes outside the image"
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
rect.is_empty(): "
<<
rect
.
is_empty
()
...
...
@@ -70,7 +73,7 @@ namespace dlib
<<
"
\n\t
get_rect(*this): "
<<
get_rect
(
*
this
)
);
long
top_left
=
0
,
top_right
=
0
,
bottom_left
=
0
,
bottom_right
=
0
;
T
top_left
=
0
,
top_right
=
0
,
bottom_left
=
0
,
bottom_right
=
0
;
bottom_right
=
int_img
[
rect
.
bottom
()][
rect
.
right
()];
if
(
rect
.
left
()
-
1
>=
0
&&
rect
.
top
()
-
1
>=
0
)
...
...
@@ -93,11 +96,15 @@ namespace dlib
private:
array2d
<
long
>
int_img
;
array2d
<
T
>
int_img
;
};
// ----------------------------------------------------------------------------------------
typedef
integral_image_generic
<
long
>
integral_image
;
// ----------------------------------------------------------------------------------------
template
<
typename
integral_image_type
>
...
...
dlib/image_transforms/integral_image_abstract.h
View file @
93121255
...
...
@@ -13,9 +13,17 @@ namespace dlib
// ----------------------------------------------------------------------------------------
class
integral_image
:
noncopyable
template
<
typename
T
>
class
integral_image_generic
:
noncopyable
{
/*!
REQUIREMENTS ON T
T should be a built in scalar type. Moreover, it should
be capable of storing sums of whatever kind of pixel
you will be dealing with.
INITIAL VALUE
- nr() == 0
- nc() == 0
...
...
@@ -29,7 +37,7 @@ namespace dlib
constant time.
!*/
public:
typedef
long
value_type
;
typedef
T
value_type
;
const
long
nr
(
)
const
;
...
...
@@ -52,7 +60,7 @@ namespace dlib
/*!
requires
- image_type == a type that implements the array2d/array2d_kernel_abstract.h interface
- pixel_traits<typename image_type::type>::
is_unsigned == tru
e
- pixel_traits<typename image_type::type>::
has_alpha == fals
e
ensures
- #nr() == img.nr()
- #nc() == img.nc()
...
...
@@ -77,6 +85,10 @@ namespace dlib
};
// ----------------------------------------------------------------------------------------
typedef
integral_image_generic
<
long
>
integral_image
;
// ----------------------------------------------------------------------------------------
template
<
typename
integral_image_type
>
...
...
@@ -88,8 +100,8 @@ namespace dlib
/*!
requires
- get_rect(img).contains(centered_rect(p,width,width)) == true
- integral_image_type == a type that implements the integral_image
interface
defined above
- integral_image_type == a type that implements the integral_image
_generic
interface
defined above
ensures
- returns the response of a Haar wavelet centered at the point p
with the given width. The wavelet is oriented along the X axis
...
...
@@ -113,8 +125,8 @@ namespace dlib
/*!
requires
- get_rect(img).contains(centered_rect(p,width,width)) == true
- integral_image_type == a type that implements the integral_image
interface
defined above
- integral_image_type == a type that implements the integral_image
_generic
interface
defined above
ensures
- returns the response of a Haar wavelet centered at the point p
with the given width in the given image. The wavelet is oriented
...
...
dlib/test/image.cpp
View file @
93121255
...
...
@@ -703,13 +703,14 @@ namespace
}
template
<
typename
T
,
typename
pixel_type
>
void
test_integral_image
(
)
{
dlib
::
rand
rnd
;
array2d
<
unsigned
char
>
img
;
integral_image
int_img
;
array2d
<
pixel_type
>
img
;
integral_image
_generic
<
T
>
int_img
;
int_img
.
load
(
img
);
DLIB_TEST
(
int_img
.
nr
()
==
0
);
...
...
@@ -725,7 +726,7 @@ namespace
{
for
(
long
c
=
0
;
c
<
img
.
nc
();
++
c
)
{
img
[
r
][
c
]
=
rnd
.
get_random_8bit_number
();
img
[
r
][
c
]
=
(
int
)
rnd
.
get_random_8bit_number
()
-
100
;
}
}
...
...
@@ -734,14 +735,14 @@ namespace
DLIB_TEST
(
int_img
.
nc
()
==
img
.
nc
());
// make 200 random rectangles
for
(
int
j
=
0
;
j
<
2
00
;
++
j
)
for
(
int
j
=
0
;
j
<
5
00
;
++
j
)
{
point
p1
(
rnd
.
get_random_32bit_number
()
%
img
.
nc
(),
rnd
.
get_random_32bit_number
()
%
img
.
nr
());
point
p2
(
rnd
.
get_random_32bit_number
()
%
img
.
nc
(),
rnd
.
get_random_32bit_number
()
%
img
.
nr
());
rectangle
rect
(
p1
,
p2
);
DLIB_TEST
(
int_img
.
get_sum_of_area
(
rect
)
==
sum
(
subm
(
matrix_cast
<
long
>
(
array_to_matrix
(
img
)),
rect
)));
DLIB_TEST
(
int_img
.
get_sum_of_area
(
rect
)
==
sum
(
subm
(
matrix_cast
<
T
>
(
array_to_matrix
(
img
)),
rect
)));
rect
=
rectangle
(
p1
,
p1
);
DLIB_TEST
(
int_img
.
get_sum_of_area
(
rect
)
==
sum
(
subm
(
matrix_cast
<
long
>
(
array_to_matrix
(
img
)),
rect
)));
DLIB_TEST
(
int_img
.
get_sum_of_area
(
rect
)
==
sum
(
subm
(
matrix_cast
<
T
>
(
array_to_matrix
(
img
)),
rect
)));
}
}
...
...
@@ -763,7 +764,10 @@ namespace
)
{
image_test
();
test_integral_image
();
test_integral_image
<
long
,
unsigned
char
>
();
test_integral_image
<
double
,
int
>
();
test_integral_image
<
long
,
unsigned
char
>
();
test_integral_image
<
double
,
float
>
();
}
}
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