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
88f8a525
Commit
88f8a525
authored
Jan 01, 2012
by
Davis King
Browse files
Moved sum_filter() into the file with all the other filtering routines.
parent
10307342
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
119 deletions
+120
-119
dlib/image_processing/scan_image.h
dlib/image_processing/scan_image.h
+1
-94
dlib/image_processing/scan_image_abstract.h
dlib/image_processing/scan_image_abstract.h
+0
-25
dlib/image_transforms/spatial_filtering.h
dlib/image_transforms/spatial_filtering.h
+94
-0
dlib/image_transforms/spatial_filtering_abstract.h
dlib/image_transforms/spatial_filtering_abstract.h
+25
-0
No files found.
dlib/image_processing/scan_image.h
View file @
88f8a525
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include "../algs.h"
#include "../algs.h"
#include "../rand.h"
#include "../rand.h"
#include "../array2d.h"
#include "../array2d.h"
#include "../image_transforms/spatial_filtering.h"
namespace
dlib
namespace
dlib
{
{
...
@@ -107,100 +108,6 @@ namespace dlib
...
@@ -107,100 +108,6 @@ namespace dlib
return
static_cast
<
double
>
(
temp
);
return
static_cast
<
double
>
(
temp
);
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_type1
,
typename
image_type2
>
void
sum_filter
(
const
image_type1
&
img
,
image_type2
&
out
,
const
rectangle
&
rect
)
{
DLIB_ASSERT
(
img
.
nr
()
==
out
.
nr
()
&&
img
.
nc
()
==
out
.
nc
(),
"
\t
void sum_filter()"
<<
"
\n\t
Invalid arguments given to this function."
<<
"
\n\t
img.nr(): "
<<
img
.
nr
()
<<
"
\n\t
img.nc(): "
<<
img
.
nc
()
<<
"
\n\t
out.nr(): "
<<
out
.
nr
()
<<
"
\n\t
out.nc(): "
<<
out
.
nc
()
);
typedef
typename
image_type1
::
type
pixel_type
;
typedef
typename
promote
<
pixel_type
>::
type
ptype
;
std
::
vector
<
ptype
>
column_sum
;
column_sum
.
resize
(
img
.
nc
()
+
rect
.
width
(),
0
);
const
long
top
=
-
1
+
rect
.
top
();
const
long
bottom
=
-
1
+
rect
.
bottom
();
long
left
=
rect
.
left
()
-
1
;
// initialize column_sum at row -1
for
(
unsigned
long
j
=
0
;
j
<
column_sum
.
size
();
++
j
)
{
rectangle
strip
(
left
,
top
,
left
,
bottom
);
strip
=
strip
.
intersect
(
get_rect
(
img
));
if
(
!
strip
.
is_empty
())
{
column_sum
[
j
]
=
sum
(
matrix_cast
<
ptype
>
(
subm
(
array_to_matrix
(
img
),
strip
)));
}
++
left
;
}
const
rectangle
area
=
get_rect
(
img
);
// save width to avoid computing them over and over
const
long
width
=
rect
.
width
();
// Now do the bulk of the scanning work.
for
(
long
r
=
0
;
r
<
img
.
nr
();
++
r
)
{
// set to sum at point(-1,r). i.e. should be equal to sum_of_rects_in_images(images, rects, point(-1,r))
// We compute it's value in the next loop.
ptype
cur_sum
=
0
;
// Update the first part of column_sum since we only work on the c+width part of column_sum
// in the main loop.
const
long
top
=
r
+
rect
.
top
()
-
1
;
const
long
bottom
=
r
+
rect
.
bottom
();
for
(
long
k
=
0
;
k
<
width
;
++
k
)
{
const
long
right
=
k
-
width
+
rect
.
right
();
const
ptype
br_corner
=
area
.
contains
(
right
,
bottom
)
?
img
[
bottom
][
right
]
:
0
;
const
ptype
tr_corner
=
area
.
contains
(
right
,
top
)
?
img
[
top
][
right
]
:
0
;
// update the sum in this column now that we are on the next row
column_sum
[
k
]
=
column_sum
[
k
]
+
br_corner
-
tr_corner
;
cur_sum
+=
column_sum
[
k
];
}
for
(
long
c
=
0
;
c
<
img
.
nc
();
++
c
)
{
const
long
top
=
r
+
rect
.
top
()
-
1
;
const
long
bottom
=
r
+
rect
.
bottom
();
const
long
right
=
c
+
rect
.
right
();
const
ptype
br_corner
=
area
.
contains
(
right
,
bottom
)
?
img
[
bottom
][
right
]
:
0
;
const
ptype
tr_corner
=
area
.
contains
(
right
,
top
)
?
img
[
top
][
right
]
:
0
;
// update the sum in this column now that we are on the next row
column_sum
[
c
+
width
]
=
column_sum
[
c
+
width
]
+
br_corner
-
tr_corner
;
// add in the new right side of the rect and subtract the old right side.
cur_sum
=
cur_sum
+
column_sum
[
c
+
width
]
-
column_sum
[
c
];
out
[
r
][
c
]
+=
cur_sum
;
}
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
template
<
...
...
dlib/image_processing/scan_image_abstract.h
View file @
88f8a525
...
@@ -10,31 +10,6 @@
...
@@ -10,31 +10,6 @@
namespace
dlib
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
<
template
<
...
...
dlib/image_transforms/spatial_filtering.h
View file @
88f8a525
...
@@ -619,6 +619,100 @@ namespace dlib
...
@@ -619,6 +619,100 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_type1
,
typename
image_type2
>
void
sum_filter
(
const
image_type1
&
img
,
image_type2
&
out
,
const
rectangle
&
rect
)
{
DLIB_ASSERT
(
img
.
nr
()
==
out
.
nr
()
&&
img
.
nc
()
==
out
.
nc
(),
"
\t
void sum_filter()"
<<
"
\n\t
Invalid arguments given to this function."
<<
"
\n\t
img.nr(): "
<<
img
.
nr
()
<<
"
\n\t
img.nc(): "
<<
img
.
nc
()
<<
"
\n\t
out.nr(): "
<<
out
.
nr
()
<<
"
\n\t
out.nc(): "
<<
out
.
nc
()
);
typedef
typename
image_type1
::
type
pixel_type
;
typedef
typename
promote
<
pixel_type
>::
type
ptype
;
std
::
vector
<
ptype
>
column_sum
;
column_sum
.
resize
(
img
.
nc
()
+
rect
.
width
(),
0
);
const
long
top
=
-
1
+
rect
.
top
();
const
long
bottom
=
-
1
+
rect
.
bottom
();
long
left
=
rect
.
left
()
-
1
;
// initialize column_sum at row -1
for
(
unsigned
long
j
=
0
;
j
<
column_sum
.
size
();
++
j
)
{
rectangle
strip
(
left
,
top
,
left
,
bottom
);
strip
=
strip
.
intersect
(
get_rect
(
img
));
if
(
!
strip
.
is_empty
())
{
column_sum
[
j
]
=
sum
(
matrix_cast
<
ptype
>
(
subm
(
array_to_matrix
(
img
),
strip
)));
}
++
left
;
}
const
rectangle
area
=
get_rect
(
img
);
// save width to avoid computing them over and over
const
long
width
=
rect
.
width
();
// Now do the bulk of the scanning work.
for
(
long
r
=
0
;
r
<
img
.
nr
();
++
r
)
{
// set to sum at point(-1,r). i.e. should be equal to sum_of_rects_in_images(images, rects, point(-1,r))
// We compute it's value in the next loop.
ptype
cur_sum
=
0
;
// Update the first part of column_sum since we only work on the c+width part of column_sum
// in the main loop.
const
long
top
=
r
+
rect
.
top
()
-
1
;
const
long
bottom
=
r
+
rect
.
bottom
();
for
(
long
k
=
0
;
k
<
width
;
++
k
)
{
const
long
right
=
k
-
width
+
rect
.
right
();
const
ptype
br_corner
=
area
.
contains
(
right
,
bottom
)
?
img
[
bottom
][
right
]
:
0
;
const
ptype
tr_corner
=
area
.
contains
(
right
,
top
)
?
img
[
top
][
right
]
:
0
;
// update the sum in this column now that we are on the next row
column_sum
[
k
]
=
column_sum
[
k
]
+
br_corner
-
tr_corner
;
cur_sum
+=
column_sum
[
k
];
}
for
(
long
c
=
0
;
c
<
img
.
nc
();
++
c
)
{
const
long
top
=
r
+
rect
.
top
()
-
1
;
const
long
bottom
=
r
+
rect
.
bottom
();
const
long
right
=
c
+
rect
.
right
();
const
ptype
br_corner
=
area
.
contains
(
right
,
bottom
)
?
img
[
bottom
][
right
]
:
0
;
const
ptype
tr_corner
=
area
.
contains
(
right
,
top
)
?
img
[
top
][
right
]
:
0
;
// update the sum in this column now that we are on the next row
column_sum
[
c
+
width
]
=
column_sum
[
c
+
width
]
+
br_corner
-
tr_corner
;
// add in the new right side of the rect and subtract the old right side.
cur_sum
=
cur_sum
+
column_sum
[
c
+
width
]
-
column_sum
[
c
];
out
[
r
][
c
]
+=
cur_sum
;
}
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
}
}
...
...
dlib/image_transforms/spatial_filtering_abstract.h
View file @
88f8a525
...
@@ -311,6 +311,31 @@ namespace dlib
...
@@ -311,6 +311,31 @@ namespace dlib
- #out_img.nr() == in_img.nr()
- #out_img.nr() == in_img.nr()
!*/
!*/
// ----------------------------------------------------------------------------------------
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)
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
}
}
...
...
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