Matlab code for wall crack detection

90 visualizaciones (últimos 30 días)
mohammed sharique
mohammed sharique el 14 de Mzo. de 2017
Comentada: Image Analyst el 11 de Jun. de 2021
can anyone please tell me the code for line detection technique of a wall crack and how to analyse the crack after a certain width. thank you

Respuestas (3)

Image Analyst
Image Analyst el 14 de Mzo. de 2017
Try thresholding. Or else look for asphalt or concrete. It's been asked before. Or else try http://www.visionbib.com/bibliography/contents.html

shivani verma
shivani verma el 17 de Oct. de 2019
i am also working on this poject soon i am going to share the process and progress of this project
  3 comentarios
roni oz
roni oz el 11 de Jun. de 2021
Hi
I'm doing work on this subject.
I would be happy if you could share the process for me too.
Thanks,
Roni

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 15 de Nov. de 2020
One way to do it is to threshold the cracks to find a binary image. Then call regionprops to get the area and perimeter. Assuming that the cracks are long and skinny, you can estimate that area = length*width, and perimeter = 2*(length+width). From that you get width = area/(length) = area / (2*(length+width)). So now solve the quadratic equation for width.
Another way is to skeletonize the binary image, then take it's skeleton with bwskel(). Then compute the Euclidean distance with bwdist() and multiply. The values in the image will be the radii along the spine of the crack. Double it to get the mean width (diameter). You can then get a histogram of widths, or simply take the mean of non-zero values to get the overall mean width.
% Program to compute the mean width of a blob in an image. By Image Analyst.
clearvars;
close all;
clc;
fontSize = 15;
% Read in original image, with white lightning on black background.
baseFileName = 'mean_width_of_blob.png';
fullFileName = fullfile(pwd, baseFileName);
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(rgbImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = grayImage(:, :, 2); % Take green channel.
else
grayImage = grayImage; % It's already gray scale.
end
% Now it's gray scale with range of 0 to 255.
subplot(2, 3, 1);
imshow(grayImage, [])
impixelinfo; % Let user mouse around and see values in the status line at the lower right.
title('Original Image', 'FontSize', fontSize);
% Binarize the image.
mask = imbinarize(grayImage);
% Fill holes.
mask = imfill(mask, 'holes');
% Take largest blob only.
mask = bwareafilt(mask, 1);
subplot(2, 3, 2);
imshow(mask)
impixelinfo; % Let user mouse around and see values in the status line at the lower right.
title('Mask', 'FontSize', fontSize)
% Compute the skeleton
skelImage = bwskel(mask);
subplot(2, 3, 3);
imshow(skelImage)
impixelinfo; % Let user mouse around and see values in the status line at the lower right.
title('Thinned', 'FontSize', fontSize)
% Enlarge figure to full screen.
g = gcf;
g.WindowState = 'maximized';
% Compute the Euclidean distance image.
edtImage = bwdist(~mask);
subplot(2, 3, 4);
imshow(edtImage, [])
title('Distance Transform Image', 'FontSize', fontSize);
impixelinfo; % Let user mouse around and see values in the status line at the lower right.
% Multiply them to get an image where the only pixels in the image
% are along the skeleton and their value is the radius.
% Multiply radius image by 2 to get diameter image.
diameterImage = 2 * edtImage .* single(skelImage);
subplot(2, 3, 5);
imshow(diameterImage, [])
title('Diameter Image', 'FontSize', fontSize);
impixelinfo; % Let user mouse around and see values in the status line at the lower right.
% Get the widths. These will be where the image is not zero.
widths = diameterImage(diameterImage > 0);
% Show histogram of widths.
subplot(2, 3, 6);
histogram(widths);
grid on;
xlabel('Width in Pixels', 'FontSize', fontSize);
ylabel('Count', 'FontSize', fontSize);
% Compute the mean width
meanWidth = mean(widths)
% Put a line on the histogram at the mean width
xline(meanWidth, 'LineWidth', 2, 'Color', 'r');
caption = sprintf('Histogram of Widths. Mean Width = %.1f Pixels', meanWidth);
title(caption, 'FontSize', fontSize);
message = sprintf('Mean Width = %.1f Pixels', meanWidth);
msgbox(message);

Community Treasure Hunt

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

Start Hunting!

Translated by