Added the randomly_sample_image_features() routine.

This commit is contained in:
Davis King 2011-12-26 10:17:18 -05:00
parent 63e17485c1
commit 2dcc0253ac
3 changed files with 114 additions and 0 deletions

View File

@ -6,6 +6,7 @@
#include "statistics/statistics.h"
#include "statistics/dpca.h"
#include "statistics/random_subset_selector.h"
#include "statistics/image_feature_sampling.h"
#endif // DLIB_STATISTICs_H_

View File

@ -0,0 +1,69 @@
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_IMAGE_FEATURE_SaMPLING_H__
#define DLIB_IMAGE_FEATURE_SaMPLING_H__
#include "image_feature_sampling_abstract.h"
#include "../statistics.h"
#include "../image_transforms.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
template <
typename image_array_type,
typename feature_extractor_type,
typename pyramid_type
>
random_subset_selector<typename feature_extractor_type::descriptor_type> randomly_sample_image_features (
const image_array_type& images,
const pyramid_type& pyr,
const feature_extractor_type& fe_,
unsigned long num
)
{
feature_extractor_type fe;
fe.copy_configuration(fe_);
random_subset_selector<typename feature_extractor_type::descriptor_type> basis;
basis.set_max_size(num);
typedef typename image_array_type::type image_type;
image_type temp_img, temp_img2;
for (unsigned long i = 0; i < images.size(); ++i)
{
assign_image(temp_img, images[i]);
while (temp_img.nr() > 10 && temp_img.nc() > 10)
{
fe.load(temp_img);
for (long r = 0; r < fe.nr(); ++r)
{
for (long c = 0; c < fe.nc(); ++c)
{
if (basis.next_add_accepts())
{
basis.add(fe(r,c));
}
else
{
basis.add();
}
}
}
pyr(temp_img, temp_img2);
temp_img2.swap(temp_img);
}
}
return basis;
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_IMAGE_FEATURE_SaMPLING_H__

View File

@ -0,0 +1,44 @@
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_IMAGE_FEATURE_SaMPLING_ABSTRACT_H__
#ifdef DLIB_IMAGE_FEATURE_SaMPLING_ABSTRACT_H__
#include "random_subset_selector_abstract.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
template <
typename image_array_type,
typename feature_extractor_type,
typename pyramid_type
>
random_subset_selector<typename feature_extractor_type::descriptor_type> randomly_sample_image_features (
const image_array_type& images,
const pyramid_type& pyr,
const feature_extractor_type& fe,
unsigned long num
);
/*!
requires
- pyramid_type == a type compatible with the image pyramid objects defined
in dlib/image_transforms/image_pyramid_abstract.h
- feature_extractor_type == a local image feature extractor type such as the
dlib::hog_image
- image_array_type == an implementation of dlib/array/array_kernel_abstract.h
and it must contain image objects which can be passed to pyr() and fe.load()
ensures
- creates an image pyramid for each image in images and performs feature
extraction on each pyramid level. Then selects a random subsample of at
most num local feature vectors and returns it.
!*/
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_IMAGE_FEATURE_SaMPLING_ABSTRACT_H__