How do I measure the length of a certain linear object in the image?

5 次查看(过去 30 天)
Hello,
I have started working on image processing just recently and have a potential problem to which I am not able to find a definite answer. I am uploading the image and attaching a link as well. The problem is, I have a certain metal rod in the picture, on which I have performed binary thresholding with threshold set for all pixels below 240 to 0 and above to 255 (which I inspected using imtool manually), then a high pass filtering and finally a morphological opening operation with a strel element of length 10 and angle of 28 degrees (which I find out using imrotate manually since the original image has the rod at an angle and not exactly at 0 degrees to the horizontal x axis). I have a final image with just a sharp chipped off contour of the image. Now the problem I have is, I am unable to figure out a way to measure the length of this inclined contour using just a piece of code. Of course, I have tried using imtool to again manually examine the number of pixels between either ends of the contour, but that seemed tedious. I was just wondering if there is a way directly through the script so that I can directly generate a generalised script for measuring any inclined length in any future images? It would be of really great help if anyone could help me solve this conundrum.
Thanks in Advance
Original Picture:
pic1.jpg
Processed Picture:
modified_pic1.jpeg

采纳的回答

Matt J
Matt J 2019-4-6
编辑:Matt J 2019-4-6
Not sure how you want to define the length. This tries to get the length of the medial line,
BW=bwconvhull(BW); %Seal the gaps
BW=bwmorph(BW,'thin',Inf); %Get medial line
out_table=bwferet(BW,'MaxFeretProperties');
line_length=out_table{'MaxDiameter'}, %get line length

更多回答(1 个)

Image Analyst
Image Analyst 2019-4-6
Why are you using high pass filtering (edge detection) in the first place? Don't. No need for high pass filtering, bwconvhull() or bwmorph(). Just threshold and call find bwferet(). See examples in the help.
  3 个评论
Image Analyst
Image Analyst 2019-4-10
You must have a little bit of noise in your image so that you don't have just one dark object. You could use bwareafilt(mask, 1) to get just the one largest object instead of 39, or it you really think all those 38 other satellite blobs should really be part of your main object (and are not noise) then you can use bwconvhull() like you did.
If I helped you then maybe you could vote for the answer at the left under my icon.

请先登录,再进行评论。

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by