OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 06 Jul 2016 04:49:01 -0500better ways to get the ridges of distance transform map?http://answers.opencv.org/question/97681/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.
![image description](/upfiles/14673595031051984.png)
(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:
![image description](/upfiles/14673596752646641.png)
(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:
![image description](/upfiles/1467360122407247.png)
(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?Fri, 01 Jul 2016 03:25:59 -0500http://answers.opencv.org/question/97681/better-ways-to-get-the-ridges-of-distance-transform-map/Comment by LBerger for <p>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.</p>
<p><img alt="image description" src="/upfiles/14673595031051984.png"/></p>
<p>(Fig.1 a hand transformed by distance transform function)</p>
<p>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:</p>
<p><img alt="image description" src="/upfiles/14673596752646641.png"/></p>
<p>(Fig.2 the ridges painted by painter)</p>
<p>I do something like derivative along the X-axis and Y-axis and the code is like:</p>
<pre><code>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);
}
}
}
}
</code></pre>
<p>the codes find the singularity point and draw it in another mat, the result shows:</p>
<p><img alt="image description" src="/upfiles/1467360122407247.png"/></p>
<p>(Fig.3 the ridges of distance transform map)</p>
<p>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.</p>
<p>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.</p>
<p>It's any method I can find the well-connected ridges of distance transform map?</p>
http://answers.opencv.org/question/97681/better-ways-to-get-the-ridges-of-distance-transform-map/?comment=97860#post-id-97860may be this one http://www.sciencedirect.com/science/article/pii/0734189X87900545. bibiography is necessary..Mon, 04 Jul 2016 06:58:28 -0500http://answers.opencv.org/question/97681/better-ways-to-get-the-ridges-of-distance-transform-map/?comment=97860#post-id-97860Comment by gino0717 for <p>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.</p>
<p><img alt="image description" src="/upfiles/14673595031051984.png"/></p>
<p>(Fig.1 a hand transformed by distance transform function)</p>
<p>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:</p>
<p><img alt="image description" src="/upfiles/14673596752646641.png"/></p>
<p>(Fig.2 the ridges painted by painter)</p>
<p>I do something like derivative along the X-axis and Y-axis and the code is like:</p>
<pre><code>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);
}
}
}
}
</code></pre>
<p>the codes find the singularity point and draw it in another mat, the result shows:</p>
<p><img alt="image description" src="/upfiles/1467360122407247.png"/></p>
<p>(Fig.3 the ridges of distance transform map)</p>
<p>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.</p>
<p>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.</p>
<p>It's any method I can find the well-connected ridges of distance transform map?</p>
http://answers.opencv.org/question/97681/better-ways-to-get-the-ridges-of-distance-transform-map/?comment=97979#post-id-97979this algorithm also work well but not so different to Zhang-Suen or Guo-Hall algorithm, and these algorithms always cost a lot of time unless using some parallel processing technique. I find a old article here talking about using the distance transform map to find the skeleton,
http://www.sciencedirect.com/science/article/pii/016786559290074A
but the figure is not so clear that I cannot estimate whether the result is good or not.Wed, 06 Jul 2016 04:49:01 -0500http://answers.opencv.org/question/97681/better-ways-to-get-the-ridges-of-distance-transform-map/?comment=97979#post-id-97979Comment by LBerger for <p>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.</p>
<p><img alt="image description" src="/upfiles/14673595031051984.png"/></p>
<p>(Fig.1 a hand transformed by distance transform function)</p>
<p>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:</p>
<p><img alt="image description" src="/upfiles/14673596752646641.png"/></p>
<p>(Fig.2 the ridges painted by painter)</p>
<p>I do something like derivative along the X-axis and Y-axis and the code is like:</p>
<pre><code>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);
}
}
}
}
</code></pre>
<p>the codes find the singularity point and draw it in another mat, the result shows:</p>
<p><img alt="image description" src="/upfiles/1467360122407247.png"/></p>
<p>(Fig.3 the ridges of distance transform map)</p>
<p>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.</p>
<p>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.</p>
<p>It's any method I can find the well-connected ridges of distance transform map?</p>
http://answers.opencv.org/question/97681/better-ways-to-get-the-ridges-of-distance-transform-map/?comment=97706#post-id-97706I think you need median axis or skeleton algorithm. About Skeleton you have this [post](http://answers.opencv.org/question/3207/what-is-a-good-thinning-algorithm-for-getting-the-skeleton-of-characters-for-ocr/)Fri, 01 Jul 2016 06:34:38 -0500http://answers.opencv.org/question/97681/better-ways-to-get-the-ridges-of-distance-transform-map/?comment=97706#post-id-97706Comment by gino0717 for <p>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.</p>
<p><img alt="image description" src="/upfiles/14673595031051984.png"/></p>
<p>(Fig.1 a hand transformed by distance transform function)</p>
<p>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:</p>
<p><img alt="image description" src="/upfiles/14673596752646641.png"/></p>
<p>(Fig.2 the ridges painted by painter)</p>
<p>I do something like derivative along the X-axis and Y-axis and the code is like:</p>
<pre><code>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);
}
}
}
}
</code></pre>
<p>the codes find the singularity point and draw it in another mat, the result shows:</p>
<p><img alt="image description" src="/upfiles/1467360122407247.png"/></p>
<p>(Fig.3 the ridges of distance transform map)</p>
<p>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.</p>
<p>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.</p>
<p>It's any method I can find the well-connected ridges of distance transform map?</p>
http://answers.opencv.org/question/97681/better-ways-to-get-the-ridges-of-distance-transform-map/?comment=97838#post-id-97838I tried the code, the result is good but really slow.Mon, 04 Jul 2016 02:14:49 -0500http://answers.opencv.org/question/97681/better-ways-to-get-the-ridges-of-distance-transform-map/?comment=97838#post-id-97838