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
0639831a
Commit
0639831a
authored
Jul 13, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some functions for running a 3x3 separable filter on part of an image.
parent
63ca672c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
174 additions
and
2 deletions
+174
-2
spatial_filtering.h
dlib/image_transforms/spatial_filtering.h
+102
-2
spatial_filtering_abstract.h
dlib/image_transforms/spatial_filtering_abstract.h
+72
-0
No files found.
dlib/image_transforms/spatial_filtering.h
View file @
0639831a
...
...
@@ -104,10 +104,110 @@ namespace dlib
// ----------------------------------------------------------------------------------------
}
template
<
long
size
,
typename
T
,
typename
in_image_type
>
inline
void
separable_3x3_filter_block_grayscale
(
T
(
&
block
)[
size
][
size
],
const
in_image_type
&
img
,
const
long
&
r
,
const
long
&
c
,
const
T
&
fe1
,
// separable filter end
const
T
&
fm
,
// separable filter middle
const
T
&
fe2
// separable filter end 2
)
{
// 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
),
"
\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
)
);
#endif // DLIB_SPATIAL_FILTERINg_H_
T
row_filt
[
size
+
2
][
size
];
for
(
long
rr
=
0
;
rr
<
size
+
2
;
++
rr
)
{
for
(
long
cc
=
0
;
cc
<
size
;
++
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
+
get_pixel_intensity
(
img
[
r
+
rr
-
1
][
c
+
cc
+
1
])
*
fe2
;
}
}
for
(
long
rr
=
0
;
rr
<
size
;
++
rr
)
{
for
(
long
cc
=
0
;
cc
<
size
;
++
cc
)
{
block
[
rr
][
cc
]
=
(
row_filt
[
rr
][
cc
]
*
fe1
+
row_filt
[
rr
+
1
][
cc
]
*
fm
+
row_filt
[
rr
+
2
][
cc
]
*
fe2
)
/
256
;
}
}
}
// ----------------------------------------------------------------------------------------
template
<
long
size
,
typename
T
,
typename
U
,
typename
in_image_type
>
inline
void
separable_3x3_filter_block_rgb
(
T
(
&
block
)[
size
][
size
],
const
in_image_type
&
img
,
const
long
&
r
,
const
long
&
c
,
const
U
&
fe1
,
// separable filter end
const
U
&
fm
,
// separable filter middle
const
U
&
fe2
// separable filter end 2
)
{
// 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
),
"
\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
)
);
T
row_filt
[
size
+
2
][
size
];
for
(
long
rr
=
0
;
rr
<
size
+
2
;
++
rr
)
{
for
(
long
cc
=
0
;
cc
<
size
;
++
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
;
row_filt
[
rr
][
cc
].
blue
=
img
[
r
+
rr
-
1
][
c
+
cc
-
1
].
blue
*
fe1
+
img
[
r
+
rr
-
1
][
c
+
cc
].
blue
*
fm
+
img
[
r
+
rr
-
1
][
c
+
cc
+
1
].
blue
*
fe2
;
}
}
for
(
long
rr
=
0
;
rr
<
size
;
++
rr
)
{
for
(
long
cc
=
0
;
cc
<
size
;
++
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
;
block
[
rr
][
cc
].
blue
=
row_filt
[
rr
][
cc
].
blue
*
fe1
+
row_filt
[
rr
+
1
][
cc
].
blue
*
fm
+
row_filt
[
rr
+
2
][
cc
].
blue
*
fe2
;
}
}
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_SPATIAL_FILTERINg_H_
dlib/image_transforms/spatial_filtering_abstract.h
View file @
0639831a
...
...
@@ -8,6 +8,8 @@
namespace
dlib
{
// ----------------------------------------------------------------------------------------
template
<
typename
in_image_type
,
typename
out_image_type
,
...
...
@@ -51,6 +53,76 @@ namespace dlib
- #out_img.nr() == in_img.nr()
!*/
// ----------------------------------------------------------------------------------------
template
<
long
size
,
typename
T
,
typename
in_image_type
>
inline
void
separable_3x3_filter_block_grayscale
(
T
(
&
block
)[
size
][
size
],
const
in_image_type
&
img
,
const
long
&
r
,
const
long
&
c
,
const
T
&
fe1
,
const
T
&
fm
,
const
T
&
fe2
);
/*!
requires
- 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)
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).
- 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
spatial filter is thus:
fe1*fe1 fe1*fm fe2*fe1
fe1*fm fm*fm fe2*fm
fe1*fe2 fe2*fm fe2*fe2
!*/
// ----------------------------------------------------------------------------------------
template
<
long
size
,
typename
T
,
typename
U
,
typename
in_image_type
>
inline
void
separable_3x3_filter_block_rgb
(
T
(
&
block
)[
size
][
size
],
const
in_image_type
&
img
,
const
long
&
r
,
const
long
&
c
,
const
U
&
fe1
,
const
U
&
fm
,
const
U
&
fe2
);
/*!
requires
- pixel_traits<typename in_image_type::type>::rgb == true
- 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)
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).
- 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
spatial filter is thus:
fe1*fe1 fe1*fm fe2*fe1
fe1*fm fm*fm fe2*fm
fe1*fe2 fe2*fm fe2*fe2
!*/
// ----------------------------------------------------------------------------------------
}
...
...
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