Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
BIAS::RANSACPreKnowledge< SolutionType > Class Template Reference

Extension of RANSAC algorithm: user-supplied guesses are evaluated and refined using RANSAC criterions before actually starting the RANSAC algorithm. More...

#include <MathAlgo/RANSACPreKnowledge.hh>

+ Inheritance diagram for BIAS::RANSACPreKnowledge< SolutionType >:
+ Collaboration diagram for BIAS::RANSACPreKnowledge< SolutionType >:

Public Member Functions

void AddDebugLevel (const long int lv)
 
void AddDebugLevel (const std::string &name)
 
virtual void AddGoodGuesses (const std::vector< SolutionType > &Guesses)
 add some guessed solutions which are tested by RANSAC later More...
 
virtual void ClearGuesses ()
 clear all guesses More...
 
bool DebugLevelIsSet (const long int lv) const
 
bool DebugLevelIsSet (const std::string &name) const
 
virtual bool EvaluateSolution (const SolutionType &solution, bool existing_solution_flag, std::vector< bool > &inlier, int &accept_count, double &evaluate_score, bool &ok_to_terminate_flag)
 evaluate the goodness of a solution More...
 
virtual bool GenerateSamples (int sample_index, std::vector< unsigned int > &which_samples)
 pick a set of samples More...
 
bool GenerateSamplesEvenspace (int sample_index, std::vector< unsigned int > &sample_table)
 
bool GenerateSamplesRandom (int sample_index, std::vector< unsigned int > &sampletable)
 
int GetDebugLevel () const
 
std::ostream & GetDebugStream () const
 
void GetDebugStream (std::ostream &os) const
 
double GetFinalScore () const
 
virtual int GetSampleSolutions (std::vector< unsigned int > &which_samples, std::vector< SolutionType > &solutions)
 Compute solution(s) for the given set of samples. More...
 
void Init (unsigned int sample_size, unsigned int max_solutions_per_sample=1, bool refine_solution=false, bool greedy=false)
 
long int Name2DebugLevel (const std::string &name) const
 looks up a debuglevel in the internal map, returns 0 if not found More...
 
long int NewDebugLevel (const std::string &name)
 creates a new debuglevel More...
 
void PrintDebugLevel (std::ostream &os=std::cout) const
 
 RANSACPreKnowledge ()
 
 RANSACPreKnowledge (unsigned int sample_size, unsigned int max_solutions_per_sample=1, bool refine_solution=false)
 Construct a RANSAC object that takes samples of size sample_size, returning at most max_solutions_per_sample solutions each time. More...
 
virtual bool RefineSolution (std::vector< unsigned int > &which_samples, SolutionType &solution, std::vector< bool > &new_inliers)
 refine previously computed solution based on its inliers More...
 
void RemoveDebugLevel (const long int lv)
 
void RemoveDebugLevel (const std::string &name)
 
void SetDebugLevel (const long int lv)
 
void SetDebugLevel (const std::string &name)
 
void SetDebugStream (const std::ostream &os)
 
void SetMaxSamples (unsigned int max_samples)
 Explicitly set max number of samples. More...
 
void SetSampleCount (unsigned int uiSamples)
 Explicitly set number of samples. More...
 
void ShowDebugLevel (std::ostream &os=std::cout) const
 prints all internally known debuglevels More...
 
virtual int SolveMaster (double inlying_data_fraction, SolutionType &solution, std::vector< bool > &inliers)
 checks UserGuesses and calls RANSAC::SolveMaster More...
 
virtual ~RANSACPreKnowledge ()
 default destructor does nothing More...
 

Static Public Member Functions

static long int GetGlobalDebugLevel ()
 
static void SetGlobalDebugLevel (long int lev)
 

Protected Member Functions

long ConsumeNextFreeDebuglevel_ ()
 returns the next available debuglevel More...
 

Static Protected Member Functions

static int ComputeSampleCount (double inlying_data_fraction, double desired_prob_good, unsigned int sample_size)
 

Protected Attributes

bool _bRefineSolution
 do we want to refine a good sample (one for which evaluate solution returned true)? More...
 
double _dBestInlierEvaluateScore
 
double _dBestSampleEvaluateScore
 
double _dLastBestSampleEvaluateScore
 
double _dProbabilityOfGoodSolution
 prob. for computing number of samples, set close to 1 More...
 
double _dSoSmallSolutionChange
 If all other conditions are right, and the fractional change in the solution statistics is less than this, stop sampling. More...
 
