Commit 39ce5a4f authored by Davis King's avatar Davis King

Added the pyramid_up() routine.

parent 631854fa
......@@ -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());
}
// ----------------------------------------------------------------------------------------
}
......
......@@ -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());
!*/
// ----------------------------------------------------------------------------------------
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment