Script for indicating whether there is a crack in my image and how big the crack is problems.

2 views (last 30 days)
I am creating a script that will detect a crack within an image tell me if there is a crack and if so how big it is and where it can be located but am struggling with a few parts of it, first of all I make it clear where the crack is by changing the image to red green blue layers and overlapping them showing a black and white image this does the job but my script doesnt say If there is a crack or not so I used an if else function to do this but seems to not be working either.
I then look at the different stats of the image using regionprops but here is where one of the first problem arises, how do I asses the stats its giving me the script I have gotten so far has gotten me nothing.
The last problem I have is I must find a way to convert pixel values to actual size I am using tihs code so far but where the distanceInPixels is I was thinking I could use one of the region props stats but which and how do i implemnt it into this?
%% Size converter from pixels to centimeters
calibrationFactor =30/509 ;
distantceInCm =distanceInPixels * calibrationFactor;
areaInSquareCm = areaInPixels * calibrationFactor;
%% Import image
a= imread('hairline crack green.PNG');
%% seperating layers of the image
red=a(:,:,1);
green=a(:,:,2);
blue=a(:,:,3);
levelr= 0.2;
levelg=0.2;
levelb=0.3;
I1 =im2bw(red, levelr)
I2 =im2bw(green,levelg);
I3 =im2bw(blue,levelb);
% imshow(I1)
total=(I1&I2&I3);
imshow(total);
%%
ImageStats= regionprops(total, 'MajorAxisLength');
imgLengths = [imageStats.MajorAxisLength];
idx = imgLength > 15;
imageStatsFinal = imagestats(idx);
disp(imageStatsFinal)
%% Saying if there is a hairline crack
if isempty (imageStatsFinal)
disp('The object does not have a hairline crack')
else
disp('The object contains a hairline crack')
end
  7 Comments
Thomas van Nedervelde
Thomas van Nedervelde on 3 Dec 2018
Thank you I wasnt to sure on what masking was but now understand it, how would I make my script analyse the mask though? would I go back to assesing the RGB values or would you suggest using the colour treshholding app? and generating a script for that or can that not be automise?
In your many years within this industry have you seen many scripts like this that excute something similar? If so do you know about any other threads that might be helpfull?
Kind regards
Thomas van Nedervelde
Thomas van Nedervelde on 4 Dec 2018
Hi image analyst I have been playing around with the masking script you attached and I was wondering why when I use my own image it only creates a binary mask of the region and it doesnt create any of the other masks?
folder = fileparts(which('p.jpg')); % Determine where demo folder is.
baseFileName = 'p.jpg';
surely these are the only two lines I have to change since the file is not called upon anywhere else?

Sign in to comment.

Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!