bool _got_solution_flag
 if we already have a solution for which EvaluateSolution returned true More...
 
bool _greedy
 if true, the first acceptable solution is returned More...
 
int _iBestInlierAcceptCount
 refined best values More...
 
int _iBestSampleAcceptCount
 sampled best values More...
 
long int _liDebugLevel
 
long int _liNextDebugLevel
 new concept, debuglevel are managed here in the debug class More...
 
std::map< std::string, long int > _String2Debuglevel
 
unsigned _uiDataSize
 number of data elements needed to compute a solution More...
 
unsigned int _uiExplicitSampleNo
 use this number of samples More...
 
unsigned int _uiMaxSamples
 absolute max number of samples More...
 
unsigned _uiMaxSolutionsPerSample
 max number of solutions that are to be computed for one sample set More...
 
unsigned _uiSampleSize
 number of samples available More...
 
std::vector< SolutionType > UserGuesses_
 vector of guesses to be checked, which were manually supplied by user More...
 

Static Protected Attributes

static std::ostream _zDebugStream
 
static long int GlobalDebugLevel = 0
 

Detailed Description

template<class SolutionType>
class BIAS::RANSACPreKnowledge< SolutionType >

Extension of RANSAC algorithm: user-supplied guesses are evaluated and refined using RANSAC criterions before actually starting the RANSAC algorithm.

Author
koeser 11/2003

Definition at line 42 of file RANSACPreKnowledge.hh.

Constructor & Destructor Documentation

template<class SolutionType >
BIAS::RANSACPreKnowledge< SolutionType >::RANSACPreKnowledge ( )
inline

Definition at line 60 of file RANSACPreKnowledge.hh.

References BIAS::Debug::NewDebugLevel().

template<class SolutionType >
BIAS::RANSACPreKnowledge< SolutionType >::RANSACPreKnowledge ( unsigned int  sample_size,
unsigned int  max_solutions_per_sample = 1,
bool  refine_solution = false 
)
inline

Construct a RANSAC object that takes samples of size sample_size, returning at most max_solutions_per_sample solutions each time.

If the refine_solution flag is true, a routine has been supplied to refine the initial fits before evaluation.

Definition at line 67 of file RANSACPreKnowledge.hh.

References BIAS::Debug::NewDebugLevel().

template<class SolutionType >
virtual BIAS::RANSACPreKnowledge< SolutionType >::~RANSACPreKnowledge ( )
inlinevirtual

default destructor does nothing

Definition at line 75 of file RANSACPreKnowledge.hh.

Member Function Documentation

void BIAS::Debug::AddDebugLevel ( const long int  lv)
inlineinherited
void BIAS::Debug::AddDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 362 of file Debug.hh.

template<class SolutionType >
virtual void BIAS::RANSACPreKnowledge< SolutionType >::AddGoodGuesses ( const std::vector< SolutionType > &  Guesses)
inlinevirtual

add some guessed solutions which are tested by RANSAC later

Definition at line 78 of file RANSACPreKnowledge.hh.

References BIAS::RANSACPreKnowledge< SolutionType >::UserGuesses_.

template<class SolutionType >
virtual void BIAS::RANSACPreKnowledge< SolutionType >::ClearGuesses ( )
inlinevirtual

clear all guesses

Definition at line 86 of file RANSACPreKnowledge.hh.

References BIAS::RANSACPreKnowledge< SolutionType >::UserGuesses_.

template<class SolutionType >
int BIAS::RANSAC< SolutionType >::ComputeSampleCount ( double  inlying_data_fraction,
double  desired_prob_good,
unsigned int  sample_size 
)
inlinestaticprotectedinherited

Definition at line 863 of file RANSAC.hh.

long BIAS::Debug::ConsumeNextFreeDebuglevel_ ( )
inlineprotectedinherited

returns the next available debuglevel

Author
woelk 09/2006

Definition at line 521 of file Debug.hh.

bool BIAS::Debug::DebugLevelIsSet ( const long int  lv) const
inlineinherited
bool BIAS::Debug::DebugLevelIsSet ( const std::string &  name) const
inlineinherited

Definition at line 350 of file Debug.hh.

template<class SolutionType>
bool BIAS::RANSAC< SolutionType >::EvaluateSolution ( const SolutionType &  solution,
bool  existing_solution_flag,
std::vector< bool > &  inlier,
int &  accept_count,
double &  evaluate_score,
bool &  ok_to_terminate_flag 
)
inlinevirtualinherited

