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
b8de7f5a
Commit
b8de7f5a
authored
Oct 02, 2013
by
Davis King
Browse files
Made resize_image() use bilinear interpolation by default and also added
a special version of it that is optimized for this case.
parent
3be34b77
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
3 deletions
+71
-3
dlib/image_transforms/interpolation.h
dlib/image_transforms/interpolation.h
+70
-1
dlib/image_transforms/interpolation_abstract.h
dlib/image_transforms/interpolation_abstract.h
+1
-2
No files found.
dlib/image_transforms/interpolation.h
View file @
b8de7f5a
...
@@ -515,6 +515,75 @@ namespace dlib
...
@@ -515,6 +515,75 @@ namespace dlib
dlib
::
impl
::
helper_resize_image
(
x_scale
,
y_scale
));
dlib
::
impl
::
helper_resize_image
(
x_scale
,
y_scale
));
}
}
// ----------------------------------------------------------------------------------------
// This is an optimized version of resize_image for the case where bilinear
// interpolation is used.
template
<
typename
image_type1
,
typename
image_type2
>
void
resize_image
(
const
image_type1
&
img
,
image_type2
&
out
,
interpolate_bilinear
)
{
typedef
typename
image_type1
::
type
T
;
const
double
x_scale
=
(
img
.
nc
()
-
1
)
/
(
double
)
std
::
max
<
long
>
((
out
.
nc
()
-
1
),
1
);
const
double
y_scale
=
(
img
.
nr
()
-
1
)
/
(
double
)
std
::
max
<
long
>
((
out
.
nr
()
-
1
),
1
);
double
y
=
-
y_scale
;
for
(
long
r
=
0
;
r
<
out
.
nr
();
++
r
)
{
y
+=
y_scale
;
const
long
top
=
static_cast
<
long
>
(
std
::
floor
(
y
));
const
long
bottom
=
std
::
min
(
top
+
1
,
img
.
nr
()
-
1
);
const
double
tb_frac
=
y
-
top
;
double
x
=
-
x_scale
;
if
(
!
pixel_traits
<
T
>::
rgb
)
{
for
(
long
c
=
0
;
c
<
out
.
nc
();
++
c
)
{
x
+=
x_scale
;
const
long
left
=
static_cast
<
long
>
(
std
::
floor
(
x
));
const
long
right
=
std
::
min
(
left
+
1
,
img
.
nc
()
-
1
);
const
double
lr_frac
=
x
-
left
;
double
tl
=
0
,
tr
=
0
,
bl
=
0
,
br
=
0
;
assign_pixel
(
tl
,
img
[
top
][
left
]);
assign_pixel
(
tr
,
img
[
top
][
right
]);
assign_pixel
(
bl
,
img
[
bottom
][
left
]);
assign_pixel
(
br
,
img
[
bottom
][
right
]);
double
temp
=
(
1
-
tb_frac
)
*
((
1
-
lr_frac
)
*
tl
+
lr_frac
*
tr
)
+
tb_frac
*
((
1
-
lr_frac
)
*
bl
+
lr_frac
*
br
);
assign_pixel
(
out
[
r
][
c
],
temp
);
}
}
else
{
for
(
long
c
=
0
;
c
<
out
.
nc
();
++
c
)
{
x
+=
x_scale
;
const
long
left
=
static_cast
<
long
>
(
std
::
floor
(
x
));
const
long
right
=
std
::
min
(
left
+
1
,
img
.
nc
()
-
1
);
const
double
lr_frac
=
x
-
left
;
const
T
tl
=
img
[
top
][
left
];
const
T
tr
=
img
[
top
][
right
];
const
T
bl
=
img
[
bottom
][
left
];
const
T
br
=
img
[
bottom
][
right
];
vector_to_pixel
(
out
[
r
][
c
],
(
1
-
tb_frac
)
*
((
1
-
lr_frac
)
*
pixel_to_vector
<
double
>
(
tl
)
+
lr_frac
*
pixel_to_vector
<
double
>
(
tr
))
+
tb_frac
*
((
1
-
lr_frac
)
*
pixel_to_vector
<
double
>
(
bl
)
+
lr_frac
*
pixel_to_vector
<
double
>
(
br
)));
}
}
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
template
<
...
@@ -533,7 +602,7 @@ namespace dlib
...
@@ -533,7 +602,7 @@ namespace dlib
<<
"
\n\t
is_same_object(in_img, out_img): "
<<
is_same_object
(
in_img
,
out_img
)
<<
"
\n\t
is_same_object(in_img, out_img): "
<<
is_same_object
(
in_img
,
out_img
)
);
);
resize_image
(
in_img
,
out_img
,
interpolate_
quadratic
());
resize_image
(
in_img
,
out_img
,
interpolate_
bilinear
());
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
dlib/image_transforms/interpolation_abstract.h
View file @
b8de7f5a
...
@@ -393,8 +393,7 @@ namespace dlib
...
@@ -393,8 +393,7 @@ namespace dlib
- The size of out_img is not modified. I.e.
- The size of out_img is not modified. I.e.
- #out_img.nr() == out_img.nr()
- #out_img.nr() == out_img.nr()
- #out_img.nc() == out_img.nc()
- #out_img.nc() == out_img.nc()
- uses the interpolate_quadratic object to perform the necessary pixel
- Uses the bilinear interpolation to perform the necessary pixel interpolation.
interpolation.
!*/
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
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