Image Processing - Finding Length and Diameter of a Curved Object.

11 views (last 30 days)
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.
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
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.

Sign in to comment.

Accepted Answer

Image Analyst
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
Kevin K
Kevin K on 25 Sep 2015
I hope to use this program on samples that are less uniform such as plant roots, so I will try the EDT method. I take it that in order to multiply the EDT by the skeletonized image they must both be square. I use imrect to select a region in the image so I will have to force the selection to be a square. Is this all really as simple as matrix multiplication?
I still need to get rid of the extra branches and the oddities at the beginning and the end of the wire. Do you have any recommendations?
I was thinking of using bwmorph('branchpoints') to find and remove the branchpoint pixels, and then identify the different sections as objects and delete the unwanted branches. I am not certain how to reliable identify the segments because they will be very close together in some instances (such as sharing a pixel diagonally).
Thank you very much for the advice and have a good day,
Kevin
Image Analyst
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!