evaluate the goodness of a solution

For the specified solution, set

  • an accept count indicating the number of data which are inliers to the given solution,
  • the inlier flag for each datum to true if the datum is inlying
  • an evaluate score (typically the average residual) indicating the goodness of fit of the inliers - the solver code requires a positive number where zero is a perfect solution, larger positive scores mean a worse solution.
  • an ok_to_terminate flag which is set TRUE if the solution is good enough that the robust solver can discontinue search for a better solution. Only happens, if greedy is set to true.
  • The return value tells the algorithm, if the solution is good enough to be refined further - meaning, if set to true and if RefineSolution_ is set to true, the solution will be refined. In the example below, true is returned even if only one samples has been found to be an inlier. Because refinement usually takes quite a while, it is sensible to use a higher threshold. For example the use of a minimum inlier fraction via a private variable in the child class can be tested on.

If existing_solution_flag is true, then the best accept count so far is in accept_count. The function can terminate early if it is not going to beat this.

A skeleton implementation of this function would be written as follows:

*  int my_accept_count = 0;
*  for (unsigned int i=0; i<_uiDataSize; i++) {
*    inlier[i] = Consistent(corner_matches[i], solution);
*    if (inlier[i]) {
*      my_accept_count++;
*      evaluate_score += Residual(corner_matches[i], solution);
*      if (existing_solution_flag && my_accept_count>accept_count)
*        break;
*    }
*  }
*  accept_count=my_accept_count;
*  evaluate_score=(accept_count!=0)?(evaluate_score/accept_count):
*    (DBL_MAX);
*  if (evaluate_score < solution_error_threshold &&
*      (double)accept_count/(double)_uiDataSize > min_inlier_fraction)
*    ok_to_terminate_flag=true;
*  else
*    ok_to_terminate_flag=false;
*  return (accept_count!=0) // maybe even (accept_count>inl_frac)
*  

The line if (existing_solution_flag && my_accept_count>accept_count) break; causes the algorithm to not determine the score and acceptcount correctly, only so far as to top the so far best solution. It can be used for very fast solutions, however if the exact inliers are needed and refineSolution_ is set to false, the evaluation should not be omnitted.

Parameters
solution(in) solution to be evaluated
existing_solution_flag(in) if true the best accept_cout so far is given in accept_count
accept_count(in/out) input: best accept_cout so far if existing_solution_flag==true, output: number of inliers to the current solution
inlier(out) inlier[i] ==> datum i is inlying
evaluate_score(out) a score for the solution, 0 means ideal solution, larger score means worse solution
ok_to_termiate_flag(out) if true, RANSACing will stop

Reimplemented in BIAS::PlaneRANSAC, and BIAS::RANSAC_double.

Definition at line 748 of file RANSAC.hh.

template<class SolutionType >
bool BIAS::RANSAC< SolutionType >::GenerateSamples ( int  sample_index,
std::vector< unsigned int > &  which_samples 
)
inlinevirtualinherited

pick a set of samples

Override this to specialize the technique used to generate samples. By default, random sampling is assumed but implementations may wish to use the latin-square sampling provided by generate_sample_evenspace (below), or some other problem-specific sampling strategy.

Definition at line 768 of file RANSAC.hh.

template<class SolutionType >
bool BIAS::RANSAC< SolutionType >::GenerateSamplesEvenspace ( int  sample_index,
std::vector< unsigned int > &  sample_table 
)
inlineinherited

Definition at line 775 of file RANSAC.hh.

template<class SolutionType >
bool BIAS::RANSAC< SolutionType >::GenerateSamplesRandom ( int  sample_index,
std::vector< unsigned int > &  sampletable 
)
inlineinherited

Definition at line 813 of file RANSAC.hh.

References BIAS::Random::GetUniformDistributedInt().

int BIAS::Debug::GetDebugLevel ( ) const
inlineinherited
std::ostream& BIAS::Debug::GetDebugStream ( ) const
inlineinherited

Definition at line 405 of file Debug.hh.

void BIAS::Debug::GetDebugStream ( std::ostream &  os) const
inlineinherited

Definition at line 414 of file Debug.hh.

template<class SolutionType>
double BIAS::RANSAC< SolutionType >::GetFinalScore ( ) const
inlineinherited

Definition at line 260 of file RANSAC.hh.

static long int BIAS::Debug::GetGlobalDebugLevel ( )
inlinestaticinherited

Definition at line 431 of file Debug.hh.

