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
200ee395
Commit
200ee395
authored
Aug 21, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated the block spatial filtering functions so they can operate on
rectangular areas instead of just square areas.
parent
45fd6ea5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
26 deletions
+30
-26
spatial_filtering.h
dlib/image_transforms/spatial_filtering.h
+20
-18
spatial_filtering_abstract.h
dlib/image_transforms/spatial_filtering_abstract.h
+10
-8
No files found.
dlib/image_transforms/spatial_filtering.h
View file @
200ee395
...
...
@@ -105,12 +105,13 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
long
size
,
long
NR
,
long
NC
,
typename
T
,
typename
in_image_type
>
inline
void
separable_3x3_filter_block_grayscale
(
T
(
&
block
)[
size
][
size
],
T
(
&
block
)[
NR
][
NC
],
const
in_image_type
&
img
,
const
long
&
r
,
const
long
&
c
,
...
...
@@ -121,19 +122,19 @@ namespace dlib
{
// make sure requires clause is not broken
DLIB_ASSERT
(
shrink_rect
(
get_rect
(
img
),
1
).
contains
(
c
,
r
)
&&
shrink_rect
(
get_rect
(
img
),
1
).
contains
(
c
+
size
-
1
,
r
+
size
-
1
),
shrink_rect
(
get_rect
(
img
),
1
).
contains
(
c
+
NC
-
1
,
r
+
NR
-
1
),
"
\t
void separable_3x3_filter_block_grayscale()"
<<
"
\n\t
The sub-window doesn't fit inside the given image."
<<
"
\n\t
get_rect(img): "
<<
get_rect
(
img
)
<<
"
\n\t
(c,r): "
<<
point
(
c
,
r
)
<<
"
\n\t
(c+
size-1,r+size-1): "
<<
point
(
c
+
size
-
1
,
r
+
size
-
1
)
<<
"
\n\t
(c+
NC-1,r+NR-1): "
<<
point
(
c
+
NC
-
1
,
r
+
NR
-
1
)
);
T
row_filt
[
size
+
2
][
size
];
for
(
long
rr
=
0
;
rr
<
size
+
2
;
++
rr
)
T
row_filt
[
NR
+
2
][
NC
];
for
(
long
rr
=
0
;
rr
<
NR
+
2
;
++
rr
)
{
for
(
long
cc
=
0
;
cc
<
size
;
++
cc
)
for
(
long
cc
=
0
;
cc
<
NC
;
++
cc
)
{
row_filt
[
rr
][
cc
]
=
get_pixel_intensity
(
img
[
r
+
rr
-
1
][
c
+
cc
-
1
])
*
fe1
+
get_pixel_intensity
(
img
[
r
+
rr
-
1
][
c
+
cc
])
*
fm
+
...
...
@@ -141,9 +142,9 @@ namespace dlib
}
}
for
(
long
rr
=
0
;
rr
<
size
;
++
rr
)
for
(
long
rr
=
0
;
rr
<
NR
;
++
rr
)
{
for
(
long
cc
=
0
;
cc
<
size
;
++
cc
)
for
(
long
cc
=
0
;
cc
<
NC
;
++
cc
)
{
block
[
rr
][
cc
]
=
(
row_filt
[
rr
][
cc
]
*
fe1
+
row_filt
[
rr
+
1
][
cc
]
*
fm
+
...
...
@@ -156,13 +157,14 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
long
size
,
long
NR
,
long
NC
,
typename
T
,
typename
U
,
typename
in_image_type
>
inline
void
separable_3x3_filter_block_rgb
(
T
(
&
block
)[
size
][
size
],
T
(
&
block
)[
NR
][
NC
],
const
in_image_type
&
img
,
const
long
&
r
,
const
long
&
c
,
...
...
@@ -173,18 +175,18 @@ namespace dlib
{
// make sure requires clause is not broken
DLIB_ASSERT
(
shrink_rect
(
get_rect
(
img
),
1
).
contains
(
c
,
r
)
&&
shrink_rect
(
get_rect
(
img
),
1
).
contains
(
c
+
size
-
1
,
r
+
size
-
1
),
shrink_rect
(
get_rect
(
img
),
1
).
contains
(
c
+
NC
-
1
,
r
+
NR
-
1
),
"
\t
void separable_3x3_filter_block_grayscale()"
<<
"
\n\t
The sub-window doesn't fit inside the given image."
<<
"
\n\t
get_rect(img): "
<<
get_rect
(
img
)
<<
"
\n\t
(c,r): "
<<
point
(
c
,
r
)
<<
"
\n\t
(c+
size-1,r+size-1): "
<<
point
(
c
+
size
-
1
,
r
+
size
-
1
)
<<
"
\n\t
(c+
NC-1,r+NR-1): "
<<
point
(
c
+
NC
-
1
,
r
+
NR
-
1
)
);
T
row_filt
[
size
+
2
][
size
];
for
(
long
rr
=
0
;
rr
<
size
+
2
;
++
rr
)
T
row_filt
[
NR
+
2
][
NC
];
for
(
long
rr
=
0
;
rr
<
NR
+
2
;
++
rr
)
{
for
(
long
cc
=
0
;
cc
<
size
;
++
cc
)
for
(
long
cc
=
0
;
cc
<
NC
;
++
cc
)
{
row_filt
[
rr
][
cc
].
red
=
img
[
r
+
rr
-
1
][
c
+
cc
-
1
].
red
*
fe1
+
img
[
r
+
rr
-
1
][
c
+
cc
].
red
*
fm
+
img
[
r
+
rr
-
1
][
c
+
cc
+
1
].
red
*
fe2
;
row_filt
[
rr
][
cc
].
green
=
img
[
r
+
rr
-
1
][
c
+
cc
-
1
].
green
*
fe1
+
img
[
r
+
rr
-
1
][
c
+
cc
].
green
*
fm
+
img
[
r
+
rr
-
1
][
c
+
cc
+
1
].
green
*
fe2
;
...
...
@@ -192,9 +194,9 @@ namespace dlib
}
}
for
(
long
rr
=
0
;
rr
<
size
;
++
rr
)
for
(
long
rr
=
0
;
rr
<
NR
;
++
rr
)
{
for
(
long
cc
=
0
;
cc
<
size
;
++
cc
)
for
(
long
cc
=
0
;
cc
<
NC
;
++
cc
)
{
block
[
rr
][
cc
].
red
=
row_filt
[
rr
][
cc
].
red
*
fe1
+
row_filt
[
rr
+
1
][
cc
].
red
*
fm
+
row_filt
[
rr
+
2
][
cc
].
red
*
fe2
;
block
[
rr
][
cc
].
green
=
row_filt
[
rr
][
cc
].
green
*
fe1
+
row_filt
[
rr
+
1
][
cc
].
green
*
fm
+
row_filt
[
rr
+
2
][
cc
].
green
*
fe2
;
...
...
dlib/image_transforms/spatial_filtering_abstract.h
View file @
200ee395
...
...
@@ -56,12 +56,13 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
long
size
,
long
NR
,
long
NC
,
typename
T
,
typename
in_image_type
>
inline
void
separable_3x3_filter_block_grayscale
(
T
(
&
block
)[
size
][
size
],
T
(
&
block
)[
NR
][
NC
],
const
in_image_type
&
img
,
const
long
&
r
,
const
long
&
c
,
...
...
@@ -74,10 +75,10 @@ namespace dlib
- in_image_type == is an implementation of array2d/array2d_kernel_abstract.h
- T should be a scalar type
- shrink_rect(get_rect(img),1).contains(c,r)
- shrink_rect(get_rect(img),1).contains(c+
size-1,r+size
-1)
- shrink_rect(get_rect(img),1).contains(c+
NC-1,r+NR
-1)
ensures
- Filters the image in the sub-window of img defined by a rectangle
with its upper left corner at (c,r) and lower right at (c+
size-1,r+size
-1).
with its upper left corner at (c,r) and lower right at (c+
NC-1,r+NR
-1).
- The output of the filter is stored in #block. Note that img will be
interpreted as a grayscale image.
- The filter used is defined by the separable filter [fe1 fm fe2]. So the
...
...
@@ -90,13 +91,14 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
long
size
,
long
NR
,
long
NC
,
typename
T
,
typename
U
,
typename
in_image_type
>
inline
void
separable_3x3_filter_block_rgb
(
T
(
&
block
)[
size
][
size
],
T
(
&
block
)[
NR
][
NC
],
const
in_image_type
&
img
,
const
long
&
r
,
const
long
&
c
,
...
...
@@ -111,10 +113,10 @@ namespace dlib
- T should be a struct with .red .green and .blue members.
- U should be a scalar type
- shrink_rect(get_rect(img),1).contains(c,r)
- shrink_rect(get_rect(img),1).contains(c+
size-1,r+size
-1)
- shrink_rect(get_rect(img),1).contains(c+
NC-1,r+NR
-1)
ensures
- Filters the image in the sub-window of img defined by a rectangle
with its upper left corner at (c,r) and lower right at (c+
size-1,r+size
-1).
with its upper left corner at (c,r) and lower right at (c+
NC-1,r+NR
-1).
- The output of the filter is stored in #block. Note that the filter is applied
to each color component independently.
- The filter used is defined by the separable filter [fe1 fm fe2]. So the
...
...
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