找回密码
 注册
关于网站域名变更的通知
查看: 756|回复: 1
打印 上一主题 下一主题

基于matlab GUI路面裂缝识别

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2021-4-14 08:49 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
2 `4 T9 h9 g7 ]9 k
一、简介
7 g9 p, {3 K) ]$ z  K7 K高速公路路面病害养护和管理的重要部分就是路面裂缝的检测。近年来,路面裂缝自动检测技术已得到了广泛应用,而由于路面裂缝图像的复杂性,检测算法直接影响着检测结果的精确度。因此,本文将重点放在路面裂缝病害的检测上,为了提高检测的精度,分别从裂缝图像的去噪、图像的增强、图像的分割以及检测后路面裂缝图像的特征提取方面进行深入研究。  在路面裂缝图像中,由于裂缝信息与背景对比度偏低,难以将裂缝直接检测到。对于图像的预处理,首先对图像进行灰度校正,再对校正之后的图像滤波,本文提出了一种改进的中值滤波方法,对图像进行去噪,之后用基于模糊理论的图像增强原理对图像做进一步增强,有效提高了路面裂缝图像的对比度。  针对路面裂缝图像分割,本文分别用了阈值分割和基于形态学多尺度的思想,对于形状规则的裂缝采用的是阈值分割,对于裂缝形状不规则的图像,本文设计了一种多结构元素的抗噪型边缘检测算子,且依据不同形状的结构元素对裂缝边缘填充的几率不同,确定了自适应权重,使得算子检测到了各种类型的裂缝边缘,有效地提高了检测的精度。  对于经过分割后的路面裂缝图像中存在噪声和裂缝断裂的问题,本文对于断裂较窄的图像用形态学中的闭运算和开运算去处理,对于断裂较宽的图像,提出了一种基于生长的断裂裂缝块的连接方法。提高了连接的效率和准确率,使整个检测结果清晰完整。最终,从识别结果图中提取裂缝信息。根据得到的识别结果图,设定一系列判定条件,提取出裂缝的连通域,对裂缝的类型进行判断,最后计算出网状裂缝的面积及线性裂缝的长宽信息。; m2 \8 P; k8 u& A: ^9 K; T
5 m& R: B+ a) x9 J2 S: Q1 k* Z) C
二、源代码
6 h3 G' m2 m* G. ~& Cfunction varargout = Gui_Main(varargin)
8 z  v8 r* A0 U# Z$ s% GUI_MAIN M-file for Gui_Main.fig
! H0 b2 z% `& L0 a2 x: p%      GUI_MAIN, by itself, creates a new GUI_MAIN or raises the existing
/ _' @( `( x3 H  n- _2 e* I/ H%      singleton*.! K& `2 x' j% u4 f& E4 `# V6 ~
%
( w, O4 [) z  ~. U* O; O9 H' H%      H = GUI_MAIN returns the handle to a new GUI_MAIN or the handle to
# _7 Q* d$ ?) l, E6 I%      the existing singleton*.
) S" |2 G# I0 J$ D9 V# {  X%) M7 t  X/ b% F/ i* s
%      GUI_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local7 ]  N. y: C# W* {( ^2 P
%      function named CALLBACK in GUI_MAIN.M with the given input arguments.
9 v, ?* p% O; d- [0 p$ I%' A, f, }- T2 ]: I0 m! D
%      GUI_MAIN('Property','Value',...) creates a new GUI_MAIN or raises the
: p" `! ?+ B0 s- h% h%      existing singleton*.  Starting from the left, property value pairs are  G  n5 M$ r4 j& ]8 {7 d: E! o- q  y
%      applied to the GUI before Gui_Main_OpeningFcn gets called.  An
' C; \6 q4 v% x4 x%      unrecognized property name or invalid value makes property application1 `7 m# x9 x" w) c
%      stop.  All inputs are passed to Gui_Main_OpeningFcn via varargin.
2 I# I+ A$ Q5 l2 J& L% M) n%: H7 d, M$ D9 v2 v
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
" S, ~5 i2 l  B/ \%      instance to run (singleton)".+ u* k5 M  S9 N/ n6 R1 N( ^* z* o
%% V: p) u9 q+ V/ _) ^5 J4 _
% See also: GUIDE, GUIDATA, GUIHANDLES9 |" L/ W4 r6 l$ R: Z/ G* D