template<class SolutionType>
int BIAS::RANSAC< SolutionType >::GetSampleSolutions ( std::vector< unsigned int > &  which_samples,
std::vector< SolutionType > &  solutions 
)
inlinevirtualinherited

Compute solution(s) for the given set of samples.

Returns
the number of solutions found.

The which_samples array will be of length sample_size, selecting the indices to be fit to from the subclass's data array.

Reimplemented in BIAS::PlaneRANSAC, and BIAS::RANSAC_double.

Definition at line 738 of file RANSAC.hh.

template<class SolutionType >
void BIAS::RANSAC< SolutionType >::Init ( unsigned int  sample_size,
unsigned int  max_solutions_per_sample = 1,
bool  refine_solution = false,
bool  greedy = false 
)
inlineinherited

Definition at line 360 of file RANSAC.hh.

Referenced by BIAS::RANSAC_double::Init(), and BIAS::PlaneRANSAC::Init().

long int BIAS::Debug::Name2DebugLevel ( const std::string &  name) const
inlineinherited

looks up a debuglevel in the internal map, returns 0 if not found

Author
woelk 09/2006

Definition at line 454 of file Debug.hh.

long int BIAS::Debug::NewDebugLevel ( const std::string &  name)
inlineinherited
void BIAS::Debug::PrintDebugLevel ( std::ostream &  os = std::cout) const
inlineinherited

Definition at line 383 of file Debug.hh.

template<class SolutionType>
bool BIAS::RANSAC< SolutionType >::RefineSolution ( std::vector< unsigned int > &  which_samples,
SolutionType &  solution,
std::vector< bool > &  new_inliers 
)
inlinevirtualinherited

refine previously computed solution based on its inliers

If implemented, this function should compute a more accurate solution, e.g. a least squares on all inliers, possibly using as an initial estimate the solution in solution. The output array new_inliers should be set to reflect the inliers to the new solution.

Returns
false if no better solution than the initial could be found

Reimplemented in BIAS::PlaneRANSAC, and BIAS::RANSAC_double.

Definition at line 758 of file RANSAC.hh.

void BIAS::Debug::RemoveDebugLevel ( const long int  lv)
inlineinherited

Definition at line 369 of file Debug.hh.

void BIAS::Debug::RemoveDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 376 of file Debug.hh.

void BIAS::Debug::SetDebugLevel ( const long int  lv)
inlineinherited
void BIAS::Debug::SetDebugLevel ( const std::string &  name)
inlineinherited

Definition at line 325 of file Debug.hh.

void BIAS::Debug::SetDebugStream ( const std::ostream &  os)
inlineinherited

Definition at line 398 of file Debug.hh.

static void BIAS::Debug::SetGlobalDebugLevel ( long int  lev)
inlinestaticinherited

Definition at line 424 of file Debug.hh.

template<class SolutionType>
void BIAS::RANSAC< SolutionType >::SetMaxSamples ( unsigned int  max_samples)
inlineinherited

Explicitly set max number of samples.

Ransacing will stop after max_samples samples, regardless of solution quality. Normally, more than a few thousand samples signifies a problem.

Definition at line 112 of file RANSAC.hh.

template<class SolutionType>
void BIAS::RANSAC< SolutionType >::SetSampleCount ( unsigned int  uiSamples)
inlineinherited

Explicitly set number of samples.

Explicitly set number of samples to make in SolveMaster, i.e. Value of ComputeSampleCount() is ignored if this function is called with a strictly positive value uiSamples. Note: SolveMaster performs at most min(_uiMaxSamples, uiSamples) iterations

Author
koeser

Definition at line 124 of file RANSAC.hh.

void BIAS::Debug::ShowDebugLevel ( std::ostream &  os = std::cout) const
inlineinherited

prints all internally known debuglevels

Author
woelk 09/2006

Definition at line 496 of file Debug.hh.

template<class SolutionType >
int BIAS::RANSACPreKnowledge< SolutionType >::SolveMaster ( double  inlying_data_fraction,
SolutionType &  solution,
std::vector< bool > &  inliers 
)
inlinevirtual

checks UserGuesses and calls RANSAC::SolveMaster

Author
koeser

Reimplemented from BIAS::RANSAC< SolutionType >.

Definition at line 103 of file RANSACPreKnowledge.hh.

References BIAS::RANSAC< SolutionType >::SolveMaster().

Member Data Documentation

template<class SolutionType>
bool BIAS::RANSAC< SolutionType >::_bRefineSolution
protectedinherited

