This class implements the Ransac::Model interface for all fitting classes. More...
#include <RansacGenericFittingModel.hpp>
Public Member Functions | |
RansacGenericFittingModel (Fit< T > &estimator) | |
Constructs an instance of RansacGenericFittingModel. | |
void | compute () |
Estimates the model parameters. | |
T | getDeviation (const Coordinate< T > &datum) const |
Returns the amount of how much a datum deviates from the model. | |
unsigned | getMinimumNumberOfItems () const |
Returns the minimum number of items required to compute the model. | |
T | getRMS () const |
Returns the root mean square error of the estimated regression model. | |
void | setData (const std::vector< Coordinate< T > > &data) |
Sets the sample data. | |
void | setEstimator (Fit< T > &estimator) |
Sets the fitting class instance. | |
virtual T | getDeviation (const DataType &datum) const =0 |
Return the amount of how much a datum deviates from the model. | |
virtual T | getRMSE () const =0 |
Return the root mean square error of the estimated regression model. | |
virtual void | setData (const std::vector< DataType > &data)=0 |
Set the sample data. No data is copied but a reference is stored. |
This class implements the Ransac::Model interface for all fitting classes.
T | Scalar type (must be a floating point). |
Here is an example that shows how to use this class:
#include <iostream> #include <TRTK/FitLine.hpp> #include <TRTK/RansacGenericFittingModel.hpp> #include <TRTK/Tools.hpp> using namespace std; using namespace TRTK; using namespace TRTK::Tools; int main() { // Construct some points lying on a line and add some noise and outliers. vector<Coordinate<double> > points; double slope = 0.7; double y_intercept = -3; for (int i = -10; i < 10; ++i) { // Noisy measurement. double x = i + randn(0.0, 0.1); double y = i * slope + y_intercept + randn(0.0, 0.1); Coordinate<double> point(x, y); points.push_back(point); } for (int i = 0; i < 5; ++i) { // Gros outliers. double x = rand(-10.0, 10.0); double y = rand(-10.0, 10.0); Coordinate<double> point(x, y); points.push_back(point); } // Estimate the line parameters using ordinary least sqares. FitLine<double> fitLine(points); fitLine.compute(); cout << "Slope: " << fitLine.getSlope() << endl; cout << "Y-intercept: " << fitLine.getYIntercept() << endl; cout << "Direction Vector: " << fitLine.getDirectionVector() << endl; cout << "Distance from origin: " << fitLine.getDistanceFromOrigin() << endl; cout << "RMS: " << fitLine.getRMS() << endl << endl; // Estimate the line parameters using RANSAC. RansacGenericFittingModel<double> model(fitLine); Ransac<double> ransac; ransac.setModel(model); ransac.setData(points); ransac.setErrorTolerance(0.2); unsigned number_of_samples_used = ransac.compute(); cout << "Slope: " << fitLine.getSlope() << endl; cout << "Y-intercept: " << fitLine.getYIntercept() << endl; cout << "Direction Vector: " << fitLine.getDirectionVector() << endl; cout << "Distance from origin: " << fitLine.getDistanceFromOrigin() << endl; cout << "Number of samples used: " << number_of_samples_used << endl; cout << "RMS: " << model.getRMS() << endl; return 0; }
Output:
Slope: 0.824709 Y-intercept: -2.97947 Direction Vector: (-0.771483, -0.63625) Distance from origin: 2.29861 RMS: 2.27904 Slope: 0.691347 Y-intercept: -3.00877 Direction Vector: (-0.822562, -0.568676) Distance from origin: 2.4749 Number of samples used: 19 RMS: 0.0712661
For further information, please have a look at the documentation of the particular fitting class and the Ransac class, respectively.
Definition at line 140 of file RansacGenericFittingModel.hpp.
TRTK::RansacGenericFittingModel< T >::RansacGenericFittingModel | ( | Fit< T > & | estimator ) |
Constructs an instance of RansacGenericFittingModel.
[in] | model | A fitting class. |
Definition at line 166 of file RansacGenericFittingModel.hpp.
Documentation generated by Doxygen