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::RANSAC_double Class Reference

Robust mean computation for double values using RANSAC. More...

#include <MathAlgo/Examples/ExampleRANSAC_double.hh>

+ Inheritance diagram for BIAS::RANSAC_double:
+ Collaboration diagram for BIAS::RANSAC_double:

Public Member Functions

void AddDebugLevel (const long int lv)
 
void AddDebugLevel (const std::string &name)
 
bool DebugLevelIsSet (const long int lv) const
 
bool DebugLevelIsSet (const std::string &name) const
 
virtual bool EvaluateSolution (const double &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< double > &solutions)
 Compute solution(s) for the given set of samples. More...
 
void Init (std::vector< double > &data, unsigned int sample_size, double inlier_distance_threshold, bool refine_solution, double expected_inlier_fraction, double solution_error_threshold)
 
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
 
 RANSAC_double ()
 
virtual bool RefineSolution (std::vector< unsigned int > &which_samples, double &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, double &solution, std::vector< bool > &inliers)
 Main computation function called by user. More...
 
 ~RANSAC_double ()
 

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 _dExpectedInlierFraction
 
double _dInlierDistanceThreshold
 
double _dLastBestSampleEvaluateScore
 
double _dProbabilityOfGoodSolution
 prob. for computing number of samples, set close to 1 More...
 
double _dSolutionErrorThreshold
 
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< double > _vData
 

Static Protected Attributes

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

Detailed Description

Robust mean computation for double values using RANSAC.

This class implements a simple example for RANSAC class overloading.

Method RANSAC_double::GetSampleSolutions picks a number of values and computes the mean from them. The sample size is not fixed here but can be chosen when calling method RANSAC_double::Init.

Method RANSAC_double::EvaluateSolution evaluates how many values are considered as "inliers" with respect to the mean hypothesis, i.e. their distance to the mean does not exceed a certain threshold.

In RANSAC_double::RefineSolution the mean is recomputed for all inliers.

You have to set the inlier threshold (max. distance to mean to accept a value as being an inlier) and the fraction of valid input values which will define the number of samples evaluated by RANSAC.

Author
MIP
Examples:
ExampleRANSAC_double.cpp.

Definition at line 53 of file ExampleRANSAC_double.hh.

Constructor & Destructor Documentation

BIAS::RANSAC_double::RANSAC_double ( )

Definition at line 94 of file ExampleRANSAC_double.hh.

BIAS::RANSAC_double::~RANSAC_double ( )

Definition at line 97 of file ExampleRANSAC_double.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.

static int BIAS::RANSAC< double >::ComputeSampleCount ( double  inlying_data_fraction,
double  desired_prob_good,
unsigned int  sample_size 
)
inlinestaticprotectedinherited
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.

bool BIAS::RANSAC_double::EvaluateSolution ( const double &  solution,
bool  existing_solution_flag,
std::vector< bool > &  inlier,
int &  accept_count,
double &  evaluate_score,
bool &  ok_to_terminate_flag 
)
virtual

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 from BIAS::RANSAC< double >.

Definition at line 129 of file ExampleRANSAC_double.hh.

References _dExpectedInlierFraction, _dInlierDistanceThreshold, _dSolutionErrorThreshold, BIAS::RANSAC< double >::_uiDataSize, and _vData.

virtual bool BIAS::RANSAC< double >::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.

bool BIAS::RANSAC< double >::GenerateSamplesEvenspace ( int  sample_index,
std::vector< unsigned int > &  sample_table 
)
inlineinherited
bool BIAS::RANSAC< double >::GenerateSamplesRandom ( int  sample_index,
std::vector< unsigned int > &  sampletable 
)
inlineinherited
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.

double BIAS::RANSAC< double >::GetFinalScore ( ) const
inlineinherited
static long int BIAS::Debug::GetGlobalDebugLevel ( )
inlinestaticinherited

Definition at line 431 of file Debug.hh.

int BIAS::RANSAC_double::GetSampleSolutions ( std::vector< unsigned int > &  which_samples,
std::vector< double > &  solutions 
)
virtual

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 from BIAS::RANSAC< double >.

Definition at line 116 of file ExampleRANSAC_double.hh.

References _vData.

void BIAS::RANSAC_double::Init ( std::vector< double > &  data,
unsigned int  sample_size,
double  inlier_distance_threshold,
bool  refine_solution,
double  expected_inlier_fraction,
double  solution_error_threshold 
)
void BIAS::RANSAC< double >::Init ( unsigned int  sample_size,
unsigned int  max_solutions_per_sample = 1,
bool  refine_solution = false,
bool  greedy = false 
)
inlineinherited
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.

