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
88f8a525
Commit
88f8a525
authored
Jan 01, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved sum_filter() into the file with all the other filtering routines.
parent
10307342
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
119 deletions
+120
-119
scan_image.h
dlib/image_processing/scan_image.h
+1
-94
scan_image_abstract.h
dlib/image_processing/scan_image_abstract.h
+0
-25
spatial_filtering.h
dlib/image_transforms/spatial_filtering.h
+94
-0
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 @@
#include "../algs.h"
#include "../rand.h"
#include "../array2d.h"
#include "../image_transforms/spatial_filtering.h"
namespace
dlib
{
...
...
@@ -107,100 +108,6 @@ namespace dlib
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
<
...
...
dlib/image_processing/scan_image_abstract.h
View file @
88f8a525
...
...
@@ -10,31 +10,6 @@
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/image_transforms/spatial_filtering.h
View file @
88f8a525
...
...
@@ -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
- #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