How to calculate the maximum width of object in binary image?
5 views (last 30 days)
Show older comments
Here is the binary image and I want to get the maximum width of the object(the gap between the right and left edges). Currently I used minboundrect function to get this max distance on a rectangular bound.
I am thinking is there any function that can tell you the direction vector anywhere along the right edge, and determine tangent and normal vector at each edge, then extend it in each direction until it hits the edge of the left edge.
Appreciate any thoughts and helps on this. Thanks!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162914/image.png)
0 Comments
Accepted Answer
Image Analyst
on 13 Apr 2017
Use bwdist():
edtImage = bwdist(binaryImage);
maxDiam = 2 * max(edtImage(:)); % Max() will give the radius.
12 Comments
Muhammad Usman khan
on 11 Jun 2017
Hey, Thanks everyone. I am still hoping to get automatically line(Not circle) coordinates(i.e P1,P2 in the image) of the maximum width of an object of any orientation in the image.
Image Analyst
on 11 Jun 2017
I don't have any code for that now, so you can write it. I'd just look at all the pixels within +/- radius from the center row and column, and send a line out from the center to any pixel that is the radius away from the center. There should only be a few pixels that are that exact distance away. It's a brute force method but it's intuitive, easy, and fast (because there aren't that many pixels to examine). It's not hard, trust me. I want you to try it and then share the final code once you've got it working.
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!