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
39ce5a4f
Commit
39ce5a4f
authored
Mar 17, 2012
by
Davis King
Browse files
Added the pyramid_up() routine.
parent
631854fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
157 additions
and
0 deletions
+157
-0
dlib/image_transforms/interpolation.h
dlib/image_transforms/interpolation.h
+98
-0
dlib/image_transforms/interpolation_abstract.h
dlib/image_transforms/interpolation_abstract.h
+59
-0
No files found.
dlib/image_transforms/interpolation.h
View file @
39ce5a4f
...
...
@@ -563,6 +563,104 @@ namespace dlib
assign_image
(
out_img
,
flipud
(
array_to_matrix
(
in_img
)));
}
// ----------------------------------------------------------------------------------------
namespace
impl
{
class
helper_pyramid_up
{
public:
helper_pyramid_up
(
double
x_scale_
,
double
y_scale_
,
const
dlib
::
vector
<
double
,
2
>
offset_
)
:
x_scale
(
x_scale_
),
y_scale
(
y_scale_
),
offset
(
offset_
)
{}
dlib
::
vector
<
double
,
2
>
operator
()
(
const
dlib
::
vector
<
double
,
2
>&
p
)
const
{
return
dlib
::
vector
<
double
,
2
>
((
p
.
x
()
-
offset
.
x
())
*
x_scale
,
(
p
.
y
()
-
offset
.
y
())
*
y_scale
);
}
private:
const
double
x_scale
;
const
double
y_scale
;
const
dlib
::
vector
<
double
,
2
>
offset
;
};
}
template
<
typename
image_type
,
typename
pyramid_type
,
typename
interpolation_type
>
void
pyramid_up
(
const
image_type
&
in_img
,
image_type
&
out_img
,
const
pyramid_type
&
pyr
,
unsigned
int
levels
,
const
interpolation_type
&
interp
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
is_same_object
(
in_img
,
out_img
)
==
false
,
"
\t
void pyramid_up()"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
is_same_object(in_img, out_img): "
<<
is_same_object
(
in_img
,
out_img
)
);
if
(
in_img
.
size
()
==
0
)
{
out_img
.
clear
();
return
;
}
if
(
levels
==
0
)
{
assign_image
(
out_img
,
in_img
);
return
;
}
rectangle
rect
=
get_rect
(
in_img
);
rectangle
uprect
=
pyr
.
rect_up
(
rect
,
levels
);
out_img
.
set_size
(
uprect
.
bottom
()
+
1
,
uprect
.
right
()
+
1
);
const
double
x_scale
=
(
rect
.
width
()
-
1
)
/
(
double
)(
uprect
.
width
()
-
1
);
const
double
y_scale
=
(
rect
.
height
()
-
1
)
/
(
double
)(
uprect
.
height
()
-
1
);
transform_image
(
in_img
,
out_img
,
interp
,
dlib
::
impl
::
helper_pyramid_up
(
x_scale
,
y_scale
,
uprect
.
tl_corner
()));
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
,
typename
pyramid_type
>
void
pyramid_up
(
const
image_type
&
in_img
,
image_type
&
out_img
,
const
pyramid_type
&
pyr
,
unsigned
int
levels
=
1
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
is_same_object
(
in_img
,
out_img
)
==
false
,
"
\t
void pyramid_up()"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
is_same_object(in_img, out_img): "
<<
is_same_object
(
in_img
,
out_img
)
);
pyramid_up
(
in_img
,
out_img
,
pyr
,
levels
,
interpolate_quadratic
());
}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/image_transforms/interpolation_abstract.h
View file @
39ce5a4f
...
...
@@ -409,6 +409,65 @@ namespace dlib
- #out_img == a copy of in_img which has been flipped upside down.
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
,
typename
pyramid_type
,
typename
interpolation_type
>
void
pyramid_up
(
const
image_type
&
in_img
,
image_type
&
out_img
,
const
pyramid_type
&
pyr
,
unsigned
int
levels
,
const
interpolation_type
&
interp
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pyramid_type == a type compatible with the image pyramid objects defined
in dlib/image_transforms/image_pyramid_abstract.h
- interpolation_type == interpolate_nearest_neighbor, interpolate_bilinear,
interpolate_quadratic, or a type with a compatible interface.
- is_same_object(in_img, out_img) == false
ensures
- This function inverts the downsampling transformation performed by pyr().
In particular, it attempts to make an image, out_img, which would result
in in_img when downsampled with pyr().
- #out_img == An upsampled copy of in_img. In particular, downsampling
#out_img levels times with pyr() should result in a final image which
looks like in_img.
- uses the supplied interpolation routine interp to perform the necessary
pixel interpolation.
- Note that downsampling an image with pyr() and then upsampling it with
pyramid_up() will not necessarily result in a final image which is
the same size as the original. This is because the exact size of the
original image cannot be determined based on the downsampled image.
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
,
typename
pyramid_type
>
void
pyramid_up
(
const
image_type
&
in_img
,
image_type
&
out_img
,
const
pyramid_type
&
pyr
,
unsigned
int
levels
=
1
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pyramid_type == a type compatible with the image pyramid objects defined
in dlib/image_transforms/image_pyramid_abstract.h
- is_same_object(in_img, out_img) == false
ensures
- performs: pyramid_up(in_img, out_img, pyr, levels, interpolate_quadratic());
!*/
// ----------------------------------------------------------------------------------------
}
...
...
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