# Skeleton, measuring a curve length

**URL:** <https://discourse.slicer.org/t/skeleton-measuring-a-curve-length/1665>\
**Category:** Support\
**Created:** [December 15, 2017, 10:06am UTC](https://discourse.slicer.org/t/skeleton-measuring-a-curve-length/1665 "2017-12-15T10:06:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [December 15, 2017, 10:06am UTC](https://discourse.slicer.org/t/skeleton-measuring-a-curve-length/1665/1 "2017-12-15T10:06:00Z")

</div>

Operating system: Ubuntu 16  
Slicer version: 4.8  
Expected behavior: getting an output  
Actual behavior: infinite loop

Dear all,  
I have few questions related automatic measurement the length of an object in Slicer. The object is already segmented out and saves as a label. This object has a curvy shape so Ruler tool does not work.  
Here are what I already tried:

- I tried “Extract Skeleton” module with different parameters but it goes on infinite loop. Why I get such behavior? in case it works, how can I compute the length as the output is just number of points that already decided by the user?
- I tried “BinaryThinningImageFilter”, it works and I get a curve from the object. How can I measure this curve length?

Thanks!  
Ibraheem

---

<div class="post-metadata">

**Author:** ![Frederic](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/frederic/32/4907_2.png) [@Frederic](https://discourse.slicer.org/u/Frederic)\
**Post date:** [December 15, 2017, 12:16pm UTC](https://discourse.slicer.org/t/skeleton-measuring-a-curve-length/1665/2 "2017-12-15T12:16:53Z")

</div>

You could use: CurveMaker (since the Extension Manager)  
Best.

---

<div class="post-metadata">

**Author:** ![Nicole\_Aucoin](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Nicole\_Aucoin](https://discourse.slicer.org/u/Nicole_Aucoin)\
**Post date:** [December 15, 2017, 3:28pm UTC](https://discourse.slicer.org/t/skeleton-measuring-a-curve-length/1665/3 "2017-12-15T15:28:04Z")

</div>

Another (less precise) option is that if you place fiducials close together  
along the length of a curve, you can get the summed linear distance between  
all the highlighted fiducials in the Markups module by right clicking in  
the table.

Nicole

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [December 26, 2017, 8:02pm UTC](https://discourse.slicer.org/t/skeleton-measuring-a-curve-length/1665/4 "2017-12-26T20:02:19Z")

</div>

Many thanks for the info. Actually, I am trying to automate things here. Here is what I tried and it works so far.

First I apply “BinaryThinningImageFilter” on the label then I apply “Extract Skeleton”.  
With this, I get a nice list of points that represent my curve in a text file. What I need to do now is to accumulate the distance between all these points. If there is already a python script for this, I appreciate sharing it. If not, I will try to write it and share it with everyone.  
I guess it will be something like (please correct me if I am wrong):

- P1 = the first point in the text file
- P1 =IJK2RAS(P1)
- D = 0
- for all remaining points p  
P2 = p  
P2 =IJK2RAS(P2)  
D = D + dist(P1,P2)  
P1=P2

Thanks!  
Ibraheem

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [December 27, 2017, 4:13pm UTC](https://discourse.slicer.org/t/skeleton-measuring-a-curve-length/1665/5 "2017-12-27T16:13:15Z")

</div>

Here is the script:

```
    import numpy as np
    inputFileName = "CurveLength.txt"
    print("================= Start Process =====================")             
    # Get GetIJKToRASMatrix from the input volume
    mFid = self.inputSelector.currentNode() # this is a slicer.qMRMLNodeComboBox()
    mRAS=vtk.vtkMatrix4x4(); 
    mFid.GetIJKToRASMatrix(mRAS)
    Distance = 0 # curve length in mm
    i= 0 # counter
    f = open(inputFileName,'r')
    for line in f:       
        i = i + 1 
        lineDig=[int(s) for s in line.split() if s.isdigit()] 
        Pijk = [lineDig[1],lineDig[2],lineDig[3], 1]
        Pras = mRAS.MultiplyDoublePoint(Pijk)
        if (i>1):
           P2x= Pras[0] ; P2y= Pras[1] ; P2z= Pras[2] ;  
           Distance = Distance + np.sqrt((P2x-P1x)**2 + (P2y-P1y)**2 + (P2z-P1z)**2)                  
           P1x= Pras[0] ; P1y= Pras[1] ; P1z= Pras[2] ;  
        else:
           P1x= Pras[0] ; P1y= Pras[1] ; P1z= Pras[2] ;  
    f.close()
    print(Distance) 

```

Still one problem. I get a length different from the one I get manually using the fiducial. Am I missing somethng?

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [January 10, 2018, 9:24pm UTC](https://discourse.slicer.org/t/skeleton-measuring-a-curve-length/1665/6 "2018-01-10T21:24:39Z")

</div>

I found out the points generated by the text files are not all the points generated by the skeleton filter, please check the images. The fiducial points represent the points from the text file. Any suggestion to correct this?

 ![skel01](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/1/a125f9a8500e709d435ceb43c2fbb7578aff14ef.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 11, 2018, 4:39am UTC](https://discourse.slicer.org/t/skeleton-measuring-a-curve-length/1665/7 "2018-01-11T04:39:39Z")

</div>

Have you enabled “Do not prune branches” option in “Extract skeleton” module?

---

<div class="post-metadata">

**Author:** ![Hamid](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@Hamid](https://discourse.slicer.org/u/Hamid)\
**Post date:** [July 4, 2021, 8:35pm UTC](https://discourse.slicer.org/t/skeleton-measuring-a-curve-length/1665/8 "2021-07-04T20:35:08Z")

</div>

What does the e.g “0.015 mm-1” in measurement of curvature in Markup? does it mean the redius of curvature is 1000/15 mm?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 5, 2021, 6:32pm UTC](https://discourse.slicer.org/t/skeleton-measuring-a-curve-length/1665/9 "2021-07-05T18:32:19Z")

</div>

The value that Slicer computes is the curvature of a curve. You can look up the exact definition I. Wikipedia, but in short, curvature is 1/R where R is the radius of the circle that best approximates the curve at that point. For a circle that has a radius of 10 mm the curvature of every point is 0.1 and the unit is 1/mm.
