How to calculate this crack from this image

How to calculate crack from this image, i have picture ceramic and i want to calculate from this image, there are any defect from this image you can see this below
you can see, there are cracks in the image defects how can I calculate the length of cracks in the image. I have to ask where else confused please help

 Accepted Answer

You might want to skeletonize with the bwmorph() function. Then all you will have are the centerlines of the cracks.
binaryImage = bwmorph(binaryImage, 'skel', inf');
Then call regionprops and ask for the area which will be the length of the cracks in pixels.
measurements = regionprops(binaryImage, 'Area');

6 Comments

image analyst thanks for your attention. I have to enter the code that you have given to me. The first to use the method skeleton, what the picture as below
sorry if I make mistakes
OK. Looks good so far. You might want to run bwareaopen first to get rid of very small regions. You can use regionprops (like I showed you) to get each crack's length or you can get the total crack length for the entire image just by summing the binary image
totalCrackLength = sum(binaryImage(:));
may I ask about the program, whether the program would be like this
binaryImage = bwmorph(im1,'skel','inf');
figure, imshow(binaryImage);
title('skeleton');
measurements = regionprops(binaryImage, 'Area');
totalCrackLength = sum(binaryImage(:));
measurements
totalCrackLength
Looks about right. You might want to extract the line lengths into an array instead of leaving them in the structure:
allCrackLengths = [measurements.Area];
That will be an array with the length for each individual crack. sum(allCrackLengths) will equal totalCrackLength.
What if I want to get how many cracks in the amount not in the array, and what if I want to get the longest and shortest of these cracks.
thanks so much for your attention and help my problem. ^_^
That can all be done by examining the measurements returned by regionprops(). Have you studied my image segmentation tutorial yet, where it does that kind of stuff? http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

Sign in to comment.

More Answers (2)

How does this question differ from your existing question at http://www.mathworks.co.uk/matlabcentral/answers/41089-crack-detection ?

5 Comments

yes but the question has not been received, so the question on specialize to detect. and I made the two questions are connected. if you think it's the same then I'll delete this question
They seem the same to me. Walter or I can delete this question later today and you can follow up on your prior thread. But it looks like your professors are not letting you use any code given to you by senior developers (like me) - that's what it seemed like you said - so I guess we're at the point where you need to take over.
thanks for help, I might be any suggestions for this problem. but i just want to learn and do not expect the code if you feel I am expecting from your code, yes indeed I expected. it is to learn so that I can understand. because learning from examples is the one - the only way to learn.
previous question I asked about the best way to detect defects on the surface of the ceramic is not included for the calculation, because the code that I wrote for the detection using the same method as before. I am in order to replace it and I am confused to use the best method.
for this question to calculations and I think the first question representing this question. I am so sorry it please delete this question

Sign in to comment.

Preetham Manjunatha
Preetham Manjunatha on 19 Dec 2024
Edited: Preetham Manjunatha on 16 May 2025
Here is the MATLAB Crack segmentation and Crack width, length and area estimation codes to calculate/estimate the crack area, width and length. In addition, this package assumes the crack is segmented either using morphological method or multiscale gradient-based or deep learning semantic segmentation methods. This package estimates the crack area, width and length (pixel scale can be provided to estimate these physical quantities). Lastly, the semantic segmentation and object detection metrics for the cracks can be found using Cracks binary class bounding box and segmentation metrics package.

Community Treasure Hunt

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

Start Hunting!