Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Contour segmentation

Hey there,

I have a contour which consists of curved segments and straigth segments. Is there any possibility to segment the contour into the curved and straigth parts? So this is an example for a contour

image description

I would like to have a segmentation like this:

image description

Do you have any idea how I could solve such a problem

Thank you very much and best regards

Contour segmentation

Hey there,

I have a contour which consists of curved segments and straigth segments. Is there any possibility to segment the contour into the curved and straigth parts? So this is an example for a contour

image description

I would like to have a segmentation like this:

image description

Do you have any idea how I could solve such a problem

Thank you very much and best regards

The solution is to calculate the curvature:

vector<double> getCurvature(vector<Point> const& tContourPoints, int tStepSize)
{
int iplus;
int iminus;

double acurvature;
double adivisor;

Point2f pplus;
Point2f pminus;
Point2f a1stDerivative;
Point2f a2ndDerivative;

vector< double > rVecCurvature( tContourPoints.size() );

if ((int)tContourPoints.size() < tStepSize)
{
      return rVecCurvature;
}

for (int i = 0; i < (int)tContourPoints.size(); i++ )
{
const Point2f& pos = tContourPoints[i];

iminus  = i-tStepSize;
iplus   = i+tStepSize;

if(iminus < 0)
{
    pminus = tContourPoints[iminus + tContourPoints.size()];
}
else
{
    pminus = tContourPoints[iminus];
}

if(iplus  > (int)tContourPoints.size())
{
    pplus = tContourPoints[iplus - (int)tContourPoints.size()];
}
else
{
    pplus = tContourPoints[iplus];
}

a1stDerivative.x = (pplus.x -           pminus.x) / ( iplus-iminus);
a1stDerivative.y = (pplus.y -           pminus.y) / ( iplus-iminus);
a2ndDerivative.x = (pplus.x - 2*pos.x + pminus.x) / ((iplus-iminus)/2*(iplus-iminus)/2);
a2ndDerivative.y = (pplus.y - 2*pos.y + pminus.y) / ((iplus-iminus)/2*(iplus-iminus)/2);


adivisor = a2ndDerivative.x*a2ndDerivative.x + a2ndDerivative.y*a2ndDerivative.y;
if (  abs(adivisor) > 10e-8 )
{
    acurvature =   abs(a2ndDerivative.y*a1stDerivative.x - a2ndDerivative.x*a1stDerivative.y) / pow(adivisor, 3.0/2.0 )  ;
}
else
{
    acurvature =  numeric_limits<double>::infinity();
}

rVecCurvature[i] = acurvature;
}
return rVecCurvature;
}

and the you can segment it with a specific border value