bool BIAS::RANSAC_double::RefineSolution ( std::vector< unsigned int > &  which_samples,
double &  solution,
std::vector< bool > &  new_inliers 
)
virtual

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 from BIAS::RANSAC< double >.

Definition at line 167 of file ExampleRANSAC_double.hh.

References _dInlierDistanceThreshold, BIAS::RANSAC< double >::_uiDataSize, and _vData.

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.

void BIAS::RANSAC< double >::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.

References BIAS::RANSAC< SolutionType >::_uiMaxSamples.

void BIAS::RANSAC< double >::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.

References BIAS::RANSAC< SolutionType >::_uiExplicitSampleNo.

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.

virtual int BIAS::RANSAC< double >::SolveMaster ( double  inlying_data_fraction,
double &  solution,
std::vector< bool > &  inliers 
)
inlinevirtualinherited

Main computation function called by user.

This function is called to run the computation. On output, solution is set to the best solution found and inliers indicate which data were inliers to that solution. The inlying_data_fraction is responsible for the maximal number of sample sets taken from the data. The smaller the inlying_data_fraction, the more sample sets are taken

Attention
Do NOT override this function in derived classes, unless you want to do modifications in the RANSAC algorithm itself (and usually you dont want to do this ...) input : inlying_data_fraction expected inlier fraction output: solution solution inliers inlier flags
Returns
<0 indicates an error, otherwise number of chosen sample
Author
frahm, woelk
Examples:
ExampleRANSAC_double.cpp.

Member Data Documentation

bool BIAS::RANSAC< double >::_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.

double BIAS::RANSAC< double >::_dBestInlierEvaluateScore
protectedinherited

Definition at line 282 of file RANSAC.hh.

double BIAS::RANSAC< double >::_dBestSampleEvaluateScore
protectedinherited

Definition at line 277 of file RANSAC.hh.

double BIAS::RANSAC_double::_dExpectedInlierFraction
protected

Definition at line 90 of file ExampleRANSAC_double.hh.

Referenced by EvaluateSolution(), and Init().

double BIAS::RANSAC_double::_dInlierDistanceThreshold
protected

Definition at line 86 of file ExampleRANSAC_double.hh.

Referenced by EvaluateSolution(), Init(), and RefineSolution().

double BIAS::RANSAC< double >::_dLastBestSampleEvaluateScore
protectedinherited

Definition at line 278 of file RANSAC.hh.

double BIAS::RANSAC< double >::_dProbabilityOfGoodSolution
protectedinherited

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

Definition at line 291 of file RANSAC.hh.

double BIAS::RANSAC_double::_dSolutionErrorThreshold
protected

Definition at line 91 of file ExampleRANSAC_double.hh.

Referenced by EvaluateSolution(), and Init().

double BIAS::RANSAC< double >::_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.

bool BIAS::RANSAC< double >::_got_solution_flag
protectedinherited

if we already have a solution for which EvaluateSolution returned true

Definition at line 298 of file RANSAC.hh.

bool BIAS::RANSAC< double >::_greedy
protectedinherited

if true, the first acceptable solution is returned

Definition at line 301 of file RANSAC.hh.

int BIAS::RANSAC< double >::_iBestInlierAcceptCount
protectedinherited

refined best values

Definition at line 281 of file RANSAC.hh.

int BIAS::RANSAC< double >::_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=().

unsigned BIAS::RANSAC< double >::_uiDataSize
protectedinherited

number of data elements needed to compute a solution

Definition at line 270 of file RANSAC.hh.

Referenced by EvaluateSolution(), Init(), and RefineSolution().

unsigned int BIAS::RANSAC< double >::_uiExplicitSampleNo
protectedinherited

use this number of samples

Definition at line 288 of file RANSAC.hh.

unsigned int BIAS::RANSAC< double >::_uiMaxSamples
protectedinherited

absolute max number of samples

Definition at line 285 of file RANSAC.hh.

unsigned BIAS::RANSAC< double >::_uiMaxSolutionsPerSample
protectedinherited

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

Definition at line 267 of file RANSAC.hh.

unsigned BIAS::RANSAC< double >::_uiSampleSize
protectedinherited

number of samples available

Definition at line 264 of file RANSAC.hh.

std::vector<double> BIAS::RANSAC_double::_vData
protected

Definition at line 83 of file ExampleRANSAC_double.hh.

Referenced by EvaluateSolution(), GetSampleSolutions(), Init(), and RefineSolution().

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.


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