【图像识别】基于matlab GUI界面之路面裂缝识别【Matlab 114期】

一、简介

高速公路路面病害养护和管理的重要部分就是路面裂缝的检测。近年来,路面裂缝自动检测技术已得到了广泛应用,而由于路面裂缝图像的复杂性,检测算法直接影响着检测结果的精确度。因此,本文将重点放在路面裂缝病害的检测上,为了提高检测的精度,分别从裂缝图像的去噪、图像的增强、图像的分割以及检测后路面裂缝图像的特征提取方面进行深入研究。  在路面裂缝图像中,由于裂缝信息与背景对比度偏低,难以将裂缝直接检测到。对于图像的预处理,首先对图像进行灰度校正,再对校正之后的图像滤波,本文提出了一种改进的中值滤波方法,对图像进行去噪,之后用基于模糊理论的图像增强原理对图像做进一步增强,有效提高了路面裂缝图像的对比度。  针对路面裂缝图像分割,本文分别用了阈值分割和基于形态学多尺度的思想,对于形状规则的裂缝采用的是阈值分割,对于裂缝形状不规则的图像,本文设计了一种多结构元素的抗噪型边缘检测算子,且依据不同形状的结构元素对裂缝边缘填充的几率不同,确定了自适应权重,使得算子检测到了各种类型的裂缝边缘,有效地提高了检测的精度。  对于经过分割后的路面裂缝图像中存在噪声和裂缝断裂的问题,本文对于断裂较窄的图像用形态学中的闭运算和开运算去处理,对于断裂较宽的图像,提出了一种基于生长的断裂裂缝块的连接方法。提高了连接的效率和准确率,使整个检测结果清晰完整。最终,从识别结果图中提取裂缝信息。根据得到的识别结果图,设定一系列判定条件,提取出裂缝的连通域,对裂缝的类型进行判断,最后计算出网状裂缝的面积及线性裂缝的长宽信息。

二、源代码

function varargout = Gui_Main(varargin)
% 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
 
% Last Modified by GUIDE v2.5 29-Mar-2011 22:28:58
 
% 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;*.bmp','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

三、运行结果

在这里插入图片描述

四、备注

完整代码或者代写添加QQ912100926
往期回顾>>>>>>
【图像压缩】图像处理教程系列之图像压缩【Matlab 074期】
【图像分割】图像处理教程系列之图像分割(一)【Matlab 075期】
【图像分割】图像处理教程系列之图像分割(二)【Matlab 076期】
【模式识别】银行卡号之识别【Matlab 077期】
【模式识别】指纹识别【Matlab 078期】
【图像处理】基于GUI界面之DWT+DCT+PBFO改进图像水印隐藏提取【Matlab 079期】
【图像融合】CBF算法之图像融合【Matlab 080期】
【图像去噪】自适应形态学之图像去噪【Matlab 081期】
【图像增强】DEHAZENET和HWD之水下去散射图像增强【Matlab 082期】
【图像增强】PSO寻优ACE之图像增强【Matlab 083期】
【图像重建】ASTRA算法之图像重建【Matlab 084期】
【图像分割】四叉树之图像分割【Matlab 085期】
【图像分割】心脏中心线之提取【Matlab 086期】
【图像识别】SVM植物叶子之疾病检测和分类【Matlab 087期】
【图像识别】基于GUI界面之模板匹配手写数字识别系统【Matlab 088期】
【图像识别】基于GUI界面之不变矩的数字验证码识别【Matlab 089期】
【图像识别】条形码识别系统【Matlab 090期】
【图像识别】基于GUI界面RGB和BP神经网络之人民币识别系统【Matlab 091期】
【图像识别】CNN卷积神经网络之验证码识别【Matlab 092期】
【图像分类】极限学习分类器之对遥感图像分类【Matlab 093期】
【图像变换】DIBR-3D之图像变换【Matalb 094期】
【图像分割】模糊聚类算法之FCM图像分割【Matlab 095期】
【模式识别】银行监控系统之人脸识别【Matlab 096期】
【模式识别】基于GUI界面之疲劳检测系统【Matlab 097期】
【图像识别】国外车牌识别【Matlab 098期】
【图像分割】最大类间方差法(otsu)之图像分割【Matlab 099期】
【图像分割】直觉模糊C均值聚类之图像分割IFCM【Matlab 100期】
【图像分割】基于matlab形态学重建和过滤改进FCM算法(FRFCM)之图像分割【Matlab 101期】
【图像增强】局部对比度增强CLAHE算法之直方图增强【Matlab 102期】
【图像融合】Frequency Partition之图像融合【Matlab 103期】
【图像评价】SVM之图像无参考质量评价【Matlab 104期】
【图像边缘检测】最小二乘法用于椭圆边缘检测【Matlab 105期】
【图像加密】基于GUI界面之混沌系统图像加密解密【Matlab 106期】
【图像配准】SIFT算法之图像配准【Matlab 107期】
【图像分割】随机游走算法用于图像分割【Matlab 108期】
【图像分割】形态学重建和过滤改进FCM算法(FRFCM)用于图像分割【Matlab 109期】
【图像分割】图像分割IFCM之直觉模糊C均值聚类【Matlab 110期】
【图像增强】区域相似变换函数与蜻蜓算法之灰度图像增强【Matlab 111期】
【图像直线拟合】最小二乘法之图像直线拟合【Matlab 112期】
【图像去雾】暗通道之图像去雾【Matlab 113期】

你可能感兴趣的:(matlab,图像处理)