Basic Image AlgorithmS Library
2.8.0
|
example class for condensation with a 2-dim state vector. More...
#include <StateEstimator/CondensImg.hh>
Public Member Functions | |
void | AddDebugLevel (const long int lv) |
void | AddDebugLevel (const std::string &name) |
CondensImg () | |
u have to set the stateDim in the constructor! More... | |
bool | DebugLevelIsSet (const long int lv) const |
bool | DebugLevelIsSet (const std::string &name) const |
void | DrawMean (BIAS::Image< unsigned char > &img) |
Draws the mean as a cross, which size is proportional to the variance. More... | |
void | DrawPosteriorDistribution (BIAS::Image< unsigned char > &img) |
Draws the samples with their weight as greyvalue, the weight is distributed to the 4 pixels around the sample postion. More... | |
double | DrawPosteriorDistribution (BIAS::Image< float > &img) |
same as above but float precision and returns the maximum value also. More... | |
void | DrawSamples (Image< unsigned char > &img, unsigned char value=255) |
this draws the sample weights as circles More... | |
virtual void | EvaluateImportanceWeights () |
If you want to use importance sampling, then overload this function, which is the importance function. More... | |
virtual void | EvaluateObservationDensities () |
most important function, here u have to calculate a probability for each sample position based on your observations and assign this prob. More... | |
int | GetDebugLevel () const |
std::ostream & | GetDebugStream () const |
void | GetDebugStream (std::ostream &os) const |
Vector< double > | GetMean () |
returns the mean state of the density distribution More... | |
double | GetMeanWeight () const |
Returns the mean weight of all samples. More... | |
void | GetSamplePositions (Image< unsigned char > &sampleImg) |
const std::vector < BIAS::Vector< double > > & | GetSamplePositions () |
double | GetVariance () const |
returns the weighted variance as a scalar More... | |
bool | GetVariance (Vector< double > &var) const |
Returns the variance of the sample positions in var. More... | |
bool | GetWeightedVariance (Vector< double > &var) const |
Returns the "weighted variance" of the sample positions in var. More... | |
int | Init (unsigned int nrSmaples) |
Init the Condensation directly after constructor, with the desired amount of Samples, there more the better the approximation of the real densities. More... | |
virtual void | InitModelDefaults () |
Here u can specify the model and process defaults. More... | |
int | InitPrior () |
sets the sample positions for first time step More... | |
virtual void | InitPriorPositions (unsigned int nrOfInitSamples) |
The Prior condition is used to init the first sample positions. More... | |
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... | |
int | PredictNewSamplePositions () |
void | PrintDebugLevel (std::ostream &os=std::cout) const |
void | Process () |
This really does one iteration of Condensation. More... | |
void | RemoveDebugLevel (const long int lv) |
void | RemoveDebugLevel (const std::string &name) |
void | SetArea (Vector2< double > min, Vector2< double > max) |
The area for the initial uniform distribution. More... | |
void | SetDebugLevel (const long int lv) |
void | SetDebugLevel (const std::string &name) |
void | SetDebugStream (const std::ostream &os) |
void | SetDefaultInitFraction (double fraction) |
Set the amount of samples, whose position is always taken by the prior distribution. More... | |
void | SetImportanceSampleFraction (double fraction) |
Only specifiy a value unlike zero, if EvaluateImportanceWeights() is overloaded. More... | |
void | SetObservation (Image< unsigned char > &osbImg) |
converts to Image<float> and calls the function above More... | |
void | SetPredictionOffset (const BIAS::Vector< double > &offSet) |
all samples are moved by this offset at the prediction step More... | |
void | SetProcessMean (const BIAS::Vector< double > &newProcessMean) |
set a new processMean for the PredictSamplePosition step, see SecondOrderARP_() More... | |
void | ShowDebugLevel (std::ostream &os=std::cout) const |
prints all internally known debuglevels More... | |
Static Public Member Functions | |
static long int | GetGlobalDebugLevel () |
static void | SetGlobalDebugLevel (long int lev) |
Protected Member Functions | |
virtual void | AddDiffusions_ () |
Adds gaussian noise to the position, can be overwritten if some other (i.e. More... | |
virtual void | AddOffsets_ () |
adds offSet_ to the samplePosNew_, can be overwritten if some other offset mechanism is needed More... | |
virtual void | CalculateBaseWeights_ () |
Once all the unweighted sample positions have been computed using predict_new_bases, this routine computes the weights by evaluating the observation density at each of the positions. More... | |
void | CalculateMean_ () |
long | ConsumeNextFreeDebuglevel_ () |
returns the next available debuglevel More... | |
unsigned int | PickImportanceSample_ () |
unsigned int | PickOneSample_ () |
The process model for a first-order auto-regressive process is: x_{t+1} - mean = (x_t - mean)*scaling + sigma*w_t where w_t is unit iid Gaussian noise, which is added by AddDiffusion. More... | |
void | SecondOrderARP_ (unsigned int indexOldSample, Vector< double > &newSample) |
question: real pos_tminus2 of each sample or better old mean value for all samples? More... | |
Static Protected Member Functions | |
static int | compdouble (const void *l, const void *r) |
Protected Attributes | |
bool | _doSecondOrderARP |
long int | _liDebugLevel |
long int | _liNextDebugLevel |
new concept, debuglevel are managed here in the debug class More... | |
double * | _randomArray |
std::map< std::string, long int > | _String2Debuglevel |
Vector< double > | areaMax_ |
Vector< double > | areaMin_ |
std::vector< double > | correctionOfImportanceWeights_ |
std::vector< double > | cumulProbArray_ |
std::vector< double > | cumulProbArrayImportance_ |
double | defaultInitFraction_ |
Vector< double > | diffusionSigma_ |
Process parameters. More... | |
BIAS::Image< float > | fImg_ |
double | importanceFraction_ |
std::vector< unsigned int > | indexTminus2_ |
bool | initial_ |
Vector< double > | mean_ |
Vector< double > | meanTminus1_ |
unsigned int | Nsamples_ |
Image< unsigned char > | obsImg_ |
BIAS::Vector< double > | offSet_ |
std::vector< unsigned int > | oldIndices_ |
Vector< double > | processFirstOrderScale_ |
Vector< double > | processMean_ |
Vector< double > | processSecondOrderScale_ |
Random | random_ |
std::vector< double > | sampleImportanceWeights_ |
std::vector< Vector< double > > | samplePosNew_ |
std::vector< Vector< double > > | samplePosOld_ |
std::vector< Vector< double > > | samplePosTminus2_ |
std::vector< double > | sampleWeights_ |
unsigned int | stateDim_ |
double | sumOfImportanceWeights_ |
double | sumOfWeights_ |
Static Protected Attributes | |
static std::ostream | _zDebugStream |
static long int | GlobalDebugLevel = 0 |
example class for condensation with a 2-dim state vector.
The observation p(Z|X) is simply an image, where the greyvalue represents the probabilty.
See condensImgExample.cpp also!
Definition at line 44 of file CondensImg.hh.
|
inline |
u have to set the stateDim in the constructor!
Definition at line 49 of file CondensImg.hh.
|
inlineinherited |
Definition at line 355 of file Debug.hh.
Referenced by BIAS::GLProjectionParametersBase::AddDebugLevel(), BIAS::Triangulation::CorrectCorrespondences(), BIAS::FilterBase< InputStorageType, OutputStorageType >::FilterBase(), BIAS::ShowCamWxVideoSourceFactory::OpenDevice(), and BIAS::SceneOpenSceneGraph::SceneOpenSceneGraph().
|
inlineinherited |
|
protectedvirtualinherited |
Adds gaussian noise to the position, can be overwritten if some other (i.e.
non gaussian) noise is needed
Definition at line 275 of file Condensation.cpp.
|
protectedvirtualinherited |
adds offSet_ to the samplePosNew_, can be overwritten if some other offset mechanism is needed
Definition at line 292 of file Condensation.cpp.
|
protectedvirtualinherited |
Once all the unweighted sample positions have been computed using predict_new_bases, this routine computes the weights by evaluating the observation density at each of the positions.
Cumulative probabilities are also computed at the same time, to permit an efficient implementation of pick_base_sample using binary search.
Definition at line 301 of file Condensation.cpp.
References BIAS::TimeMeasure::GetRealTime(), BIAS::TimeMeasure::Reset(), BIAS::TimeMeasure::Start(), and BIAS::TimeMeasure::Stop().
|
inlineprotectedinherited |
Definition at line 324 of file Condensation.hh.
References BIAS::TimeMeasure::GetRealTime(), BIAS::Condensation::mean_, BIAS::Vector< T >::MultiplyIP(), BIAS::Condensation::Nsamples_, BIAS::Condensation::samplePosOld_, BIAS::Condensation::sampleWeights_, BIAS::Vector< T >::Set(), BIAS::TimeMeasure::Start(), BIAS::TimeMeasure::Stop(), and BIAS::Condensation::sumOfWeights_.
|
inlinestaticprotectedinherited |
Definition at line 252 of file Condensation.hh.
|
inlineprotectedinherited |
|
inlineinherited |
Definition at line 341 of file Debug.hh.
Referenced by BIAS::GenSynthMatches::_AddUniformDistributedOutliers(), BIAS::GenSynthMatches::_CreateCamMovement(), BIAS::GenSynthMatches::_CreateStatic2DPoints(), BIAS::UnscentedTransform::ComputeSigmaPoints_(), BIAS::Triangulation::CorrectCorrespondences(), BIAS::GenSynthMatches::GetGTNormalizedF(), BIAS::MonteCarloTransform::GetSamples_(), and BIAS::MonteCarloTransform::Transform().
|
inlineinherited |
void CondensImg::DrawMean | ( | BIAS::Image< unsigned char > & | img | ) |
Draws the mean as a cross, which size is proportional to the variance.
Definition at line 190 of file CondensImg.cpp.
References BIAS::ImageDraw< StorageType >::LineGrey(), and BIAS::Vector< T >::ScalarProduct().
void CondensImg::DrawPosteriorDistribution | ( | BIAS::Image< unsigned char > & | img | ) |
Draws the samples with their weight as greyvalue, the weight is distributed to the 4 pixels around the sample postion.
Image has to be initialized with correct size and channelcount !
Definition at line 131 of file CondensImg.cpp.
References BIAS::ImageBase::GetHeight(), BIAS::Image< StorageType >::GetImageData(), BIAS::ImageBase::GetPixelCount(), and BIAS::ImageBase::GetWidth().
double CondensImg::DrawPosteriorDistribution | ( | BIAS::Image< float > & | img | ) |
same as above but float precision and returns the maximum value also.
Definition at line 153 of file CondensImg.cpp.
References BIAS::Image< StorageType >::FillImageWithConstValue(), BIAS::ImageBase::GetHeight(), BIAS::Image< StorageType >::GetImageDataArray(), and BIAS::ImageBase::GetWidth().
void CondensImg::DrawSamples | ( | Image< unsigned char > & | img, |
unsigned char | value = 255 |
||
) |
this draws the sample weights as circles
Definition at line 106 of file CondensImg.cpp.
References BIAS::ImageDraw< StorageType >::CircleCenter(), BIAS::ImageBase::CM_Grey, BIAS::Image< StorageType >::FillImageWithConstValue(), BIAS::ImageBase::GetHeight(), BIAS::ImageBase::GetWidth(), BIAS::Image< StorageType >::Init(), BIAS::ImageBase::IsEmpty(), BIAS::Image< StorageType >::Release(), and BIAS::ImageBase::SetColorModel().
|
virtual |
If you want to use importance sampling, then overload this function, which is the importance function.
It should be a density distribution, which gives hint where to measure the object state.
Evaluate here the samplePosOld_, not the new ones
IMPORTANT: the scale of the importance weights must be equal to the normal weights, like in EvaluateObservationDensities()
Reimplemented from BIAS::Condensation.
Definition at line 81 of file CondensImg.cpp.
|
virtual |
most important function, here u have to calculate a probability for each sample position based on your observations and assign this prob.
as a weight to the sample
Implements BIAS::Condensation.
Definition at line 65 of file CondensImg.cpp.
|
inlineinherited |
Definition at line 332 of file Debug.hh.
Referenced by BIAS::listenthread(), BIAS::Image< StorageType >::operator=(), and BIAS::ImageBase::operator=().
|
inlineinherited |
|
inlineinherited |
|
inlinestaticinherited |
|
inlineinherited |
returns the mean state of the density distribution
Definition at line 115 of file Condensation.hh.
|
inherited |
Returns the mean weight of all samples.
Initialization samples and importance samples are not used in calculation.
Definition at line 432 of file Condensation.cpp.
void BIAS::CondensImg::GetSamplePositions | ( | Image< unsigned char > & | sampleImg | ) |
|
inlineinherited |
Definition at line 107 of file Condensation.hh.
|
inherited |
returns the weighted variance as a scalar
Definition at line 375 of file Condensation.cpp.
|
inherited |
Returns the variance of the sample positions in var.
Initialization samples and importance samples are not used in calculation.
Definition at line 412 of file Condensation.cpp.
References BIAS::Vector< T >::ElementwiseProduct(), TNT::Vector< T >::newsize(), and BIAS::Vector< T >::SetZero().
|
inherited |
Returns the "weighted variance" of the sample positions in var.
Initialization samples and importance samples are not used in calculation.
Definition at line 390 of file Condensation.cpp.
References BIAS::Vector< T >::ElementwiseProduct(), TNT::Vector< T >::newsize(), and BIAS::Vector< T >::SetZero().
|
inherited |
Init the Condensation directly after constructor, with the desired amount of Samples, there more the better the approximation of the real densities.
The other Init functions are called here also.
Definition at line 58 of file Condensation.cpp.
|
virtual |
Here u can specify the model and process defaults.
Implements BIAS::Condensation.
Definition at line 32 of file CondensImg.cpp.
|
inherited |
sets the sample positions for first time step
Definition at line 113 of file Condensation.cpp.
References BIAS::TimeMeasure::GetRealTime(), BIAS::TimeMeasure::Start(), and BIAS::TimeMeasure::Stop().
|
virtual |
The Prior condition is used to init the first sample positions.
Calculates a initial pos for all samples. The prior cond. maybe defined by an image (if state vector is 2-dim) or by a mixture of gaussions or Uniform_distributed or ... or ...
Implements BIAS::Condensation.
Definition at line 54 of file CondensImg.cpp.
|
inlineinherited |
|
inlineinherited |
creates a new debuglevel
Definition at line 474 of file Debug.hh.
Referenced by BIAS::COSAC< SolutionType >::COSAC(), BIAS::ProjectionParametersPerspectiveDepth::Init(), BIAS::MonteCarloTransform::MonteCarloTransform(), BIAS::PMatrixEstimation::PMatrixEstimation(), BIAS::PreemptiveRANSAC< SolutionType >::PreemptiveRANSAC(), BIAS::RANSACPreKnowledge< SolutionType >::RANSACPreKnowledge(), BIAS::ROI::ROI(), BIAS::RotationAveraging::RotationAveraging(), BIAS::SceneOpenSceneGraph::SceneOpenSceneGraph(), BIAS::ThreeDOutOpenSceneGraph::ThreeDOutOpenSceneGraph(), BIAS::Triangulation::Triangulation(), and BIAS::UnscentedTransform::UnscentedTransform().
|
inlineprotectedinherited |
Definition at line 282 of file Condensation.hh.
References BIAS::Condensation::cumulProbArrayImportance_, BIAS::Random::GetUniformDistributed(), BIAS::Condensation::Nsamples_, BIAS::Condensation::random_, and BIAS::Condensation::sumOfImportanceWeights_.
|
inlineprotectedinherited |
The process model for a first-order auto-regressive process is:
x_{t+1} - mean = (x_t - mean)*scaling + sigma*w_t
where w_t is unit iid Gaussian noise, which is added by AddDiffusion.
This is binary search using cumulative probabilities to pick a base sample. The use of this routine makes Condensation O(NlogN) where N is the number of samples. It is probably better to pick base samples deterministically, since then the algorithm is O(N) and probably marginally more efficient, but this routine is kept here for conceptual simplicity and because it maps better to the published literature.
Definition at line 258 of file Condensation.hh.
References BIAS::Condensation::cumulProbArray_, BIAS::Random::GetUniformDistributed(), BIAS::Condensation::Nsamples_, BIAS::Condensation::random_, and BIAS::Condensation::sumOfWeights_.
|
inherited |
now pick samples from the last time step using the weights
most probably from the process model
most probably gaussian noise
Definition at line 142 of file Condensation.cpp.
References BIAS::TimeMeasure::GetRealTime(), BIAS::TimeMeasure::Reset(), BIAS::TimeMeasure::Start(), and BIAS::TimeMeasure::Stop().
|
inlineinherited |
|
inherited |
This really does one iteration of Condensation.
It calls PredictSamplePosition() and EvaluateObservationDensity() in the necessary order.
Definition at line 332 of file Condensation.cpp.
References BIAS::TimeMeasure::GetRealTime(), BIAS::TimeMeasure::Reset(), BIAS::TimeMeasure::Start(), and BIAS::TimeMeasure::Stop().
|
inlineinherited |
|
inlineinherited |
|
inlineprotectedinherited |
question: real pos_tminus2 of each sample or better old mean value for all samples?
Definition at line 303 of file Condensation.hh.
References BIAS::Condensation::indexTminus2_, BIAS::Condensation::processFirstOrderScale_, BIAS::Condensation::processMean_, BIAS::Condensation::processSecondOrderScale_, BIAS::Condensation::samplePosOld_, BIAS::Condensation::samplePosTminus2_, and BIAS::Condensation::stateDim_.
The area for the initial uniform distribution.
Probably image size...
Definition at line 94 of file CondensImg.cpp.
|
inlineinherited |
Definition at line 318 of file Debug.hh.
Referenced by BIAS::ShowCamWxVideoSourceFactory::CreateBumbleBee(), BIAS::ShowCamWxVideoSourceFactory::CreateDCAM(), BIAS::VideoSource_MDcam::ScanBus(), BIAS::GLProjectionParametersBase::SetDebugLevel(), BIAS::VideoSource_Disk::VideoSource_Disk(), BIAS::VideoSource_DV2::VideoSource_DV2(), BIAS::VideoSource_DV::VideoSource_DV_Internal_Init_(), and BIAS::VideoSource_V4L::VideoSource_V4L().
|
inlineinherited |
|
inlineinherited |
|
inherited |
Set the amount of samples, whose position is always taken by the prior distribution.
Default is 0.2.
fraction must be in [0..1];
Definition at line 260 of file Condensation.cpp.
|
inlinestaticinherited |
|
inherited |
Only specifiy a value unlike zero, if EvaluateImportanceWeights() is overloaded.
Definition at line 268 of file Condensation.cpp.
void CondensImg::SetObservation | ( | Image< unsigned char > & | osbImg | ) |
converts to Image<float> and calls the function above
Definition at line 101 of file CondensImg.cpp.
|
inlineinherited |
all samples are moved by this offset at the prediction step
Definition at line 103 of file Condensation.hh.
|
inlineinherited |
set a new processMean for the PredictSamplePosition step, see SecondOrderARP_()
Definition at line 152 of file Condensation.hh.
|
inlineinherited |
|
protectedinherited |
Definition at line 177 of file Condensation.hh.
|
protectedinherited |
Definition at line 510 of file Debug.hh.
Referenced by BIAS::Debug::operator=(), and BIAS::ImageBase::operator=().
|
protectedinherited |
new concept, debuglevel are managed here in the debug class
Definition at line 516 of file Debug.hh.
Referenced by BIAS::Debug::operator=().
|
protectedinherited |
Definition at line 249 of file Condensation.hh.
|
protectedinherited |
Definition at line 517 of file Debug.hh.
Referenced by BIAS::Debug::operator=().
|
staticprotectedinherited |
Definition at line 511 of file Debug.hh.
Referenced by BIAS::Debug::operator=().
|
protected |
Definition at line 93 of file CondensImg.hh.
|
protected |
Definition at line 93 of file CondensImg.hh.
|
protectedinherited |
Definition at line 236 of file Condensation.hh.
|
protectedinherited |
Definition at line 234 of file Condensation.hh.
Referenced by BIAS::Condensation::PickOneSample_().
|
protectedinherited |
Definition at line 235 of file Condensation.hh.
Referenced by BIAS::Condensation::PickImportanceSample_().
|
protectedinherited |
Definition at line 245 of file Condensation.hh.
|
protectedinherited |
Process parameters.
Definition at line 241 of file Condensation.hh.
|
protected |
Definition at line 97 of file CondensImg.hh.
|
staticprotectedinherited |
|
protectedinherited |
Definition at line 246 of file Condensation.hh.
|
protectedinherited |
Definition at line 230 of file Condensation.hh.
Referenced by BIAS::Condensation::SecondOrderARP_().
|
protectedinherited |
Definition at line 244 of file Condensation.hh.
|
protectedinherited |
Definition at line 232 of file Condensation.hh.
Referenced by BIAS::Condensation::CalculateMean_().
|
protectedinherited |
Definition at line 232 of file Condensation.hh.
|
protectedinherited |
Definition at line 223 of file Condensation.hh.
Referenced by BIAS::Condensation::CalculateMean_(), BIAS::Condensation::PickImportanceSample_(), and BIAS::Condensation::PickOneSample_().
|
protected |
Definition at line 94 of file CondensImg.hh.
|
protectedinherited |
Definition at line 250 of file Condensation.hh.
|
protectedinherited |
Definition at line 230 of file Condensation.hh.
|
protectedinherited |
Definition at line 242 of file Condensation.hh.
Referenced by BIAS::Condensation::SecondOrderARP_().
|
protectedinherited |
Definition at line 241 of file Condensation.hh.
Referenced by BIAS::Condensation::SecondOrderARP_().
|
protectedinherited |
Definition at line 242 of file Condensation.hh.
Referenced by BIAS::Condensation::SecondOrderARP_().
|
protectedinherited |
Definition at line 248 of file Condensation.hh.
Referenced by BIAS::Condensation::PickImportanceSample_(), and BIAS::Condensation::PickOneSample_().
|
protectedinherited |
Definition at line 235 of file Condensation.hh.
|
protectedinherited |
Definition at line 225 of file Condensation.hh.
|
protectedinherited |
Definition at line 226 of file Condensation.hh.
Referenced by BIAS::Condensation::CalculateMean_(), and BIAS::Condensation::SecondOrderARP_().
|
protectedinherited |
Definition at line 227 of file Condensation.hh.
Referenced by BIAS::Condensation::SecondOrderARP_().
|
protectedinherited |
Definition at line 234 of file Condensation.hh.
Referenced by BIAS::Condensation::CalculateMean_().
|
protectedinherited |
Definition at line 224 of file Condensation.hh.
Referenced by BIAS::Condensation::SecondOrderARP_().
|
protectedinherited |
Definition at line 238 of file Condensation.hh.
Referenced by BIAS::Condensation::PickImportanceSample_().
|
protectedinherited |
Definition at line 238 of file Condensation.hh.
Referenced by BIAS::Condensation::CalculateMean_(), and BIAS::Condensation::PickOneSample_().