How to measure a crack length (using skeleton function)?
古いコメントを表示
I am trying to calculate the length of the crack (attached) however I can't figure out a way to remove the extra sections of the skeleton that branch off from the main crack path - crackoverlay.png.
Does anyone have any advice as to how I could do this?
clc
clear variables
RGB = imread('crack2.jpg'); % Aquires original image
I = rgb2gray(RGB); % Creates greyscale image
BW = imbinarize(I,'global'); % Binarises it
BW2 = ~(bwmorph(BW,'majority',Inf)); % Fills in holes
BW3 = bwmorph(BW2,'skel',Inf); % Reduces image to center areas of the white sections
BW4 = bwmorph(BW3,'spur',Inf); % Removes spurs
Ov = imfuse(RGB,BW4); % Overlay of original image and skeleton
figure('Name','All_Steps')
subplot(3,2,1), imshow(RGB), title('Original Image')
subplot(3,2,2), imshow(BW) , title('Binarised Image')
subplot(3,2,3), imshow(BW2), title('Binarised Inverted')
subplot(3,2,4), imshow(BW3), title('Skeleton')
subplot(3,2,5), imshow(BW4), title('Simplified Skeleton')
subplot(3,2,6), imshow(Ov), title('Overlay')
4 件のコメント
Adam Danz
2020 年 10 月 20 日
This is the shortest path problem and there are several algorithms you can search for and learn about. You can apply it to the coordinates in BW4 which can be found using [y,x]=find(~BW4). You'll probably need to identify the starting and ending points manually which can be done using ginput() or something slimiar and then finding the closest coordinates to your selection.
Thomas Bainbridge
2020 年 10 月 21 日
編集済み: Thomas Bainbridge
2020 年 10 月 22 日
Adam Danz
2020 年 10 月 22 日
Well done! Perhaps you could share your solution as an answer. I'd be interested in seeing it.
Thomas Bainbridge
2020 年 10 月 22 日
採用された回答
その他の回答 (1 件)
Jimena López de Uralde Gómez de Olea
2022 年 1 月 16 日
0 投票
the script was so helpfull for my program too thanks!!
one question, the units from the path length are pixels?
1 件のコメント
Image Analyst
2022 年 1 月 16 日
Yes, units are pixels. See attached spatial calibration demo and other demos.
Also, you might want to look at bwskel() - I think it has less spurs than bwmorph()
カテゴリ
ヘルプ センター および File Exchange で Morphological Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!