第 21 章 路面裂缝检测识别系统设计--matlab深度学习实战

第 21 章 路面裂缝检测识别系统设计--matlab深度学习实战_第1张图片
在汽车智能技术、汽车新能源技术、汽车电子这个群雄逐鹿的赛道。智能驾驶技术的要求也在不断的提升。
智能车辆教学平台、智能网联教学平台、汽车电子教学设备、在环仿真系统,目前主流的系统有很多,常用的基础部分和算法开发,智能驾驶模块,入门较好的还是matlab平台。
第 21 章 路面裂缝检测识别系统设计--matlab深度学习实战_第2张图片

回归本文,现阶段,路面裂缝识别与提取是路面裂缝检测领域中亟待解决的关键问题,存在着极大的挑战。一方面,由于路面情况复杂,纹理、噪声、阴影等干扰因素的存在,目前的路面裂缝识别任务中存在大量的误判和漏判现象;另一方面,当已知路面上存在裂缝时,如何排除干扰因素的影响,实现路面裂缝的自动、准确提取是路面裂缝检测中的另一个关键问题。
引文说明

% GUI_MAIN M-file for Gui_Main.fig
% GUI_MAIN, by itself, creates a new GUI_MAIN or raises the existing
% singleton*.
%
% H = GUI_MAIN returns the handle to a new GUI_MAIN or the handle to
% the existing singleton*.
%
% GUI_MAIN(‘CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in GUI_MAIN.M with the given input arguments.
%
% GUI_MAIN(‘Property’,‘Value’,…) creates a new GUI_MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Gui_Main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Gui_Main_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE’s Tools menu. Choose “GUI allows only one
% instance to run (singleton)”.
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Gui_Main

主程序文件:

function varargout = Gui_Main(varargin)


% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @Gui_Main_OpeningFcn, ...
    'gui_OutputFcn',  @Gui_Main_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Gui_Main is made visible.
function Gui_Main_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Gui_Main (see VARARGIN)

% Choose default command line output for Gui_Main
handles.output = hObject;
handles.Result = [];
handles.File = [];
% Update handles structure
guidata(hObject, handles);
clc; warning off all;
InitAxes(handles);

% UIWAIT makes Gui_Main wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Gui_Main_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbuttonOpenFile.
function pushbuttonOpenFile_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonOpenFile (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
    '*.*','All Files' },'载入图像',...
    fullfile(pwd, 'images'));
if isequal(filename, 0) || isequal(pathname, 0)
    return;
end
I = imread(fullfile(pathname, filename));
Result = Process_Main(I);
handles.File = fullfile(pathname, filename);
handles.Result = Result;
guidata(hObject, handles);
InitAxes(handles)
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');


