Commit 8c2d87db authored by Davis King's avatar Davis King

Added find_pyramid_down_output_image_size()

parent 9ba4b45f
......@@ -977,6 +977,50 @@ namespace dlib
return (N-1.0)/N;
}
// ----------------------------------------------------------------------------------------
template <unsigned int N>
void find_pyramid_down_output_image_size(
const pyramid_down<N>& pyr,
long& nr,
long& nc
)
{
const double rate = pyramid_rate(pyr);
nr = std::floor(rate*nr);
nc = std::floor(rate*nc);
}
inline void find_pyramid_down_output_image_size(
const pyramid_down<3>& /*pyr*/,
long& nr,
long& nc
)
{
nr = 2*(nr-2)/3;
nc = 2*(nc-2)/3;
}
inline void find_pyramid_down_output_image_size(
const pyramid_down<2>& /*pyr*/,
long& nr,
long& nc
)
{
nr = (nr-3)/2;
nc = (nc-3)/2;
}
inline void find_pyramid_down_output_image_size(
const pyramid_down<1>& /*pyr*/,
long& nr,
long& nc
)
{
nr = 0;
nc = 0;
}
// ----------------------------------------------------------------------------------------
template <
......
......@@ -208,6 +208,26 @@ namespace dlib
- returns (N-1.0)/N
!*/
// ----------------------------------------------------------------------------------------
template <
unsigned int N
>
void find_pyramid_down_output_image_size(
const pyramid_down<N>& pyr,
long& nr,
long& nc
);
/*!
requires
- nr >= 0
- nc >= 0
ensures
- If pyr() were called on an image with nr by nc rows and columns, what would
be the size of the output image? This function finds the size of the output
image and stores it back into #nr and #nc.
!*/
// ----------------------------------------------------------------------------------------
template <
......
......@@ -278,12 +278,37 @@ void test_pyramid_down_grayscale2()
}
}
// ----------------------------------------------------------------------------------------
template <typename pyramid_down_type>
void test_pyr_sizes()
{
dlib::rand rnd;
for (int iter = 0; iter < 20; ++iter)
{
long nr = rnd.get_random_32bit_number()%10+40;
long nc = rnd.get_random_32bit_number()%10+40;
array2d<unsigned char> img(nr,nc), img2;
assign_all_pixels(img,0);
pyramid_down_type pyr;
pyr(img, img2);
find_pyramid_down_output_image_size(pyr, nr, nc);
DLIB_TEST(img2.nr() == nr);
DLIB_TEST(img2.nc() == nc);
}
}
// ----------------------------------------------------------------------------------------
template <typename pyramid_down_type>
void test_pyramid_down_small_sizes()
{
print_spinner();
// just make sure it doesn't get messed up with small images. This test
// is only really useful if asserts are enabled.
pyramid_down_type pyr;
......@@ -378,6 +403,17 @@ void test_pyramid_down_small_sizes()
print_spinner();
dlog << LINFO << "call test_pyramid_down_grayscale2<pyramid_down<6> >();";
test_pyramid_down_grayscale2<pyramid_down<6> >();
test_pyr_sizes<pyramid_down<1>>();
test_pyr_sizes<pyramid_down<2>>();
test_pyr_sizes<pyramid_down<3>>();
test_pyr_sizes<pyramid_down<4>>();
test_pyr_sizes<pyramid_down<5>>();
test_pyr_sizes<pyramid_down<6>>();
test_pyr_sizes<pyramid_down<7>>();
test_pyr_sizes<pyramid_down<8>>();
test_pyr_sizes<pyramid_down<28>>();
}
} 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