# Revision history [back]

### better ways to get the ridges of distance transform map?

Hi there, I'm considering use distance transform map to do some finger detection. I drew a hand, distance transformed it and normalized. It's very useful to find the palm center and I drew a circle to label it. (Fig.1 a hand transformed by distance transform function)

It seems the ridges of the finger and the palm is very clear to my naked eyes and I want to do something to draw the ridge. just like: (Fig.2 the ridges painted by painter)

I do something like derivative along the X-axis and Y-axis and the code is like:

for(int i=5;i<dist.rows-5;i+=1)
{
for(int j=5;j<dist.cols-5;j+=1)
{

if(dist.at<float>(i,j)>0.1)
{
if(dist.at<float>(i,j)>dist.at<float>(i,j-5)&&
dist.at<float>(i,j)>dist.at<float>(i,j+5))
{
circle(thinfinger,Point2f(j,i),5,CV_RGB(255,0,0),-1);
}

if(dist.at<float>(i,j)>dist.at<float>(i-5,j)&&
dist.at<float>(i,j)>dist.at<float>(i+5,j))
{
circle(thinfinger,Point2f(j,i),5,CV_RGB(255,0,0),-1);
}
}
}
}

for(int j=5;j<dist.cols-5;j+=1)
{
for(int i=5;i<dist.rows-5;i+=1)
{

if(dist.at<float>(i,j)>0.1)
{
if(dist.at<float>(i,j)>dist.at<float>(i,j-5)&&
dist.at<float>(i,j)>dist.at<float>(i,j+5))
{
circle(thinfinger,Point2f(j,i),6,CV_RGB(255,0,0),-1);
}

if(dist.at<float>(i,j)>dist.at<float>(i-5,j)&&
dist.at<float>(i,j)>dist.at<float>(i+5,j))
{
circle(thinfinger,Point2f(j,i),6,CV_RGB(255,0,0),-1);
}
}
}

}


the codes find the singularity point and draw it in another mat, the result shows: (Fig.3 the ridges of distance transform map)

The result seems reasonable but there are always somewhere not connected together,especially in the seams between the finger and the palm. The result could be better if I do the derivative from more different angles, but it would always some gaps there.

I search the forum to find better solutions. One recommanded "Zhang-Suen fast thinning algorithm", but it seems really slow when I want to do realtime tracking. I searched some jounral papers,and some say that path-finding algorithm can connect all together well. But actually I did the path-finding after and found that the path-finding result can be improved by skeletonizing the fingers, so it's strange to do the path-finding before path-finding.

It's any method I can find the well-connected ridges of distance transform map?