I have some code lying around that will do this. It's not the most efficient way though, but if you just need a quick solution: def floyd_warshall(x,y):
dist = np.sqrt((x[:,np.newaxis]-x[np.newaxis,:])**2 + (y[:,np.newaxis]-y[np.newaxis,:])**2) d = np.array(dist) d[dist>1.5] = np.inf # sqrt(2) < 1.5 < 2 n = len(x) for k in xrange(n): kd = d[:,k,np.newaxis] + d[k,:] d = np.minimum(d,kd) return d skel = np.argwhere(skel) x, y = skel[:,0], skel[:,1] d = np.max(floyd_warshall(x,y))
(if you have many seperated skeletons it's worth doing each label
independently)
A better method is to find the two end points and use Dijkstra's algorithm
on those.
On 18 November 2015 at 06:43, Pratap Vardhan
My first thought was what Juan suggested and seemed logical to do that.
As an alternative, you could also (this may be an overfill and could be slower than network approach) try.
1. From every endpoints of skeleton compute the distance transform (using flood-fill or neighbourhood methods). 2. Now the maximum distance for above all distances will give you the longest path in skeleton.
This way you can have the trace path of the longest thread in skeleton in image form itself.
On Wednesday, November 18, 2015 at 8:52:05 AM UTC+5:30, Arctic_python wrote:
Hello, Anyone has suggestions for an algorithm to measure the length of a skeleton line/thread(e.g http://scikit-image.org/docs/dev/auto_examples/plot_skeleton.html)? The context- I skeletonize a shape to infer its length. Thanks
-- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.