Length of a thin curved object in an image

2 次查看(过去 30 天)
I'd like to use image analysis to calculate the length of a thread.
Because the thread is not entirely straight, I can't just use regionprops, so I think the best option is to use the function bwdistgeodesic
In the bwdistgeodesic function, what is it expecting for the variable "mask"? How could I use image analysis to generate said mask? I've looked into using regionprops 'Extrema' property, but since I'm not sure what the "mask" variable is in bwdistgeodesic, I'm not sure how I would use the x,y dimensions from 'Extrema' in a mask.
I've attached the example image I'm using - with a "thread" and a one inch coin for size reference.

采纳的回答

Matt J
Matt J 2018-1-9
编辑:Matt J 2018-1-9
Because the thread is not entirely straight, I can't just use regionprops,
Why not? Couldn't you just do
S=regionprops( bwareafilt(BW,1,'smallest') ,'Perimeter');
length=S.Perimeter/2
  4 个评论
Audrey
Audrey 2018-1-9
Actually, the new issue I'm having is that the perimeter edge is very jagged, and it's giving me a longer value than expected. I wonder if this can be improved by reducing the size of the image and using sgolayfilt. I'm not sure if that can be used on the image itself, or if I have to draw the perimeter line, and then apply the filter to that.
Matt J
Matt J 2018-1-9
I think you could just extract the points using regionprops(...,'PixelList') and then apply filtering.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2018-1-9
Assuming your line is just a one pixel thick line, you could just compute the area with bwarea() which weights the area depending on the shape of the boundary.
binaryImage = bwareafilt(binaryImage, 1, 'smallest'); % Extract smallest area.
% Now only the line is remaining.
lineLength = bwarea(binaryImage); % Get area, which is it's length.
  2 个评论
Audrey
Audrey 2018-1-10
Hi IA,
The future goal is to be able to do this with a real image, and when I tried this (with image below), the binary image produced a line that was many pixels wide, and a bit jagged. I'm working on using filtering to smooth this, but if you have other ideas let me know!
here's that picture:
Matt J
Matt J 2018-1-10
If it's many pixels wide, you could try to thin it using,
BW = bwmorph(BW,'skel',Inf);

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by