Image processing for crack detection and length estimation

Technical Source
2 min readJan 17, 2024

--

Hi,

I have written the following matlab code to do the following:-

  • load rgb image of surface
  • contrast stretch
  • convert rgb to gray scale
  • image segmentation
  • morphological operations (thin, clean , fill, etc…)
  • imtool for pixel length determination
  • Calculation of crack length based on calibration of image and above determined pixel lenght.

My aim is to develop the SIMPLEST matlab code for automatic detection of cracks and estimate the length of the crack (if possible other geometrical properties) from a sample image.

The code is shown below:

%%load image
I=imread('two.jpg');
figure,imshow(I)
title('Original image')
%%Image adjust Istrech = imadjust(I,stretchlim(I));
figure,imshow(Istrech)
title('Contrast stretched image')
%%Convert RGB image to grayIgray_s = rgb2gray(Istrech);
figure,imshow(Igray_s,[])
title('RGB to gray (contrast stretched) ')
%%Image segmentation by thresholding
%use incremental value to run this selection till required threshold 'level' is
%achieved
level = 0.08;
Ithres = im2bw(Igray_h,level);
figure,imshow(Ithres)
title('Segmented cracks')
%%Image morphological operationBW = bwmorph(gradmag,'clean',10);
figure,imshow(BW)
title('Cleaned image')
BW = bwmorph(gradmag,'thin', inf);
figure,imshow(BW)
title('Thinned image')
BW = imfill(gradmag, 'holes')
figure,imshow(BW)
title('Filled image')
%%Image toolfigure,imtool(BW1)
figure,imtool(I)
%%Calaculate crack lengthcalibration_length=0.001;
calibration_pixels=1000;
crack_pixel=35;
crack_length=(crack_pixel *calibration_length)/calibration_pixels;

Please, I need help from image specialist to improve the code from above to meet my aim. I have also attached a sample picture that I am using for this code.

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

You’re just arbitrarily setting

crack_pixel=35;

You’re not even doing it manually (with user assistance) — you’re just setting some arbitrary number. What’s up with that? If you need code to find the distance between the farthest points in a binary blob, see my demo .

clc;    % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet