How to measure crack width

7 views (last 30 days)
yasmin ismail
yasmin ismail on 7 Mar 2023
Edited: yasmin ismail on 13 Jul 2023
I noticed that when I reduced the minimum acceptable area the crack width decreased although the appearance of blobs in this situation, while when i increased minimum acceptable area and the blobs removed and the width increased
for example:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 10;
% Read in image and convert to gray scale.
rgbImage = imread('7004-46.jpg');
I = rgb2gray(rgbImage);
subplot(2,2,1);
imshow(I);
title('7004-46');
% Take histogram.
subplot(2,2,2);
histogram(I);
grid on; %to make grid line
title('histogram Gray image');
% Binarize image.
threshold = 145;
xline(threshold, 'Color', 'r', 'LineWidth',2)
mask=I < threshold;
mask = imfill(mask, 'holes');
% Filter image.
se = strel('line',1, 0);
filteredImage = imclose(mask, se);
subplot(2, 2, 3);
imshow(filteredImage);
title('closed Image');
%%% Measure the areas to determin minAcceptableArea show the histogram of
%%% area
% props = regionprops(filteredImage, 'Area');
% allAreas = sort([props.Area], 'descend');
% histogram(allAreas)
%%Look at the histogram. What area do you think is the minimum size to be a valid crack?
minAcceptableArea =20;
mask = bwareafilt(filteredImage, [minAcceptableArea, inf]);
subplot(2, 2, 4);
imshow(mask);
%
% % Measure size of crack.
props = regionprops(mask, 'Area');
allAreas = [props.Area];
out=bwferet(mask)
% Measure the areas to know the area not to be considered
% props = regionprops(mask, 'Area');
% allAreas = sort([props.Area], 'descend')
% Get width = area / maximum length
averageWidths = sort(allAreas ./ out.MaxDiameter, 'descend');
message = sprintf('The average width = %.2f pixels.', averageWidths(1));
fprintf('%s\n', message);
caption = sprintf('Binary Image of Cracks larger than %d\nAverage width of largest = %.2f pixels', minAcceptableArea, averageWidths(1));
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
uiwait(helpdlg(message));
  2 Comments
yasmin ismail
yasmin ismail on 7 Mar 2023
another thing when i added the whole areas and divided by the maximum diamter I got different answer for example if minimum accpetable area is 100 the output is :
3×3 table
MaxDiameter MaxAngle MaxCoordinates
________________ _________________ ______________
136.297468795279 -108.833752912659 {2×2 double}
45.6946386351835 113.198590513648 {2×2 double}
69.3541635375988 -95.7927964950321 {2×2 double}
allAreas =
523 253 230
The average width = 11.45 pixels.
if I take (523+253+230)/136.29= 7.46 not 11.45

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 8 Mar 2023
That doesn't look like the right algorithm if you want to find crack widths. Did you see my post where I found the mean width of a blob (image of lightning)? Basically you want to
  1. Threshold/mask your image
  2. Get the Euclidean Distance Transform (EDT) of your mask
  3. Get the skeleton of your mask
  4. Multiply your EDT image by your skeleton image to get the radius of the blob at each point along it's skeleton;
  5. Double the radii to get the widths.
  6. Display the histogram to see the distribution, or take the mean.
See attached demo.
  49 Comments
Image Analyst
Image Analyst on 12 Jul 2023
For saving to disk, use PNG format. Of course once it's read back into an array in MATLAB, the format it had on disk doesn't matter, but you want to make sure you use a lossless format such as PNG or TIF to make sure you get back exactly the same data you saved out..
yasmin ismail
yasmin ismail on 13 Jul 2023
Edited: yasmin ismail on 13 Jul 2023
@Image Analyst so when I take photo by mobile , I have to save it in labtop as PNG, then start use it in matlab, and also the result output from process by matlb save it as png
is it correct?
The thing that I noticed when I send captured photo from my mobile to labtop automatically formated as jpg ,so its entered matlab as it jpg, so its already jpg. The only thing I can do if my model has several process for example start with filteration, the output could be saved as png then input it to next step for binarization.
Thus , what do you think?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!