Script for indicating whether there is a crack in my image and how big the crack is problems.
2 views (last 30 days)
Show older comments
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
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!