Commit e340f1cb authored by Davis King's avatar Davis King

Added an overload of partition_pixels() that provides multiple output thresholds.

parent 69a53cc9
This diff is collapsed.
......@@ -34,6 +34,35 @@ namespace dlib
deviations between each pixel and the mean of its group is minimized.
!*/
template <
typename image_type,
typename ...T
>
void partition_pixels (
const image_type& img,
typename pixel_traits<typename image_traits<image_type>::pixel_type>::basic_pixel_type& pix_thresh,
T&& ...more_thresholds
);
/*!
requires
- image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
- pixel_traits<typename image_traits<image_type>::pixel_type>::has_alpha == false
- more_thresholds == a bunch of parameters of the same type as pix_thresh.
ensures
- This version of partition_pixels() finds multiple partitions rather than just
one partition. It does this by first partitioning the pixels just as the
above partition_pixels(img) does. Then it forms a new image with only pixels
>= that first partition value and recursively partitions this new image.
However, the recursion is implemented in an efficient way which is faster than
explicitly forming these images and calling partition_pixels(), but the
output is the same as if you did. For example, suppose you called
partition_pixels(img, t1, t2, t3). Then we would have:
- t1 == partition_pixels(img)
- t2 == partition_pixels(an image with only pixels with values >= t1 in it)
- t3 == partition_pixels(an image with only pixels with values >= t2 in it)
!*/
// ----------------------------------------------------------------------------------------
template <
......
......@@ -1904,10 +1904,39 @@ namespace
p = rnd.get_random_8bit_number();
DLIB_TEST(simple_partition_pixels(img) == partition_pixels(img));
DLIB_TEST(simple_partition_pixels(img) == impl::partition_pixels_float(img));
unsigned char thresh;
impl::partition_pixels_float(img,thresh);
DLIB_TEST(simple_partition_pixels(img) == thresh);
matrix<float> fimg = matrix_cast<float>(img);
DLIB_TEST(simple_partition_pixels(img) == partition_pixels(fimg));
std::vector<unsigned char> tmp;
for (auto& v : img)
if (v >= thresh)
tmp.push_back(v);
matrix<unsigned char> img2 = mat(tmp);
unsigned char thresh2;
impl::partition_pixels_float(img,thresh, thresh2);
DLIB_TEST(simple_partition_pixels(img) == thresh);
DLIB_TEST(simple_partition_pixels(img2) == thresh2);
partition_pixels(img,thresh, thresh2);
DLIB_TEST(simple_partition_pixels(img) == thresh);
DLIB_TEST(simple_partition_pixels(img2) == thresh2);
std::vector<float> ftmp;
for (auto& v : fimg)
if (v >= thresh)
ftmp.push_back(v);
matrix<float> fimg2 = mat(ftmp);
float fthresh, fthresh2;
partition_pixels(fimg,fthresh, fthresh2);
DLIB_TEST(simple_partition_pixels(img) == fthresh);
DLIB_TEST(simple_partition_pixels(img2) == fthresh2);
}
......@@ -1919,10 +1948,42 @@ namespace
p = rnd.get_random_8bit_number();
DLIB_TEST(simple_partition_pixels(img) == partition_pixels(img));
DLIB_TEST(simple_partition_pixels(img) == impl::partition_pixels_float(img));
unsigned char thresh;
impl::partition_pixels_float(img,thresh);
DLIB_TEST(simple_partition_pixels(img) == thresh);
matrix<float> fimg = matrix_cast<float>(img);
DLIB_TEST(simple_partition_pixels(img) == partition_pixels(fimg));
std::vector<unsigned char> tmp;
for (auto& v : img)
if (v >= thresh)
tmp.push_back(v);
matrix<unsigned char> img2 = mat(tmp);
unsigned char thresh2;
impl::partition_pixels_float(img,thresh, thresh2);
DLIB_TEST(simple_partition_pixels(img) == thresh);
DLIB_TEST(simple_partition_pixels(img2) == thresh2);
partition_pixels(img,thresh, thresh2);
DLIB_TEST(simple_partition_pixels(img) == thresh);
DLIB_TEST(simple_partition_pixels(img2) == thresh2);
std::vector<float> ftmp;
for (auto& v : fimg)
if (v >= thresh)
ftmp.push_back(v);
matrix<float> fimg2 = mat(ftmp);
float fthresh, fthresh2;
partition_pixels(fimg,fthresh, fthresh2);
DLIB_TEST(simple_partition_pixels(img) == fthresh);
DLIB_TEST(simple_partition_pixels(img2) == fthresh2);
}
}
......
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