% ^* R. r6 l( r! [: E  K% Edit the above text to modify the response to help Gui_Main2 J. j* o3 A5 _- ~3 y, L
0 C6 n! F, x# b; [0 Z; q% }% C8 k
% Last Modified by GUIDE v2.5 29-Mar-2011 22:28:585 p& {1 `5 r* Q; {9 P

6 h% ^( z! @. \1 s; o% Begin initialization code - DO NOT EDIT
" x' L& `+ c! Dgui_Singleton = 1;
. \! J* T' e. m" rgui_State = struct('gui_Name',       mfilename, ...  u0 w9 X/ e+ r$ z1 t, D1 ^
    'gui_Singleton',  gui_Singleton, ...; D0 \$ u- C7 M* w7 S
    'gui_OpeningFcn', @Gui_Main_OpeningFcn, ...6 R- i, {# C# Y3 q) v0 l
    'gui_OutputFcn',  @Gui_Main_OutputFcn, ...
3 d& f" L6 @- Y; T, ]2 T) P    'gui_LayoutFcn',  [] , ...
( ~* f8 f1 z- Z( G- i    'gui_Callback',   []);  Y% j, V+ `2 K& M
if nargin && ischar(varargin{1})
0 e5 U! W7 y& z    gui_State.gui_Callback = str2func(varargin{1});
0 g( H: S7 g( \/ Nend
/ c4 P4 H# y1 v' a  X) z
* u1 J2 s1 Q7 rif nargout4 r/ u0 _; ], W- K7 W% N
    [varargout{1:nargout}] = gui_maiNFCn(gui_State, varargin{:});
) f1 w" u6 g2 R" ^7 M' W/ M' F5 Celse
5 k3 P5 R4 J; v" `    gui_mainfcn(gui_State, varargin{:});
4 n+ j9 D  p8 Y1 z$ |, {: j" ^- w6 o; S8 eend
/ B& g3 I, p5 M& E" H$ U' u% End initialization code - DO NOT EDIT
- y# H, n6 r& C9 A ( B  b; U; L, D: i' t" y

  Y: m4 ?6 H1 T! S! P% --- Executes just before Gui_Main is made visible., v1 h8 F. c8 {" Z
function Gui_Main_OpeningFcn(hObject, eventdata, handles, varargin)1 Y6 A0 q& e( V- t) H
% This function has no output args, see OutputFcn.
8 t3 j% V% @: B( A$ M5 A% hObject    handle to figure
7 V) y. G; z3 o+ u9 x+ [" m0 X2 M% eventdata  reserved - to be defined in a future version of MATLAB
4 C0 n( K7 v3 [! {$ ?4 G- Z8 l% handles    structure with handles and user data (see GUIDATA)! ^+ K! r% u. X1 K9 t. c
% varargin   command line arguments to Gui_Main (see VARARGIN)
9 o7 ~: |3 n. ~; @5 L; n3 [/ k
- r! A0 H9 r6 F- D% Choose default command line output for Gui_Main
0 _& i/ |# s+ k% y0 R0 Ohandles.output = hObject;
& S# ^8 o* y3 Y7 C& yhandles.Result = [];1 q  X* v1 E3 K: w' w3 w: u
handles.File = [];! I* c5 k1 @: g' }
% Update handles structure
1 o1 f) R) g/ U& ], P( `guidata(hObject, handles);& o- X: W- f- j: {+ A# h" B' M, W- `
clc; warning off all;5 }: f# t" s2 J& M- i
InitAxes(handles);6 B! u4 M+ B$ K2 H6 |2 E; E

7 ?! T0 M0 v) Y% UIWAIT makes Gui_Main wait for user response (see UIRESUME)
- U! N* n# E' P2 g% uiwait(handles.figure1);) q! M, a: e' m) y: Q

( j  I7 {0 Y; q+ @& }8 A: P
1 h+ }1 h3 T) f6 s% --- Outputs from this function are returned to the command line.. J6 `8 r& U/ o; @9 J1 r
function varargout = Gui_Main_OutputFcn(hObject, eventdata, handles)# k. L+ ~* \* A9 f* E
% varargout  cell array for returning output args (see VARARGOUT);
5 ~7 t3 b0 D$ U4 ]- E. T/ ~9 p- _% hObject    handle to figure- t4 X) `9 |, h
% eventdata  reserved - to be defined in a future version of MATLAB
* O6 }5 G$ c: r% u$ v1 |: v8 c, i7 [$ N% handles    structure with handles and user data (see GUIDATA)
2 c* O' [4 u* B9 X* V- }0 ^
; C6 y9 {8 {5 I9 m- p: v( Q$ R% Get default command line output from handles structure
' r2 ~3 L0 T. Mvarargout{1} = handles.output;
2 H, _/ A+ N! c; X$ x7 x# ~ & g+ I7 l* X! a8 Y/ u

) H* a! L) R) S( U( ]* S& W% --- Executes on button press in pushbuttonOpenFile." C) L1 D( e' ~$ ]' ~4 y( a
function pushbuttonOpenFile_Callback(hObject, eventdata, handles)) D; T$ a; L# C) p' [! a5 ?
% hObject    handle to pushbuttonOpenFile (see GCBO)
% w) A. S, a4 f( @% eventdata  reserved - to be defined in a future version of MATLAB
8 \2 A+ D) v4 J4 k% handles    structure with handles and user data (see GUIDATA)
# c4 i' `2 S5 `( g: t* E) F[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
* B/ K  j/ ~* Q8 C1 c: m' ^6 H$ B    '*.*','All Files' },'载入图像',...
3 ]0 ?1 a( T( N- a    fullfile(pwd, 'images'));/ i; q. @. q' i2 j0 B
if isequal(filename, 0) || isequal(pathname, 0)
6 M* M! R8 n- s6 ~) {    return;$ N8 c: l/ I( u% K2 W
end, A) M+ u0 C( \3 `0 F7 F* ?
I = imread(fullfile(pathname, filename));6 o# n) n% b4 P1 d  [1 W7 ?5 h4 _
Result = Process_Main(I);
& z( ?1 f; g) {. H  H5 I0 p" a  L, Ahandles.File = fullfile(pathname, filename);9 d5 o3 r) h& m# t! `  D! v; ?7 g
handles.Result = Result;
: E9 Z. i/ k& uguidata(hObject, handles);* P  ?3 z8 B3 c
InitAxes(handles)7 K. E7 O* Z; v4 }/ K) |
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');% d4 x5 L5 x! r+ \7 y% |3 Y  m( p
' I8 i. P# A# H* r8 Y
" M- ?+ _1 F7 H9 ?# h; L4 j" L
% --- Executes on button press in pushbuttonHisteq.
" M3 M- U2 v; }( R, m% wfunction pushbuttonHisteq_Callback(hObject, eventdata, handles)
& l3 f  N2 {  B1 D' e" M% hObject    handle to pushbuttonHisteq (see GCBO)
/ p% C; I- l* N+ R% l% eventdata  reserved - to be defined in a future version of MATLAB
0 A3 l. u/ P+ m/ c% handles    structure with handles and user data (see GUIDATA)
" \) l/ |3 U: W) A2 m2 nif ~isempty(handles.Result)
8 J) a/ A) g! j) ]4 n4 X    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');9 b+ C" ^0 F& Q/ E; j0 w* M
    axes(handles.axes2); imshow(handles.Result.hist); title('直方图均衡化图像');7 Q; k# t$ v, @0 J+ x! |
end
! W( Y- m! a$ ~( M" {- i! k6 a 8 {, f# Y( R7 h3 E  d! S1 L
  W3 h! j3 L6 y& \$ i

6 ?" F8 u% f9 H. [0 |% --- Executes on button press in pushbuttonMedfilt.
& K5 i. S6 g' g3 b- A( Hfunction pushbuttonMedfilt_Callback(hObject, eventdata, handles)& c! Q2 s# J0 ]4 r  J3 H0 L+ m, \
% hObject    handle to pushbuttonMedfilt (see GCBO)6 e6 n" p3 v' k
% eventdata  reserved - to be defined in a future version of MATLAB* `% ^( |2 x# H2 n% D/ `/ ^) k
% handles    structure with handles and user data (see GUIDATA)! q( U3 C$ G; o$ F% \/ @: @
if ~isempty(handles.Result)' m) P- l4 u0 L, Y0 P# W
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');! V3 @% C- ^$ E' f0 S
    axes(handles.axes2); imshow(handles.Result.Medfilt); title('中值滤波图像');- }; \7 {  i" w# ]
end
( W, k) |6 K. C " n: }" O( u( Q
: i' ]/ o$ Y7 z/ A  y- P1 X
% --- Executes on button press in pushbuttonBw.. o- P6 `$ v2 k* l+ R
function pushbuttonBw_Callback(hObject, eventdata, handles)# a5 O, n6 i) l. B0 j
% hObject    handle to pushbuttonBw (see GCBO), N) Z- S/ C8 B
% eventdata  reserved - to be defined in a future version of MATLAB/ r: W7 k3 G3 g5 y4 O4 n
% handles    structure with handles and user data (see GUIDATA)+ D( T6 c7 r& x( l' j! V
if ~isempty(handles.Result)
: K0 s' [' ^* v* X: J    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
: G# ?% i% ?' U4 M7 C    axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');8 F! J6 {+ L, v* F2 h  F, N" C9 l
end
2 R0 z; v! i& m) g+ \! G* R , v. i* B+ O& l+ V3 q1 X$ t4 F% A1 e
% --- Executes on button press in pushbuttonEnance.) Z# e* ]  [; f! I0 r: b3 _
function pushbuttonEnance_Callback(hObject, eventdata, handles)
7 {% d: C7 S  c- s4 K% hObject    handle to pushbuttonEnance (see GCBO)/ h/ P! J3 B: i/ N- X$ h% t8 o
% eventdata  reserved - to be defined in a future version of MATLAB
5 _6 R* F0 P9 `2 r0 ]2 X7 S% handles    structure with handles and user data (see GUIDATA)
  {$ n9 G! [' C+ Qif ~isempty(handles.Result)/ j& N7 d: ~- f' z
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
# Q, ^8 e5 U4 `! f0 {    axes(handles.axes2); imshow(handles.Result.Enance); title('增强图像');) w& p- j/ G3 ^  ?0 @! f
end
; t' ?4 b+ \: L* O: Y2 h+ s
; R0 B3 x8 P; G, p; d1 ]% --- Executes on button press in pushbuttonBwfilter.; n( |' u3 ?+ ?1 j- l
function pushbuttonBwfilter_Callback(hObject, eventdata, handles)4 h- C9 h% M: h  w! P
% hObject    handle to pushbuttonBwfilter (see GCBO)( {+ V) ]/ M+ W: c6 L
% eventdata  reserved - to be defined in a future version of MATLAB
) j  ]/ m0 ~; J4 W, \% handles    structure with handles and user data (see GUIDATA)
8 R8 x' `7 J: o, N7 D8 O9 V% Cif ~isempty(handles.Result)* J  d# w; q" i& T! O# L
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');1 T( i$ {7 ^3 o) |8 X: S
    axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');
$ e5 y( @# J; l1 K/ ~    axes(handles.axes3); imshow(handles.Result.BwFilter); title('二值图像滤波');& ]8 H' q: @9 ^$ k2 F
end
1 M4 D: h5 a* {: R  s2 {
& `5 V7 b6 V6 B2 I$ j9 ?) n1 R2 ~% --- Executes on button press in pushbuttonCrackRec.
# L" B$ x6 [; ^; |9 Z. [+ Afunction pushbuttonCrackRec_Callback(hObject, eventdata, handles)  D( e& w4 ~' s' g
% hObject    handle to pushbuttonCrackRec (see GCBO)7 {* m1 x& T) w8 G3 V, q" P8 e
% eventdata  reserved - to be defined in a future version of MATLAB# Q, W# h* b' d; l3 g/ c* A
% handles    structure with handles and user data (see GUIDATA)6 `: X- Y4 S5 Y$ }& s! s" V9 f+ ]2 f, h
if ~isempty(handles.Result); [% {% Z4 V$ @4 t8 D& @4 `: f! q' ?
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');8 b" G( W3 _4 ]3 n7 j4 h
    axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');0 ^/ b+ k7 v( s9 U1 O8 e
    axes(handles.axes3); imshow(handles.Result.BwFilter); title('二值图像滤波');; z4 g/ l- d$ L
    axes(handles.axes4); imshow(handles.Result.CrackRec); title('裂缝识别');0 ^' G7 \. r# @5 \  p
end
9 W( b7 c, K# E1 H ( ^/ c- `$ v- r2 {% ?. x- r
2 p2 m9 {5 u: {( p" K
% --- Executes on button press in pushbuttonCrackJudge.9 I# U0 Q+ \2 G8 j+ }8 h9 u9 u
function pushbuttonCrackJudge_Callback(hObject, eventdata, handles)
$ Z# `6 }" g9 a4 ?4 Y/ z0 W; N) ~+ s% hObject    handle to pushbuttonCrackJudge (see GCBO)
" T. X; c6 a' }0 n3 o2 h9 o+ z% eventdata  reserved - to be defined in a future version of MATLAB$ p/ S2 v3 s) [7 V
% handles    structure with handles and user data (see GUIDATA)
/ ?  d4 ^) p' |8 z" i2 d( A0 uif ~isempty(handles.Result)* X) d0 M$ r& r4 e8 L
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
: L* M7 T1 A) O8 `$ f  k9 X    axes(handles.axes2); imshow(handles.Result.BwFilter); title('二值图像滤波');
: j# J  u0 Y9 r: n$ I% g( s    axes(handles.axes3); imshow(handles.Result.CrackRec); title('裂缝识别');8 c+ f6 B1 n9 t5 g1 S
    axes(handles.axes4); imshow(handles.Result.CrackJudge); title('裂缝判断');; A$ A/ g. H! V; q
end+ G* }4 e8 ^1 ]0 y0 m% c# Z
. r+ y3 s$ b$ y, B5 f
% --- Executes on button press in pushbuttonCrackLoc.
$ q* O) \7 F# ~* Tfunction pushbuttonCrackLoc_Callback(hObject, eventdata, handles)
2 M% f/ b; U7 l+ T2 ?5 S9 l% hObject    handle to pushbuttonCrackLoc (see GCBO)/ T: y9 P) y8 F- l& y
% eventdata  reserved - to be defined in a future version of MATLAB
8 B- `7 d0 y: _4 o: e( J* Z, \" K% handles    structure with handles and user data (see GUIDATA)
+ \( C, h" M- R: x" lif ~isempty(handles.Result)
/ \/ ^/ \+ f5 ?6 \( C# y/ g) T    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
/ m* K0 B* o7 d% O7 E3 b) h    axes(handles.axes2); imshow(handles.Result.CrackJudge); title('裂缝图像');2 P4 D9 ~2 `- J& `5 h
    axes(handles.axes3); imshow(handles.Result.CrackJudge); title(handles.Result.str);
4 @) `/ T8 o* S, v1 k    axes(handles.axes4); imshow(handles.Result.CrackJudge); title('裂缝标记图像');0 e7 `3 Z, @" P) }: g( _
    hold on;; H7 d3 I9 {& t) ^% h3 x) L
    rectangle('Position', handles.Result.rect, 'EdgeColor', 'g', 'LineWidth', 2);! r& {9 Y2 H5 Q% ?$ \9 @- H% ^0 ?
    hold off;
$ D) r6 `! N! k: m7 Pend4 c, S" ], i- k

7 o) g7 l1 O" ~$ w7 H' X% --- Executes on button press in pushbuttonProject.
5 L5 e9 r5 \7 _* i# ~function pushbuttonProject_Callback(hObject, eventdata, handles)2 w6 {9 x5 a  C$ S; G" u
% hObject    handle to pushbuttonProject (see GCBO)
. D9 P2 Z- t6 X0 Z. N  t; Z$ p% eventdata  reserved - to be defined in a future version of MATLAB( H2 c% g% D8 r2 k* ^( i
% handles    structure with handles and user data (see GUIDATA)
. g& ^5 S( u( Fif ~isempty(handles.Result)
8 m1 n+ x( J) C  S% x! Y; v    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');8 V* x5 }  Z3 c' N; @, {
    axes(handles.axes2); imshow(handles.Result.CrackJudge); title('裂缝图像');; x) i" T1 y' `) H9 t# e$ w! e" G
    axes(handles.axes3); plot(1:size(handles.Result.Image, 1), handles.Result.Projectr);3 c- Q' y/ Z3 W
    title('行投影');7 m8 r& l. I) g
    axes(handles.axes4); plot(1:size(handles.Result.Image, 2), handles.Result.Projectc);
8 q2 |; K" T; O+ j, e" b    title('列投影');$ h% C, t/ l+ `
end
8 X2 D) T, x. z% o & N) g6 |4 `, s2 X. J' g

% u- O' b& i6 B8 G; Q* o% --- Executes on button press in pushbuttonClose.
, I" Z" ]  L5 gfunction pushbuttonClose_Callback(hObject, eventdata, handles)$ x3 C) D! U# C/ I. @
% hObject    handle to pushbuttonClose (see GCBO)
; t% k8 A  V( U# `7 o% eventdata  reserved - to be defined in a future version of MATLAB
, ?! {- h( N, i) g( [6 V' @5 }7 i% handles    structure with handles and user data (see GUIDATA)
. X, ~* T0 I0 V) d' F0 ~# tchoice = questdlg('确定退出?', ...7 Y  o6 V8 j% X4 t8 U
    '退出', ...# X4 l. A1 c4 V) l) ^' l. G) t
    '是','否','否');7 R! }, m: Z2 V8 O
switch choice
8 q1 c- O4 f9 I1 P/ \    case '是'7 ]2 J/ r- S6 P; M
        close;
" L% ?$ O0 @$ \/ N0 w7 n$ d    otherwise
1 R6 t) l) J* W- `% V( {3 M2 Q% k        return;0 u) L; Q' W7 U+ W3 v* Y9 {1 u9 ?7 U7 q+ T
end. \( X& Y% y% R- H% {

* \# _  p, T4 V9 t7 |1 t6 @ ) y" a8 p/ W: J. \
! z+ V3 K0 v( S( B% w5 f% S
% --- Executes on button press in pushbuttonSaveResult.6 n; B, k2 I8 }) ~5 K
function pushbuttonSaveResult_Callback(hObject, eventdata, handles): C7 {8 t: Y# X  Q4 [, Y
% hObject    handle to pushbuttonSaveResult (see GCBO)
- Q% O& M' F! ^& @+ a& a% eventdata  reserved - to be defined in a future version of MATLAB8 M: W/ K. ]0 r3 Y8 N& [7 H
% handles    structure with handles and user data (see GUIDATA)
) J- [/ b' j2 ptry# k2 T5 }1 y/ c- j$ ]! n
    if ~isempty(handles.File)
! O9 ]2 i/ G/ b% u7 P5 w: m+ m        raw = [];4 |- e& D/ e) N) |% l6 ^) \) Q* B
        xlsfile = fullfile(pwd, 'Result/result.xls');
& Y: L, T% t# H5 W. y        if exist(xlsfile, 'file')# F) \$ [5 z5 M( S
            [num, txt, raw] = xlsread(xlsfile);
, y/ x7 s6 w  M, X8 ]' x! [        end, k$ [! C5 R0 m9 @! o
        8 ]8 t( \0 W1 `% p3 d0 d
        F = [];) \6 \% h, @* w; r/ Q  O: c
        F{1, 1} = '文件名';
; Q, F# j* q; M' E1 P        F{1, 2} = '阈值信息';' M* d2 y' h- h8 M  V; Q
        F{1, 3} = '面积信息';5 ]/ I9 H' X- x1 t7 x
        F{1, 4} = '长度信息';
4 I# E$ l  B2 b: A# d; }        F{1, 5} = '最大宽度信息';
' k  x5 N, @" G3 R+ u6 o, V, a        F{1, 6} = '最小宽度信息';
# U6 z7 B0 T" M7 D4 T2 N        F{1, 7} = '形状信息';8 e& M, n/ L1 Z) H6 E6 |/ \, ]$ @
        ) X/ l" D! r$ X& e# ~# }7 W
        F{2, 1} = handles.File;
% V8 N; E) ?( Y, U9 H        F{2, 2} = handles.Result.BwTh;
2 B0 u( t$ f# N% H4 d4 L' w( D; g        F{2, 3} = handles.Result.BwArea;
% C/ G: B; I8 u+ ?. F        F{2, 4} = handles.Result.BwLength;" \; \7 X/ t3 a( x
        F{2, 5} = handles.Result.BwWidthMax;7 _) G0 C; L- r- w: a
        F{2, 6} = max(handles.Result.BwWidthMin,0.01);
" c6 u$ B0 m, m" j; H2 {* s" I        F{2, 7} = handles.Result.str;
) Q- Z0 i9 P. L% O# b        
7 V# t% h# C7 k2 u% C# V        F = [raw; F];4 f8 r( P8 o/ t: |# U3 C! _
        xlswrite(xlsfile, F);% Z3 |4 H7 k" g
        
/ B: F- p; r+ B3 j: `        msgbox('保存结果成功!', '信息提示框');
; [2 [$ k* k- A$ l! ]9 Z9 x    end2 d% g# d+ c- B- V! ^$ ]. N
catch
; _' e5 o% M3 K  q- V+ T    msgbox('保存结果失败,请检查程序!', '信息提示框');- {- K8 w: [3 n
end
7 ]/ G! l" e: z8 H1 F1 Y* X
4 z' \) ?* _/ X' C) C- w' \- N) T1 z # O% V2 @5 L+ u/ ]
% --- Executes on button press in pushbuttonBridge.
# c/ k& d! ]4 y4 w/ r2 Ffunction pushbuttonBridge_Callback(hObject, eventdata, handles)
; E1 \7 T9 @3 n8 v# ~: C% hObject    handle to pushbuttonBridge (see GCBO); m# H. r) Z) P; g3 J! }* M3 o$ U
% eventdata  reserved - to be defined in a future version of MATLAB
& y7 A0 G8 t: J" w. E5 ~% g% handles    structure with handles and user data (see GUIDATA)5 ]+ r, u: Z. j- C, u/ N
if ~isempty(handles.Result)
# H" N/ i4 J5 p5 d; U3 Y0 X- R    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');0 D. O  s% N8 t* O$ w9 P4 {  h) R
    axes(handles.axes2); imshow(handles.Result.BwFilter); title('二值图像滤波');5 O! ^/ E! Z) G7 `2 X' G
    axes(handles.axes3); imshow(handles.Result.CrackJudge); title('裂缝判断');: C8 U0 E  d- h; K8 U: `
    axes(handles.axes4); imshow(handles.Result.CrackBridge); title('裂缝拼接');
3 M) ~; l- |7 ~& @end4 x, e: h( M- y$ G
% _0 D' X5 D1 J. k2 k) h

$ a# Z& Z' r' Y4 t7 D5 |, u% u% --- Executes on button press in pushbuttonSaveImage.! X7 P* N' j6 D8 x1 R9 K* Y
function pushbuttonSaveImage_Callback(hObject, eventdata, handles)- ^+ d' k7 P. t$ Y+ W) c3 F
% hObject    handle to pushbuttonSaveImage (see GCBO)
5 [" S2 y8 O4 Q( h% eventdata  reserved - to be defined in a future version of MATLAB( _) q* G! ]0 G7 L! `
% handles    structure with handles and user data (see GUIDATA)5 A+ J% R; ^* y/ y0 d* k0 F
[filename, pathname] = uiputfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...* Z" t; a- H) ]# U: O
    '*.*','All Files' },'Save Image',...
( T2 N$ b& g' J4 h6 A    fullfile(pwd, 'Result/result.png'));" D' A7 E$ `/ t! _2 s0 w9 V
if ~isequal(filename, 0)
) t0 N; ?; _0 [. e9 k; p2 H& \    imwrite(handles.Result.BwEnd, fullfile(pathname, filename));. ?) w$ W8 p. {3 Q: J1 w+ F1 e
    msgbox('保存图像成功!', '信息提示框');
( Y( l) z* b8 T: v2 Cend
( {, I7 `! k# a0 O5 U! O, K
5 Q; f3 ?! Z/ h" c 9 G+ B3 V1 Y* B; X2 L
% --- Executes on button press in pushbuttonDiplay.
3 h% l) J) v5 c8 C  K% F: q% pfunction pushbuttonDiplay_Callback(hObject, eventdata, handles)
+ {1 E+ w- r# e- V& u% hObject    handle to pushbuttonDiplay (see GCBO)! S2 v2 r% d% P! ^& f" {+ ~
% eventdata  reserved - to be defined in a future version of MATLAB
7 m4 l" K% @" [% handles    structure with handles and user data (see GUIDATA)7 o* E1 E# ~$ E$ i  L, c. q
if ~isempty(handles.File)6 }4 j" D4 j+ w2 ?0 p4 }2 l6 v
    F = [];# {7 f1 ^7 X7 O* {4 y2 e
    F{1} = sprintf('文件名:%s', handles.File);
4 p1 \6 u6 S% E4 s7 _+ Y* [/ f' I    F{2} = sprintf('阈值信息%.2f', handles.Result.BwTh);/ b# [( j6 D% i
    F{3} = sprintf('面积信息%.2f', handles.Result.BwArea);
6 O4 n# g0 k' L, G* J/ F" }9 U    F{4} = sprintf('长度信息%.2f', handles.Result.BwLength);
$ R/ @0 T9 h6 O; U$ S    F{5} = sprintf('最大宽度信息%.2f', handles.Result.BwWidthMax);
! l% U6 q( X- e( n. i' s    F{6} = sprintf('最小宽度信息%.2f', max(handles.Result.BwWidthMin,0.01));& W8 z5 w+ A2 Z1 H8 E$ {  e% p
    F{7} = sprintf('形状信息%s', handles.Result.str);
& m$ q9 ]% Z) l4 `& i% @/ E* r    listdlg('PromptString', '参数显示:',...
* ]" U5 h" `: H        'Name', '参数信息', ...# ?! s  x& Y; t
        'ListSize', [300, 150], ...
0 m: N7 r+ F$ l8 _6 |7 B. A; |3 s+ T        'SelectionMode','single',...
7 U, Y4 h" {" }1 e4 k  w4 |        'ListString', F);
- w8 z: U" c  Y  ]end! b" F" U- K9 z2 _* Y# F

2 `  p  \+ }# {! P) T- e4 [9 _: M三、运行结果# b% g& M0 ^) [9 w  m% U

" I9 `3 s1 I+ l' F" X% O
' W5 j# m8 K8 G$ k% R5 Y( n) o) `9 s! ?) \5 V3 @6 @# y

$ V$ `* Z+ P- W0 |; v; u
. O5 [4 h( _$ a8 h

该用户从未签到

2#
发表于 2021-4-14 10:51 | 只看该作者
基于matlab GUI路面裂缝识别
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-11-23 20:58 , Processed in 0.187500 second(s), 26 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表