How to write a MATLAB code for road crack detection and length estimation using image processing? I am currently doing related research in cracks detection on road surfaces. This is my first time.
UPDATE(5/20/2019): That took longer than expected. I've finished porting over to PyTorch in the pytorch
branch. I still have to obtain some decent results. Would require some hyperparameter tuning. Feel free to train your own models, shouldn't take longer than a couple of hours on CPU.
UPDATE(3/23/2019): Currently porting this to PyTorch as I'm out of touch with TensorFlow. Should be done in a week.
This repository contains the code for crack detection in concrete surfaces. It is a TensorFlow implementation of the paper by by Young-Jin Cha and Wooram Choi - 'Deep Learning-Based Crack Damage Detection Using Convolutional Neural Networks'.
The model acheived 85% accuracy on the validation set. A few results are shown below -
MATLAB was used to prepare the data. Regions of Interest were sliced into smaller 128 x 128 pixel images and used for training -
Dependencies required-
- TensorFlow
- OpenCV
- Dataset -The data set can be downloaded from this link
The dataset.py file creates the training dataset class to be fed into the Convolutional Neural Network. This class automatically determines the number of classes by the number of folders in 'in_dir' (number of folders=number of classes)
NOTE: This script utilizes an already saved cache file. The cache file contains the filenames of the data. If the cache file doesn't exist, a new one created. If the data has been altered with, please delete the old cache file and run the script again. This applies for both Running.py
and Train_CD.py
. This was my first ever Deep Learning project hence, the naive approach. I'll streamline this once I get some time, or gladly accept a pull request!
The directory structure is assumed to be the following- (For example considering 3 classes)
- in_dir/class1/ - Contains all the training images for class 1
- test/ - Contains all the validation images for class 1
- in_dir/class2/ - Contains all the training images for class 2
- test/ - Contains all the validation images for class 2
- in_dir/class3/ - Contains all the training images for class 3
- test/ - Contains all the validation images for class 3
To train the network run the command with the following arguments:
python Train_CD.py
Argument | Details | Default |
---|
--in_dir | path to in_dir folder | cracky |
--iter | number of iterations to run the model for | 1500 |
--save_folder | Directory to save checkpoint | CURRENT_DIR |
After model has been trained, meta_files are saved into 'save_folder'. To test the model, run the command with the following arguments:python Running.py
Argument | Details | Default |
---|
--in_dir | directory containing unlabeled test data | cracky_test |
--meta_file | MetaFile path | None (Will throw error if not given) |
--CP_dir | dir contatining checkpoint | None (Will throw error if not given) |
--save_dir | dir to save output images | CURRENT_DIR |
TODO:
- Streamline data loading; remove cache file system
- Combine training and testing scripts into one
댓글 수: 12
9 Apr 2015
Thanks for your blob demo, helped alot! In line with your example I have started to tweak my code as below and would like to ask the following questions before.
i) Is thebwlabel function labelling ALL 4-5 cracks in the image under one label? if yes how do I make sure it labels each crack separately?
ii) the area returned from regionprop function is it for ALL 4-5 cracks in image? if yes how do get the area for each crack separately?
iii) thebwboundaries function returns 34 boundaries how do plot these boundaries such that the edges of each crack is highlighted.
iv) finally based on all these can you clarify me on how to determine the length of each crack (4-5 as shown in the sample image)? It was not clear from your example.
I=imread('two.jpg');
figure,imshow(Igray)
%% Binarize
binaryImage = im2bw(Igray, level);
title('Binarized image')
labeledImage = bwlabel(binaryImage);
%% Boundaries
numberOfBoundaries = size(boundaries, 1);
9 Apr 2015
No, they're all separate. measurements is an array of structures. Each structure represents one blob. The fields of the structure are whatever you measure, like area, perimeter, etc.
10 Apr 2015
Okay, thanks. I see the problem in my code. When I convert the image 'two.jpg' image to binary the cracks in are shown in black as background, while the surface of the steel is taken as foreground white. Thus the label and regionprop function returns only 'one' label and field respectively. How can I fix this pls?
I think with this fixed I can apply bwboundaries function to find which two boundaries are the farthest for each label (each crack) right?
Matlab License Crack
10 Apr 2015
YES! I have managed to label and plot out each crack and also get its boundaries and area. see code below:
figure,imshow(I)
level = 0.599;
figure,imshow(binaryImage)
binaryImage2=zeros(row,col);
for j=1:col
binaryImage2(i,j)=1;
binaryImage2(i,j)=0;
end
figure,imshow(binaryImage2)
figure,imshow(binaryImage2)
figure,imshow(binaryImage2)
binaryImage2 = bwareaopen(binaryImage2, round(0.001*numel(binaryImage2)));
number_of_labeles = max(max(labeledImage))
for i= 1:number_of_labeles
figure, imshow(Im)
numberOfBoundaries = size(boundaries, 1);
I would like to know if I can apply farthest boundaries points demo on each label to determine the length of each crack???? Thanks alot!
10 Apr 2015
This code is not very efficient and you could cut out a few steps (inverse and clean). However when I tried to run it on the image your originally attached, two.jpg, it didn't seem to work at all. Please attach 'GCC4.jpg' so I can improve your code.
11 Apr 2015
Right, In Binarize section the value of level is not same for 'two.jpg'.
binaryImage = im2bw(Igray,level);
GCC4.jpg is attached
Thanks!
13 Apr 2015
Well that looks completely different and would require a different algorithm. Your first image could probably be segmented fairly well with a global threshold. Maybe try adapthisteq() on this to even out the slow undulations and give a flatter image which you can then use a global threshold on.
14 Apr 2015
Like you said the first image is straight forward with global threshold.
However the second is not well segmented even with the adapthisteq() function.
Is there a Variable or optimum global thresholding function? and can I use it here?
Else I will stick to selecting graythresh level by trial and error for now (if no simple way out), with that, what are the improvements you offered the code?
14 Apr 2015
See my interactive thresholding app:http://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image
If it doesn't work well after adapthisteq(), then you're going to have to develop a much more sophisticated algorithm. It looks like if you improved this lighting, camera, and focus that you could get a much better image to start with.
8 Nov 2018
I went through your code and couldn't understand the distance measurement. if possible, could you let me know the algorithm.
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.
7 Feb 2019
Crack Detection Image Processing Matlab Code
I have tried your code 'farthest_points.m' . how can I choose another image other than you have set?
Matlab Crack Torrent
로그인 to comment.