MATLAB Answers

Image processing for crack detection and length estimation

336 views (last 30 days)
BB BSB
BB BSB on 9 Apr 2015
Commented: Image Analyst on 12 Feb 2020
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 gray
Igray_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 operation
BW = 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 tool
figure,imtool(BW1)
figure,imtool(I)
%%Calaculate crack length
calibration_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.
Picture two.jpg is attached below:
Thanks

  3 Comments

BB BSB
BB BSB on 9 Apr 2015
At he moment my supervisor thinks the above code is a manual method of determining crack length and requires it is 'automated' (by labeling and extracting length of labelled cracks??? is that possible?)
Cheers!
Hari krishna
Hari krishna on 3 Nov 2019
Could someone please help me to measure the crack and sketch a line on a diagram .

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 9 Apr 2015
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 attached demo.

  13 Comments

Image Analyst
Image Analyst on 8 Nov 2018
I have no idea what algorithm or program you're talking about. There has been lots of code segments posted here. Please be specific.
Neptune16
Neptune16 on 7 Feb 2019
to Image Analyst:
I have tried your code "farthest_points.m" . how can I choose another image other than you have set?
Arulmozhi priya
Arulmozhi priya on 12 Nov 2019
sir can you help with my project i want to measure crack length,width

Sign in to comment.

More Answers (3)

Dan
Dan on 13 Apr 2015
I just glanced at your code and if you need a completely automated system, you need to either define what constitutes a crack beforehand OR have the system learn these rules using something like a neural net.
But... that's a bigger project. In the short term, you might want to play with the graythresh function that will automate your selection of a threshold.
Just my $0.02.
Dan

  1 Comment

BB BSB
BB BSB on 14 Apr 2015
I see, for timeline limits Id rather attempt the easier of the 3 methods you outlined which I guess is playing around with graythresh function.
Any hints as to how or what to look out for in doing so? Because my first approach would be to scale by a factor??? make any sense? Thanks.

Sign in to comment.


Yashwanth G M
Yashwanth G M on 25 Mar 2019
Sir help me to find out the area of a solar panel interms of Sq.mm....

  1 Comment

Image Analyst
Image Analyst on 25 Mar 2019
Then post a new Question, not an Answer to BB's question.

Sign in to comment.


Ram kumar R
Ram kumar R on 12 Feb 2020
i got error in line no.21 as Ithres = im2bw(Igray_h,level) can u explain it ?

  1 Comment

Image Analyst
Image Analyst on 12 Feb 2020
You forgot to tell us the error! What is there to explain?
You probably have a color image. Start your own question since this is not an Answer to the original question. Attach your code, your image, and the error message.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!