Commit 79f8e146 authored by Davis King's avatar Davis King

Added pyramid_down_generic

parent 2ec475cc
......@@ -2332,6 +2332,126 @@ namespace dlib
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
unsigned int N
>
class pyramid_down_generic : noncopyable
{
public:
COMPILE_TIME_ASSERT(N > 1);
template <typename T>
vector<double,2> point_down (
const vector<T,2>& p
) const
{
const double ratio = (N-1.0)/N;
return p*ratio;
}
template <typename T>
vector<double,2> point_up (
const vector<T,2>& p
) const
{
const double ratio = N/(N-1.0);
return p*ratio;
}
// -----------------------------
template <typename T>
vector<double,2> point_down (
const vector<T,2>& p,
unsigned int levels
) const
{
vector<double,2> temp = p;
for (unsigned int i = 0; i < levels; ++i)
temp = point_down(temp);
return temp;
}
template <typename T>
vector<double,2> point_up (
const vector<T,2>& p,
unsigned int levels
) const
{
vector<double,2> temp = p;
for (unsigned int i = 0; i < levels; ++i)
temp = point_up(temp);
return temp;
}
// -----------------------------
rectangle rect_up (
const rectangle& rect
) const
{
return rectangle(point_up(rect.tl_corner()), point_up(rect.br_corner()));
}
rectangle rect_up (
const rectangle& rect,
unsigned int levels
) const
{
return rectangle(point_up(rect.tl_corner(),levels), point_up(rect.br_corner(),levels));
}
// -----------------------------
rectangle rect_down (
const rectangle& rect
) const
{
return rectangle(point_down(rect.tl_corner()), point_down(rect.br_corner()));
}
rectangle rect_down (
const rectangle& rect,
unsigned int levels
) const
{
return rectangle(point_down(rect.tl_corner(),levels), point_down(rect.br_corner(),levels));
}
template <
typename in_image_type,
typename out_image_type
>
void operator() (
const in_image_type& original,
out_image_type& down
) const
{
// make sure requires clause is not broken
DLIB_ASSERT(is_same_object(original, down) == false,
"\t void pyramid_down_generic::operator()"
<< "\n\t is_same_object(original, down): " << is_same_object(original, down)
<< "\n\t this: " << this
);
COMPILE_TIME_ASSERT( pixel_traits<typename in_image_type::type>::has_alpha == false );
COMPILE_TIME_ASSERT( pixel_traits<typename out_image_type::type>::has_alpha == false );
down.set_size(((N-1)*original.nr())/N,
((N-1)*original.nc())/N);
resize_image(original, down);
}
};
template <>
class pyramid_down_generic<2> : public pyramid_down {};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
......
......@@ -188,6 +188,24 @@ namespace dlib
!*/
};
// ----------------------------------------------------------------------------------------
template <
unsigned int N
>
class pyramid_down_generic : noncopyable
{
/*!
REQUIREMENTS ON N
N > 1
WHAT THIS OBJECT REPRESENTS
This is a function object with an interface identical to pyramid_down
(defined at the top of this file) except that it downsamples images at a
ratio of N to N-1 instead of 2 to 1.
!*/
};
// ----------------------------------------------------------------------------------------
class pyramid_disable : noncopyable
......
......@@ -335,6 +335,8 @@ void test_pyramid_down_small_sizes()
test_pyramid_down_small_sizes<pyramid_down_5_4>();
dlog << LINFO << "call test_pyramid_down_small_sizes<pyramid_disable>();";
test_pyramid_down_small_sizes<pyramid_disable>();
dlog << LINFO << "call test_pyramid_down_small_sizes<pyramid_down_generic<3> >();";
test_pyramid_down_small_sizes<pyramid_down_generic<3> >();
print_spinner();
dlog << LINFO << "call test_pyramid_down_rgb2<pyramid_down>();";
......@@ -352,6 +354,10 @@ void test_pyramid_down_small_sizes()
dlog << LINFO << "call test_pyramid_down_rgb2<pyramid_down_5_4>();";
test_pyramid_down_rgb2<pyramid_down_5_4>();
print_spinner();
dlog << LINFO << "call test_pyramid_down_rgb2<pyramid_down_generic<5> >();";
test_pyramid_down_rgb2<pyramid_down_generic<5> >();
print_spinner();
dlog << LINFO << "call test_pyramid_down_grayscale2<pyramid_down>();";
......@@ -368,6 +374,10 @@ void test_pyramid_down_small_sizes()
print_spinner();
dlog << LINFO << "call test_pyramid_down_grayscale2<pyramid_down_5_4>();";
test_pyramid_down_grayscale2<pyramid_down_5_4>();
print_spinner();
dlog << LINFO << "call test_pyramid_down_grayscale2<pyramid_down_generic<6> >();";
test_pyramid_down_grayscale2<pyramid_down_generic<6> >();
}
} a;
......
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