Skip to content

Commit

Permalink
Check for RMSE when inlier count is same
Browse files Browse the repository at this point in the history
  • Loading branch information
PranjalSahu committed Dec 21, 2022
1 parent 58aebfd commit 07d57c5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/itkLandmarkRegistrationEstimator.h
Expand Up @@ -69,7 +69,7 @@ class LandmarkRegistrationEstimator : public itk::ParametersEstimator<Point<doub
virtual bool
Agree(std::vector<double> & parameters, Point<double, Dimension> & data) override;

virtual std::vector<bool>
virtual std::vector<double>
AgreeMultiple(std::vector<double> & parameters, std::vector<Point<double, Dimension>> & data, unsigned int currentBest) override;

virtual bool
Expand Down
6 changes: 3 additions & 3 deletions include/itkLandmarkRegistrationEstimator.hxx
Expand Up @@ -371,7 +371,7 @@ LandmarkRegistrationEstimator<Dimension, TTransform>::CheckCorresspondenceDistan
}

template <unsigned int Dimension, typename TTransform>
std::vector<bool>
std::vector<double>
LandmarkRegistrationEstimator<Dimension, TTransform>::AgreeMultiple(std::vector<double> & parameters,
std::vector<Point<double, Dimension>> & data, unsigned int currentBest)
{
Expand All @@ -398,7 +398,7 @@ LandmarkRegistrationEstimator<Dimension, TTransform>::AgreeMultiple(std::vector<
transform->SetParameters(optParameters);

std::vector<double> query_pt(3);
std::vector<bool> output(data.size(), false);
std::vector<double> output(data.size(), -1.0);
//output.reserve(data.size());

const size_t num_results = 1;
Expand Down Expand Up @@ -434,8 +434,8 @@ LandmarkRegistrationEstimator<Dimension, TTransform>::AgreeMultiple(std::vector<
if (flag)
{
localBest++;
output[i] = out_dists_sqr[0];
}
output[i] = flag;
}

return output;
Expand Down
2 changes: 1 addition & 1 deletion include/itkParametersEstimator.h
Expand Up @@ -86,7 +86,7 @@ class ITK_TEMPLATE_EXPORT ParametersEstimator : public Object
virtual bool
Agree(std::vector<SType> & parameters, T & data) = 0;

virtual std::vector<bool>
virtual std::vector<double>
AgreeMultiple(std::vector<SType> & parameters, std::vector<T> & data, unsigned int currentBest) = 0;

virtual bool
Expand Down
1 change: 1 addition & 0 deletions include/itkRANSAC.h
Expand Up @@ -203,6 +203,7 @@ class ITK_TEMPLATE_EXPORT RANSAC : public Object
// agrees with the best model, otherwise false
bool * bestVotes;
unsigned int numVotesForBest;
double bestRMSE;

std::vector<T> data;
std::vector<T> agreeData;
Expand Down
9 changes: 7 additions & 2 deletions include/itkRANSAC.hxx
Expand Up @@ -345,19 +345,24 @@ RANSAC<T, SType, TTransform>::RANSACThreadCallback(void * arg)

// Expensive Inlier Test
auto result = caller->paramEstimator->AgreeMultiple(exactEstimateParameters, caller->agreeData, caller->numVotesForBest);
double rmse_value = 0.0;

for (m = 0; m < numAgreeObjects; m++)
{
if (result[m])
if (result[m] > 0)
{
curVotes[m] = true;
numVotesForCur++;
rmse_value = rmse_value + result[m];
}
} // found a larger consensus set?

caller->resultsMutex.lock();
if (numVotesForCur > caller->numVotesForBest)
if (numVotesForCur > caller->numVotesForBest || (numVotesForCur == caller->numVotesForBest && rmse_value < caller->bestRMSE))
{
caller->numVotesForBest = numVotesForCur;
caller->bestRMSE = rmse_value;

std::copy(curVotes, curVotes + numAgreeObjects, caller->bestVotes);

caller->parametersRansac.clear();
Expand Down

0 comments on commit 07d57c5

Please sign in to comment.