How to Get Length of Thick Lines from Image?
5 views (last 30 days)
Show older comments
I would like to calculate the length of individual sections of the road.
Originally, I have a road map image. Using image segmentation, I have isolated sections of the road as seen below.

I would like to calculate the length of each individual white section in pixels (i.e. the length of each section of the road including bends). What's the best way to do this?
I've tried using 'bwlabel' & 'regionprops' to split it into sections and use 'MajorAxisLength' (explained here https://uk.mathworks.com/matlabcentral/fileexchange/25157-image-segmentation-tutorial). As the original image isn't perfect and has some letters overlaid onto it, this results in too many sections around the letters (on the right) seen here

Next, I tried to use 'houghlines' to find the length (explained here https://uk.mathworks.com/help/images/ref/houghlines.html). As the lines are thick, it doesn't seem to work well. Using the 'edge' function first, I get this

Without the 'edge' function, I get this

In both cases above, some white straight sections are not detected.
Ideally, I would like to get the result shown below, and subsequently measure the purple lines in pixels (Sorry, drawn in Paint, lines should be straight). What's the best way to do this?

2 Comments
Accepted Answer
Image Analyst
on 3 Aug 2018
Use bwdist() to compute the Euclidean Distance Transform of each blob. Then take a histogram of that. The mode will be the most common radius so multiply that by 2 to get the mean blob width. Try it. If you need help, ask. Here's a start:
[labeledImage, numberOfBlobs] = bwlabel(binaryImage);
for k = 1 : numberOfBlobs
thisBlob = ismember(labeledImage, k);
edtImage = bwdist(thisBlob);
[counts, binValues] = histcounts(edtImage);
modeRadius(k) = .....
meanWidth(k) = 2 * modeRadius
etc.....
end
I'm confident in your ability to finish this code. Try it, but if you can't do it, ask for more help.
13 Comments
Image Analyst
on 7 Aug 2018
Not sure. I think you may have to merge the labeled images and then relabel. Then figure out what component blobs went into making it. Then relabel and add them back in while not affecting any others. Seems like it would be a pain. I'd avoid it unless it's absolutely necessary. And I don't have code to do it so you're on your own.
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