% --- Executes on button press in pushbuttonHisteq.
function pushbuttonHisteq_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonHisteq (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
    axes(handles.axes2); imshow(handles.Result.hist); title('直方图均衡化图像');
end



% --- Executes on button press in pushbuttonMedfilt.
function pushbuttonMedfilt_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonMedfilt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
    axes(handles.axes2); imshow(handles.Result.Medfilt); title('中值滤波图像');
end


% --- Executes on button press in pushbuttonBw.
function pushbuttonBw_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonBw (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
    axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');
end

% --- Executes on button press in pushbuttonEnance.
function pushbuttonEnance_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonEnance (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
    axes(handles.axes2); imshow(handles.Result.Enance); title('增强图像');
end

% --- Executes on button press in pushbuttonBwfilter.
function pushbuttonBwfilter_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonBwfilter (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
    axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');
    axes(handles.axes3); imshow(handles.Result.BwFilter); title('二值图像滤波');
end

% --- Executes on button press in pushbuttonCrackRec.
function pushbuttonCrackRec_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonCrackRec (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
    axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');
    axes(handles.axes3); imshow(handles.Result.BwFilter); title('二值图像滤波');
    axes(handles.axes4); imshow(handles.Result.CrackRec); title('裂缝识别');
end


% --- Executes on button press in pushbuttonCrackJudge.
function pushbuttonCrackJudge_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonCrackJudge (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
    axes(handles.axes2); imshow(handles.Result.BwFilter); title('二值图像滤波');
    axes(handles.axes3); imshow(handles.Result.CrackRec); title('裂缝识别');
    axes(handles.axes4); imshow(handles.Result.CrackJudge); title('裂缝判断');
end

% --- Executes on button press in pushbuttonCrackLoc.
function pushbuttonCrackLoc_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonCrackLoc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
    axes(handles.axes2); imshow(handles.Result.CrackJudge); title('裂缝图像');
    axes(handles.axes3); imshow(handles.Result.CrackJudge); title(handles.Result.str);
    axes(handles.axes4); imshow(handles.Result.CrackJudge); title('裂缝标记图像');
    hold on;
    rectangle('Position', handles.Result.rect, 'EdgeColor', 'g', 'LineWidth', 2);
    hold off;
end

% --- Executes on button press in pushbuttonProject.
function pushbuttonProject_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonProject (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
    axes(handles.axes2); imshow(handles.Result.CrackJudge); title('裂缝图像');
    axes(handles.axes3); plot(1:size(handles.Result.Image, 1), handles.Result.Projectr);
    title('行投影');
    axes(handles.axes4); plot(1:size(handles.Result.Image, 2), handles.Result.Projectc);
    title('列投影');
end


% --- Executes on button press in pushbuttonClose.
function pushbuttonClose_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonClose (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
choice = questdlg('确定退出?', ...
    '退出', ...
    '是','否','否');
switch choice
    case '是'
        close;
    otherwise
        return;
end



% --- Executes on button press in pushbuttonSaveResult.
function pushbuttonSaveResult_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonSaveResult (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
    if ~isempty(handles.File)
        raw = [];
        xlsfile = fullfile(pwd, 'Result/result.xls');
        if exist(xlsfile, 'file')
            [num, txt, raw] = xlsread(xlsfile);
        end
        
        F = [];
        F{1, 1} = '文件名';
        F{1, 2} = '阈值信息';
        F{1, 3} = '面积信息';
        F{1, 4} = '长度信息';
        F{1, 5} = '最大宽度信息';
        F{1, 6} = '最小宽度信息';
        F{1, 7} = '形状信息';
        
        F{2, 1} = handles.File;
        F{2, 2} = handles.Result.BwTh;
        F{2, 3} = handles.Result.BwArea;
        F{2, 4} = handles.Result.BwLength;
        F{2, 5} = handles.Result.BwWidthMax;
        F{2, 6} = max(handles.Result.BwWidthMin,0.01);
        F{2, 7} = handles.Result.str;
        
        F = [raw; F];
        xlswrite(xlsfile, F);
        
        msgbox('保存结果成功!', '信息提示框');
    end
catch
    msgbox('保存结果失败,请检查程序!', '信息提示框');
end


% --- Executes on button press in pushbuttonBridge.
function pushbuttonBridge_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonBridge (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
    axes(handles.axes2); imshow(handles.Result.BwFilter); title('二值图像滤波');
    axes(handles.axes3); imshow(handles.Result.CrackJudge); title('裂缝判断');
    axes(handles.axes4); imshow(handles.Result.CrackBridge); title('裂缝拼接');
end


% --- Executes on button press in pushbuttonSaveImage.
function pushbuttonSaveImage_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonSaveImage (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename, pathname] = uiputfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
    '*.*','All Files' },'Save Image',...
    fullfile(pwd, 'Result/result.png'));
if ~isequal(filename, 0)
    imwrite(handles.Result.BwEnd, fullfile(pathname, filename));
    msgbox('保存图像成功!', '信息提示框');
end


% --- Executes on button press in pushbuttonDiplay.
function pushbuttonDiplay_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonDiplay (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if ~isempty(handles.File)
    F = [];
    F{1} = sprintf('文件名:%s', handles.File);
    F{2} = sprintf('阈值信息%.2f', handles.Result.BwTh);
    F{3} = sprintf('面积信息%.2f', handles.Result.BwArea);
    F{4} = sprintf('长度信息%.2f', handles.Result.BwLength);
    F{5} = sprintf('最大宽度信息%.2f', handles.Result.BwWidthMax);
    F{6} = sprintf('最小宽度信息%.2f', max(handles.Result.BwWidthMin,0.01));
    F{7} = sprintf('形状信息%s', handles.Result.str);
    listdlg('PromptString', '参数显示:',...
        'Name', '参数信息', ...
        'ListSize', [300, 150], ...
        'SelectionMode','single',...
        'ListString', F);
end

初步处理效果图
第 21 章 路面裂缝检测识别系统设计--matlab深度学习实战_第3张图片
第 21 章 路面裂缝检测识别系统设计--matlab深度学习实战_第4张图片
函数目录
第 21 章 路面裂缝检测识别系统设计--matlab深度学习实战_第5张图片
部分函数说明
直方图处理和均衡化
hist_con.m

function s_out = hist_con(s_in, flag)
if nargin < 2
    flag = 0;
end
if ndims(s_in) == 3
    I = rgb2gray(s_in);
else
    I = s_in;
end
s_out = histeq(I);
if flag
    figure;
    subplot(2, 2, 1); imshow(I); title('原图');
    subplot(2, 2, 2); imhist(I); title('原图直方图');
    subplot(2, 2, 3); imshow(s_out); title('均衡化结果');
    subplot(2, 2, 4); imhist(s_out); title('均衡化结果直方图');
end

目标特征识别函数
Identify_Object.m

function bwn = Identify_Object(bw, MinArea, MinRate)
if nargin < 3    
    MinRate = 3; 
end
if nargin < 2
    MinArea = 20;
end
[L, num] = bwlabel(bw); 
stats = regionprops(L, 'Area', 'MajorAxisLength', ...
    'MinorAxisLength'); 
Ap = cat(1, stats.Area);
Lp1 = cat(1, stats.MajorAxisLength);
Lp2 = cat(1, stats.MinorAxisLength); 
Lp = Lp1./Lp2; 
for i = 1 : num
    if Ap(i) < MinArea
        bw(L == i) = 0;
    end
end
MinRate = max(Lp)*0.4;
for i = 1 : num
    if Lp(i) < MinRate
        bw(L == i) = 0;
    end
end
bwn = bw;

结果显示
第 21 章 路面裂缝检测识别系统设计--matlab深度学习实战_第6张图片
本文配套文件源码下载地址–>传送门
https://download.csdn.net/download/dongbao520/85705992?spm=1001.2014.3001.5503

你可能感兴趣的:(matlab智能驾驶,深度学习,matlab,深度学习,开发语言)