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
3c04d06a
Commit
3c04d06a
authored
Sep 29, 2011
by
Davis King
Browse files
Changed the behavior of gaussian_blur() to make it a little more user friendly.
parent
128cc0cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
17 deletions
+26
-17
dlib/image_transforms/spatial_filtering.h
dlib/image_transforms/spatial_filtering.h
+20
-12
dlib/image_transforms/spatial_filtering_abstract.h
dlib/image_transforms/spatial_filtering_abstract.h
+6
-5
No files found.
dlib/image_transforms/spatial_filtering.h
View file @
3c04d06a
...
...
@@ -369,33 +369,41 @@ namespace dlib
>
matrix
<
T
,
0
,
1
>
create_gaussian_filter
(
double
sigma
,
int
size
int
max_
size
)
/*!
requires
- sigma > 0
- size > 0
- size is an odd number
-
max_
size > 0
-
max_
size is an odd number
ensures
- returns a separable Gaussian filter F such that:
- is_vector(F) == true
- F.size()
=
= size
- F.size()
<
=
max_
size
- F is suitable for use with the spatially_filter_image_separable() routine
and its use with this function corresponds to running a Gaussian filter
of sigma width over an image.
!*/
{
DLIB_ASSERT
(
sigma
>
0
&&
size
>
0
&&
(
size
%
2
)
==
1
,
DLIB_ASSERT
(
sigma
>
0
&&
max_
size
>
0
&&
(
max_
size
%
2
)
==
1
,
"
\t
matrix<T,0,1> create_gaussian_filter()"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
sigma: "
<<
sigma
<<
"
\n\t
size: "
<<
size
<<
"
\n\t
max_
size: "
<<
max_
size
);
matrix
<
double
,
0
,
1
>
f
(
size
);
// Adjust the size so that the ratio of the gaussian values isn't huge.
// This only matters when T is an integer type. However, we do it for
// all types so that the behavior of this function is always relatively
// the same.
while
(
gaussian
(
0
,
sigma
)
/
gaussian
(
max_size
/
2
,
sigma
)
>
50
)
--
max_size
;
matrix
<
double
,
0
,
1
>
f
(
max_size
);
for
(
long
i
=
0
;
i
<
f
.
size
();
++
i
)
{
f
(
i
)
=
gaussian
(
i
-
size
/
2
,
sigma
);
f
(
i
)
=
gaussian
(
i
-
max_
size
/
2
,
sigma
);
}
if
(
is_float_type
<
T
>::
value
==
false
)
...
...
@@ -419,22 +427,22 @@ namespace dlib
const
in_image_type
&
in_img
,
out_image_type
&
out_img
,
double
sigma
=
1
,
int
size
=
7
int
max_
size
=
1001
)
{
DLIB_ASSERT
(
sigma
>
0
&&
size
>
0
&&
(
size
%
2
)
==
1
&&
DLIB_ASSERT
(
sigma
>
0
&&
max_
size
>
0
&&
(
max_
size
%
2
)
==
1
&&
is_same_object
(
in_img
,
out_img
)
==
false
,
"
\t
void gaussian_blur()"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
sigma: "
<<
sigma
<<
"
\n\t
size: "
<<
size
<<
"
\n\t
max_
size: "
<<
max_
size
<<
"
\n\t
is_same_object(in_img,out_img): "
<<
is_same_object
(
in_img
,
out_img
)
);
typedef
typename
pixel_traits
<
typename
out_image_type
::
type
>::
basic_pixel_type
type
;
typedef
typename
promote
<
type
>::
type
ptype
;
const
matrix
<
ptype
,
0
,
1
>&
filt
=
create_gaussian_filter
<
ptype
>
(
sigma
,
size
);
const
matrix
<
ptype
,
0
,
1
>&
filt
=
create_gaussian_filter
<
ptype
>
(
sigma
,
max_
size
);
ptype
scale
=
sum
(
filt
);
scale
=
scale
*
scale
;
...
...
dlib/image_transforms/spatial_filtering_abstract.h
View file @
3c04d06a
...
...
@@ -225,7 +225,7 @@ namespace dlib
const
in_image_type
&
in_img
,
out_image_type
&
out_img
,
double
sigma
=
1
,
int
size
=
7
int
max_
size
=
1001
);
/*!
requires
...
...
@@ -235,12 +235,13 @@ namespace dlib
- pixel_traits<typename out_image_type::type>::has_alpha == false
- is_same_object(in_img, out_img) == false
- sigma > 0
- size > 0
- size is an odd number
-
max_
size > 0
-
max_
size is an odd number
ensures
- Filters in_img with a Gaussian filter of sigma width. The actual spatial filter will
be applied to pixel blocks that are size wide and size tall. The results are stored
into #out_img.
be applied to pixel blocks that are at most max_size wide and max_size tall (note that
this function will automatically select a smaller block size as appropriate). The
results are stored into #out_img.
- Pixel values are stored into out_img using the assign_pixel() function and therefore
any applicable color space conversion or value saturation is performed.
- if (pixel_traits<typename in_image_type::type>::grayscale == false) then
...
...
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