struct Point
{
Point(int_t _x, int_t _y) : x(_x), y (_y)
{
}
int_t x;
int_t y;
};
typedef std::list<Point*> points_t;
double euclideanDistance(const Point& lhs,const Point& rhs)
{
double p1 = std::pow((float)(rhs.x - lhs.x), 2);
double p2 = std::pow((float)(rhs.y - lhs.y), 2);
double vd = std::sqrt(p1 + p2);
return vd;
}
double hausdorffPHD(points_t seta, points_t setb)
{
double maxDistance = 0;
points_t::iterator afront = seta.begin();
points_t::iterator aback = seta.end();
std::vector<double> ranking;
for(int_t i=0; afront != aback ; ++afront, ++i)
{
Point* a = *afront;
double minDistance = std::numeric_limits<double>::max();
points_t::iterator bfront = setb.begin();
points_t::iterator bback = setb.end();
for(; bfront != bback ; ++bfront)
{
Point* b = *bfront;
double ed = euclideanDistance(*a, *b);
if (ed < minDistance)
minDistance = ed;
}
ranking.push_back(minDistance);
}
std::sort(ranking.begin(), ranking.end());
double fraction = .7;
int k = (int) (seta.size() * fraction);
return ranking[k];
}
double hausdorff(points_t seta, points_t setb)
{
double habPHD = hausdorffPHD( seta, setb);
double hbaPHD = hausdorffPHD( setb, seta);
double distancePHD = std::max(habPHD, hbaPHD);
printf("hd = %0.4f\t %0.4f\t %0.4f\t \n", distancePHD, habPHD, hbaPHD);
return distancePHD;
}
int_t main(int_t argc, char_t** args)
{
points_t seta;
points_t setb;
seta.push_back(new Point(1,2));
seta.push_back(new Point(2, 4));
setb.push_back(new Point(2, 4));
setb.push_back(new Point(3, 4));
double val = hausdorff(seta, setb);
} |

struct Point
{
Point(int_t _x, int_t _y) : x(_x), y (_y)
{
}
int_t x;
int_t y;
};
typedef std::list<Point*> points_t;
double euclideanDistance(const Point& lhs,const Point& rhs)
{
double p1 = std::pow((float)(rhs.x - lhs.x), 2);
double p2 = std::pow((float)(rhs.y - lhs.y), 2);
double vd = std::sqrt(p1 + p2);
return vd;
}
double hausdorffPHD(points_t seta, points_t setb)
{
double maxDistance = 0;
points_t::iterator afront = seta.begin();
points_t::iterator aback = seta.end();
std::vector<double> ranking;
for(int_t i=0; afront != aback ; ++afront, ++i)
{
Point* a = *afront;
double minDistance = std::numeric_limits<double>::max();
points_t::iterator bfront = setb.begin();
points_t::iterator bback = setb.end();
for(; bfront != bback ; ++bfront)
{
Point* b = *bfront;
double ed = euclideanDistance(*a, *b);
if (ed < minDistance)
minDistance = ed;
}
ranking.push_back(minDistance);
}
std::sort(ranking.begin(), ranking.end());
double fraction = .7;
int k = (int) (seta.size() * fraction);
return ranking[k];
}
double hausdorff(points_t seta, points_t setb)
{
double habPHD = hausdorffPHD( seta, setb);
double hbaPHD = hausdorffPHD( setb, seta);
double distancePHD = std::max(habPHD, hbaPHD);
printf("hd = %0.4f\t %0.4f\t %0.4f\t \n", distancePHD, habPHD, hbaPHD);
return distancePHD;
}
int_t main(int_t argc, char_t** args)
{
points_t seta;
points_t setb;
seta.push_back(new Point(1,2));
seta.push_back(new Point(2, 4));
setb.push_back(new Point(2, 4));
setb.push_back(new Point(3, 4));
double val = hausdorff(seta, setb);
}

## One thought on “Calculating partial Hausdorff Distance”

Thank you!

This article useful.

Magiamgia