
Image Processing - Finding Length and Diameter of a Curved Object.
11 views (last 30 days)
Show older comments
I have a curved wire, and I am trying to find its contour length and average diameter.
I have already imported the image and converted it to a binary matrix. I then cleaned up the image with bwareaopen, imfill, and imopen. I found the perimeter of the wire with bwperim and I hope to now find the centerline of the wire. This is where I am having trouble. I hope to calculate the contour length of the centerline to get the length of the wire, and will use the difference between the perimeter lines and the centerline to find radius.
I have attempted to use bwmorph(IMG,'skel') and bwmorph(IMG,'thin) to find the centerline, however I havn't found a method of properly trimming the branches without affecting the centerline. (I have tried bwmorph(IMG,'spur) I end up with the image below after using the thin function.
- Starting image: http://imgur.com/YMG3ZWm (The white box on the right is used for a scale and is 127.4 mm long)
- MATLAB bwmorph thin image: http://imgur.com/mc0jkrh
- MATLAB bwmorph skel image: http://imgur.com/pUy2Xeo
Both of the bwmorph images appear to have gaps however they are continuous.
I have seen forum users such as Image Analyst suggest taking the skeleton and multiplying it by the euclidean distance transform of the original image to find the distances however I haven't been able to get that method to work either.
Any advice would be great. I have been stuck on this all week.
Thanks,
Kevin
3 Comments
Image Analyst
on 24 Apr 2023
Edited: Image Analyst
on 24 Apr 2023
@Ankit Jaiswal please start your own discussion thread on this, and let us know there if the tube walls are in the same place in every image, and if you have an image with no curved object in it (and attach that image if you do).
Attach your data and code to read it in with the paperclip icon, in your new discussion thread, after you read this:
I gave you a start in the attachments.

Ankit Jaiswal
on 28 Apr 2023
Edited: Ankit Jaiswal
on 28 Apr 2023
please find problem as per your instructions.please reply to the question by visiting above link.
Accepted Answer
Image Analyst
on 25 Sep 2015
For a long skinny object, you can get the length by getting the perimeter and dividing by 2, which is a fair guess for thin things but less accurate as the object gets thicker. Then the diameter is just the area divided by the length.
The gaps you see are most likely just due to subsampling for display - like you said they're really continuous.
The thinned object looks pretty good. Maybe you can get the length just by summing the binary image to add up all the white pixels. Then the width (diameter) is the full area divided by the length.
If you really need the diameter as a function of length, or if you want a histogram of different diameters, then you need to use the method you said I mentioned - multiplying the EDT by the thinned or skeletonized image. You wouldn't need to do this for your image since the width is pretty uniform. If your object is really lumpy and you wanted all the diameters then you'd have to do that, but I don't think you need to in your case.
2 Comments
Image Analyst
on 26 Sep 2015
MATLAB does not have a good function for removing all the shortest branches and leaving just the longest ones. I again let the developers know of that need yesterday.
The EDT image and the skeleton or thinned image will have the same size. They do not need to be square. You can crop out some portion with imrect() or rbbox() if you wish but you should crop it out of the original gray scale image first, then that will guarantee any other images you generate will have that same size and the multiplication will work perfectly.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!