do we want to refine a good sample (one for which evaluate solution returned true)?

Definition at line 273 of file RANSAC.hh.

template<class SolutionType>
double BIAS::RANSAC< SolutionType >::_dBestInlierEvaluateScore
protectedinherited

Definition at line 282 of file RANSAC.hh.

template<class SolutionType>
double BIAS::RANSAC< SolutionType >::_dBestSampleEvaluateScore
protectedinherited

Definition at line 277 of file RANSAC.hh.

template<class SolutionType>
double BIAS::RANSAC< SolutionType >::_dLastBestSampleEvaluateScore
protectedinherited

Definition at line 278 of file RANSAC.hh.

Referenced by BIAS::RANSAC< double >::GetFinalScore().

template<class SolutionType>
double BIAS::RANSAC< SolutionType >::_dProbabilityOfGoodSolution
protectedinherited

prob. for computing number of samples, set close to 1

Definition at line 291 of file RANSAC.hh.

template<class SolutionType>
double BIAS::RANSAC< SolutionType >::_dSoSmallSolutionChange
protectedinherited

If all other conditions are right, and the fractional change in the solution statistics is less than this, stop sampling.

Definition at line 295 of file RANSAC.hh.

template<class SolutionType>
bool BIAS::RANSAC< SolutionType >::_got_solution_flag
protectedinherited

if we already have a solution for which EvaluateSolution returned true

Definition at line 298 of file RANSAC.hh.

template<class SolutionType>
bool BIAS::RANSAC< SolutionType >::_greedy
protectedinherited

if true, the first acceptable solution is returned

Definition at line 301 of file RANSAC.hh.

template<class SolutionType>
int BIAS::RANSAC< SolutionType >::_iBestInlierAcceptCount
protectedinherited

refined best values

Definition at line 281 of file RANSAC.hh.

template<class SolutionType>
int BIAS::RANSAC< SolutionType >::_iBestSampleAcceptCount
protectedinherited

sampled best values

Definition at line 276 of file RANSAC.hh.

long int BIAS::Debug::_liDebugLevel
protectedinherited

Definition at line 510 of file Debug.hh.

Referenced by BIAS::Debug::operator=(), and BIAS::ImageBase::operator=().

long int BIAS::Debug::_liNextDebugLevel
protectedinherited

new concept, debuglevel are managed here in the debug class

Definition at line 516 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

std::map<std::string, long int> BIAS::Debug::_String2Debuglevel
protectedinherited

Definition at line 517 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

template<class SolutionType>
unsigned BIAS::RANSAC< SolutionType >::_uiDataSize
protectedinherited

number of data elements needed to compute a solution

Definition at line 270 of file RANSAC.hh.

template<class SolutionType>
unsigned int BIAS::RANSAC< SolutionType >::_uiExplicitSampleNo
protectedinherited

use this number of samples

Definition at line 288 of file RANSAC.hh.

Referenced by BIAS::RANSAC< double >::SetSampleCount().

template<class SolutionType>
unsigned int BIAS::RANSAC< SolutionType >::_uiMaxSamples
protectedinherited

absolute max number of samples

Definition at line 285 of file RANSAC.hh.

Referenced by BIAS::RANSAC< double >::SetMaxSamples().

template<class SolutionType>
unsigned BIAS::RANSAC< SolutionType >::_uiMaxSolutionsPerSample
protectedinherited

max number of solutions that are to be computed for one sample set

Definition at line 267 of file RANSAC.hh.

template<class SolutionType>
unsigned BIAS::RANSAC< SolutionType >::_uiSampleSize
protectedinherited

number of samples available

Definition at line 264 of file RANSAC.hh.

std::ostream BIAS::Debug::_zDebugStream
staticprotectedinherited

Definition at line 511 of file Debug.hh.

Referenced by BIAS::Debug::operator=().

long int BIAS::Debug::GlobalDebugLevel = 0
staticprotectedinherited

Definition at line 513 of file Debug.hh.

template<class SolutionType >
std::vector<SolutionType> BIAS::RANSACPreKnowledge< SolutionType >::UserGuesses_
protected

vector of guesses to be checked, which were manually supplied by user

Definition at line 98 of file RANSACPreKnowledge.hh.

Referenced by BIAS::RANSACPreKnowledge< SolutionType >::AddGoodGuesses(), and BIAS::RANSACPreKnowledge< SolutionType >::ClearGuesses().


The documentation for this class was generated from the following file: