contrib/brl/bbas/bsta/algo/bsta_mean_shift.h
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/algo/bsta_mean_shift.h
00002 #ifndef bsta_mean_shift_h_
00003 #define bsta_mean_shift_h_
00004 //:
00005 // \file
00006 // \brief Classes to run mean shift algorithm on data distributions to find its modes
00007 //        Implements mean shift with a flat kernel of fixed bandwidth_
00008 //
00009 // \author Ozge C. Ozcanli
00010 // \date February 10, 2009
00011 //
00012 // \verbatim
00013 //  Modifications
00014 //   (none yet)
00015 // \endverbatim
00016 //
00017 
00018 #include <bsta/bsta_parzen_sphere.h>
00019 #include <bsta/bsta_mixture.h>
00020 #include <bsta/bsta_attributes.h>
00021 #include <bsta/bsta_gaussian_sphere.h>
00022 #include <bsta/bsta_gaussian_full.h>
00023 #include <vnl/vnl_random.h>
00024 #include <vcl_utility.h>
00025 #include <bsta/algo/bsta_sample_set.h>
00026 
00027 template <class T, unsigned n>
00028 class bsta_mean_shift
00029 {
00030  public:
00031   typedef typename bsta_parzen_sphere<T,n>::vector_type vector_;
00032   //typedef typename bsta_parzen_sphere<T,n>::covar_type var_t;
00033 
00034   //Constructor
00035   bsta_mean_shift() : max_iter_(1000) {}
00036 
00037   //: initializes seeds randomly and finds all the resulting modes
00038   //  \p epsilon : the difference required for updating to come to a halt
00039   //  \p percentage: the percentage of the sample set to initialize as seed
00040   bool find_modes(bsta_sample_set<T,n>& set, vnl_random & rng, float percentage = 10.0f, T epsilon = 10e-3);
00041 
00042   //: use all the samples to get its mode, no need for random seed picking
00043   bool find_modes(bsta_sample_set<T,n>& set, T epsilon = 10e-3);
00044 
00045   //: trim modes that are within epsilon distance to each other
00046   //  \p epsilon : the difference required for two modes to be merged
00047   bool trim_modes(bsta_sample_set<T,n>& set, T epsilon = 10e-3);
00048 
00049   //: merge the mode with samples less than cnt to one of the modes depending on its samples mean-shift paths
00050   bool merge_modes(bsta_sample_set<T,n>& set, int cnt, T epsilon);
00051 
00052   void clear() { modes_.clear(); }
00053 
00054   unsigned size() const { return modes_.size(); }
00055   vcl_vector<vector_ >& modes() { return modes_; }
00056 
00057   //: the default for maximum iterations to quit search starting from a seed is 1000
00058   void set_max_iter(unsigned iter) { max_iter_ = iter; }
00059 
00060  private:
00061 
00062   vcl_vector<vector_ > modes_;  // modes of the distribution
00063 
00064   unsigned max_iter_;
00065 };
00066 
00067 #endif // bsta_mean_shift_h_