|  | 
 
| 
8 r, d. W) b* Y' d) ]) e$ h! }
x
EDA365欢迎您登录!您需要 登录 才可以下载或查看,没有帐号?注册  一、简介
 0 S; a% ]8 y. ^5 Y. w4 `: D3 |  k高速公路路面病害养护和管理的重要部分就是路面裂缝的检测。近年来,路面裂缝自动检测技术已得到了广泛应用,而由于路面裂缝图像的复杂性,检测算法直接影响着检测结果的精确度。因此,本文将重点放在路面裂缝病害的检测上,为了提高检测的精度,分别从裂缝图像的去噪、图像的增强、图像的分割以及检测后路面裂缝图像的特征提取方面进行深入研究。  在路面裂缝图像中,由于裂缝信息与背景对比度偏低,难以将裂缝直接检测到。对于图像的预处理,首先对图像进行灰度校正,再对校正之后的图像滤波,本文提出了一种改进的中值滤波方法,对图像进行去噪,之后用基于模糊理论的图像增强原理对图像做进一步增强,有效提高了路面裂缝图像的对比度。  针对路面裂缝图像分割,本文分别用了阈值分割和基于形态学多尺度的思想,对于形状规则的裂缝采用的是阈值分割,对于裂缝形状不规则的图像,本文设计了一种多结构元素的抗噪型边缘检测算子,且依据不同形状的结构元素对裂缝边缘填充的几率不同,确定了自适应权重,使得算子检测到了各种类型的裂缝边缘,有效地提高了检测的精度。  对于经过分割后的路面裂缝图像中存在噪声和裂缝断裂的问题,本文对于断裂较窄的图像用形态学中的闭运算和开运算去处理,对于断裂较宽的图像,提出了一种基于生长的断裂裂缝块的连接方法。提高了连接的效率和准确率,使整个检测结果清晰完整。最终,从识别结果图中提取裂缝信息。根据得到的识别结果图,设定一系列判定条件,提取出裂缝的连通域,对裂缝的类型进行判断,最后计算出网状裂缝的面积及线性裂缝的长宽信息。
 4 e4 ^) [/ {$ j& ~7 q1 Z( V- L" P+ q! |4 `
 二、源代码, m  Y' ?1 o; \
 function varargout = Gui_Main(varargin)2 j8 j1 `7 L( }0 A
 % GUI_MAIN M-file for Gui_Main.fig( G& U# b1 V/ C2 D
 %      GUI_MAIN, by itself, creates a new GUI_MAIN or raises the existing
 l9 q0 G( O& M% Z+ B9 Z%      singleton*.
 % t- i! `7 S; T6 z& E& b%
 , V$ V1 }) L$ L, C' y1 H# h%      H = GUI_MAIN returns the handle to a new GUI_MAIN or the handle to
 ) ~/ s  W1 ~  H( G) F%      the existing singleton*.
 # Z, ~5 i# h' r, A2 @%
 ; \0 M2 s% G  i4 S%      GUI_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local. d4 m$ v* g$ k$ n0 R3 R
 %      function named CALLBACK in GUI_MAIN.M with the given input arguments.$ h+ R+ h% ^' n( \9 S9 s; f
 %
 $ g- o) x% f% ^/ s+ U! Y* ~%      GUI_MAIN('Property','Value',...) creates a new GUI_MAIN or raises the
 9 q" u0 x. [, s* L+ s" s6 r%      existing singleton*.  Starting from the left, property value pairs are, Z  y& ~' j& e1 f' K& n
 %      applied to the GUI before Gui_Main_OpeningFcn gets called.  An  t% t; G5 Q9 z/ E% i! Z/ R
 %      unrecognized property name or invalid value makes property application. r+ ]- M6 a0 a& h5 ]# x! ]
 %      stop.  All inputs are passed to Gui_Main_OpeningFcn via varargin./ t- O$ O) E& j
 %" q. L. ?, ~5 g1 A/ H4 X& R8 o
 %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one% |' y3 J3 s- N2 e
 %      instance to run (singleton)".1 l* a9 y* e3 a6 H
 %
 . f4 W: b0 w1 C. T, [; ~: x& Q% See also: GUIDE, GUIDATA, GUIHANDLES
 * B: ?/ N/ V* u, f) s/ M
 / [: y% {$ b7 @& f# ^% Edit the above text to modify the response to help Gui_Main
 # r- n; o* ~5 \0 Q( ~) y2 r 1 R6 r  P' F. l
 % Last Modified by GUIDE v2.5 29-Mar-2011 22:28:58: S, u2 Q( p) ]& i: d: |4 u- j' T
 
 3 _; J1 C: O, A( g% Begin initialization code - DO NOT EDIT+ Q$ J, `/ {$ B' ~+ A; h5 q
 gui_Singleton = 1;! X% m2 ?) t4 z4 g- k
 gui_State = struct('gui_Name',       mfilename, ...
 ( O& g9 i) H  p$ b: N    'gui_Singleton',  gui_Singleton, ...& Z/ Q  U  Z/ W
 'gui_OpeningFcn', @Gui_Main_OpeningFcn, ..., z6 D; f: B* E4 Z- t/ z8 i
 'gui_OutputFcn',  @Gui_Main_OutputFcn, ...
 6 y6 T+ j$ y( {" g8 D, u; l    'gui_LayoutFcn',  [] , ...
 7 D: `; t5 D4 I& G% @& c    'gui_Callback',   []);$ n( z! n7 G) k# {2 y  g
 if nargin && ischar(varargin{1}); z( Q4 h6 D" I6 L4 p
 gui_State.gui_Callback = str2func(varargin{1});
 9 q6 }4 i+ p3 B! \# d1 x; nend
 9 y; U! _7 o9 p$ H; z9 N4 \. b 1 ?$ a! ]1 K% q
 if nargout3 }* W: F  e5 |/ k8 G# C" D6 b7 o- T4 ^
 [varargout{1:nargout}] = gui_maiNFCn(gui_State, varargin{:});! V) Z9 D) T8 H" ~( g. U
 else
 , |/ O, I2 e4 S2 U/ ?0 i    gui_mainfcn(gui_State, varargin{:});
 s- ~& V4 F/ Q6 e$ L' K+ U5 ?end
 ( d6 P: d# P3 n( @& X- I% End initialization code - DO NOT EDIT4 D9 E6 y/ ~4 ^1 R. v0 ^1 D
 ( l8 Y4 B1 F. D. O; V
 
 2 G" `! ]+ [" q) S1 r% --- Executes just before Gui_Main is made visible.- V+ \3 F! n, v& N
 function Gui_Main_OpeningFcn(hObject, eventdata, handles, varargin)6 b' f: a& A: b9 r) c
 % This function has no output args, see OutputFcn.9 o9 g  k6 T: @, m3 j
 % hObject    handle to figure
 - ^! q! z$ {5 s% eventdata  reserved - to be defined in a future version of MATLAB' v4 E- N2 l4 V5 j2 Y. p
 % handles    structure with handles and user data (see GUIDATA)
 4 o0 ~& s9 e% ?( w: e, D8 }$ a# J% varargin   command line arguments to Gui_Main (see VARARGIN)
 1 A) l* m; g/ W8 R+ D7 T
 % i; [, t7 g  ~3 e- Y; p% Choose default command line output for Gui_Main
 % a% Y" |% M7 R& r- e# M4 Vhandles.output = hObject;& q" c, X0 M/ q. k
 handles.Result = [];" E* O; C4 u- t- z. b
 handles.File = [];
 ! L5 x" I& k. a& d& e% Update handles structure$ i/ J  O) g. i* {) L9 A, Y
 guidata(hObject, handles);- H9 c& a' ^) N' s" S1 D
 clc; warning off all;
 9 x7 b! D( C( |$ XInitAxes(handles);
 8 h( r4 x$ p! ~; R! ?( X( d% D
 2 }4 X0 }! W8 g* R; y% UIWAIT makes Gui_Main wait for user response (see UIRESUME)
 8 I2 F- ~* A; X0 Q2 j% X9 q/ ^; F1 A) X3 D% uiwait(handles.figure1);
 " A/ C% X/ X2 w: `6 J
 / m' L: b  n, N' x& x
 ( J- e4 U; q# [) _; S% --- Outputs from this function are returned to the command line.
 4 w' o! L3 e) Z6 P$ x) O! @1 bfunction varargout = Gui_Main_OutputFcn(hObject, eventdata, handles)' q# \7 ]% S0 o9 T  O9 T
 % varargout  cell array for returning output args (see VARARGOUT);
 $ ~- E. p  ?' ^% hObject    handle to figure
 , ^0 h( @, M6 ?0 B% eventdata  reserved - to be defined in a future version of MATLAB6 [+ O: r1 K* y" W" e3 W% v
 % handles    structure with handles and user data (see GUIDATA)3 [  V5 t7 U$ l2 n7 l
 
 8 t$ ~8 Q0 z! n; B2 ]2 U% Get default command line output from handles structure" g9 G, F& c7 c9 x* P
 varargout{1} = handles.output;
 & p% [1 l! X( ^4 L : \+ o8 t' f7 f2 ]; v! f
 ( L9 T8 ^/ h9 r
 % --- Executes on button press in pushbuttonOpenFile.9 v* Z6 z( m- P8 t- J
 function pushbuttonOpenFile_Callback(hObject, eventdata, handles)% e" v$ l- D% K1 M
 % hObject    handle to pushbuttonOpenFile (see GCBO)
 % y% \' y6 ~" o+ ^8 K% eventdata  reserved - to be defined in a future version of MATLAB# w) S' |9 }; }
 % handles    structure with handles and user data (see GUIDATA)
 6 p4 {) A* V1 Y2 v4 y( d3 L* n! `+ n7 X[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
 7 s( h' {- Q, t& k' u2 H# J    '*.*','All Files' },'载入图像',...6 O; d8 o3 Z- q5 P8 H( R* K
 fullfile(pwd, 'images'));( E: z4 @# q7 t* b1 G
 if isequal(filename, 0) || isequal(pathname, 0)
 6 |4 w& p) }5 F2 ^! z/ L5 P5 e    return;5 l1 \2 x4 E; W6 X/ L
 end) a& x. H. G2 v" F; V5 F9 K% T
 I = imread(fullfile(pathname, filename));
 : [, t! y4 p3 T/ |- E# E1 s& oResult = Process_Main(I);- g4 T, W* U+ e
 handles.File = fullfile(pathname, filename);0 t/ C% h8 [% ~" ^# [8 [
 handles.Result = Result;
 : v( d' \9 N7 S/ J+ x! Vguidata(hObject, handles);
 ( c- a' h3 t3 p" W: M2 b! ]6 XInitAxes(handles)6 F* M+ V6 k2 w
 axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
 l* Z% y2 b) z  Y
 |2 W; _- p8 ^5 g, U 0 x$ B! s1 ~0 o2 J; y6 [
 % --- Executes on button press in pushbuttonHisteq.
 : ^" M- w4 k& R7 m2 ffunction pushbuttonHisteq_Callback(hObject, eventdata, handles)
 , m; c# ^2 |4 ~' h% hObject    handle to pushbuttonHisteq (see GCBO)6 W; s! t4 u# f& Q  D8 j# n
 % eventdata  reserved - to be defined in a future version of MATLAB
 6 b8 K) u+ U& T, d% handles    structure with handles and user data (see GUIDATA)
 % ^* o% B, G" t% L; {if ~isempty(handles.Result)
 " b9 s  h# V( U1 f* V    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');( }7 K: }; h/ @1 U0 Z0 H# R) [# }
 axes(handles.axes2); imshow(handles.Result.hist); title('直方图均衡化图像');
 - \! H* \! ]' A5 l; eend! g! d" w1 f. [4 t" g8 n
 
 + a  R8 E8 m& [* ]$ U # a5 a5 X: c; \. j8 `' R
 
 1 Z8 E4 m% a5 X& N: o% --- Executes on button press in pushbuttonMedfilt.
 1 H+ b! I; j+ _function pushbuttonMedfilt_Callback(hObject, eventdata, handles)
 + N5 H  c2 K" j% hObject    handle to pushbuttonMedfilt (see GCBO)% R8 N* n. G# y. \, r4 G
 % eventdata  reserved - to be defined in a future version of MATLAB
 v3 K1 Q- f# J- P4 z/ F7 H  v6 z% handles    structure with handles and user data (see GUIDATA)
 . v% C) I4 }5 u8 B+ h$ v: L+ jif ~isempty(handles.Result)
 ' \; Y( j( }0 C( I9 G1 A    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
 7 e7 ]6 w( _5 ]7 X2 e9 ?! o, {* K    axes(handles.axes2); imshow(handles.Result.Medfilt); title('中值滤波图像');
 2 [- Q# @3 u/ M& Q/ ~4 L: p6 [9 Aend
 " k: F5 Y7 g5 C& e+ G
 7 \# a/ z/ X+ x
 8 F/ I8 u7 \7 o# a% --- Executes on button press in pushbuttonBw.
 % h; o" [, Q1 r$ Z2 lfunction pushbuttonBw_Callback(hObject, eventdata, handles)/ |" p* W+ `% N# G- e
 % hObject    handle to pushbuttonBw (see GCBO)
 - }# U' p! n! `% eventdata  reserved - to be defined in a future version of MATLAB- X" e$ D' Y' z1 g& h) p) j/ S. Y
 % handles    structure with handles and user data (see GUIDATA)
 ! u0 {: Z* l" e) H1 W4 }9 P' Yif ~isempty(handles.Result)
 4 z4 q; ^' s3 f8 |5 M7 e( _    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
 . _) R! d* i+ H' Y4 V; w    axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');
 $ C+ w2 ^( j- O( P7 Hend& u: n; K5 @  M  a, v
 
 ; \, z, A0 c5 ^( C" V$ y% --- Executes on button press in pushbuttonEnance.3 t1 |# Y6 w, m) ?7 V: T) r5 f- g
 function pushbuttonEnance_Callback(hObject, eventdata, handles)/ f( U; m% z, t% W, ?* G6 F
 % hObject    handle to pushbuttonEnance (see GCBO)
 6 U( b5 l8 P2 @- m4 K% W* n$ [% eventdata  reserved - to be defined in a future version of MATLAB0 }4 d% [4 y. n4 T* \/ X! T% G
 % handles    structure with handles and user data (see GUIDATA)
 1 v7 o0 x4 R& F! }0 N: `$ y" Lif ~isempty(handles.Result)
 0 o+ K2 R4 }- X( x1 p% c    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
 ! [' C! K. B. f9 D4 @1 J0 e    axes(handles.axes2); imshow(handles.Result.Enance); title('增强图像');
 4 W' @2 f; C0 Y5 a0 rend
 ' {1 _$ @* F: j4 q " z6 W7 c7 U6 ]: g3 \( M/ Q: X0 ^
 % --- Executes on button press in pushbuttonBwfilter.* ?# @' i% L, @, U
 function pushbuttonBwfilter_Callback(hObject, eventdata, handles)
 ; V& |# Z  b4 o1 n% G$ ^% hObject    handle to pushbuttonBwfilter (see GCBO)
 8 `0 W( S3 S8 ~" E" ?+ U% eventdata  reserved - to be defined in a future version of MATLAB% P$ K5 w' A; t+ I
 % handles    structure with handles and user data (see GUIDATA)
 5 t( y* F. y5 y2 w! bif ~isempty(handles.Result)7 y9 x. D$ W: }) |- Q5 k1 Z2 U
 axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
 8 y* R+ z$ n0 N; u* ~    axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');
 ; G' o9 |- M: {7 [3 r    axes(handles.axes3); imshow(handles.Result.BwFilter); title('二值图像滤波');
 2 c$ t, X( z% r8 A. Xend3 r  h2 @3 B& u! J; v/ H# z' N% O
 0 _; c: @2 E' @3 ?% X/ u! ~
 % --- Executes on button press in pushbuttonCrackRec.
 ( I& `4 O( m" k( x1 Rfunction pushbuttonCrackRec_Callback(hObject, eventdata, handles)9 n1 |6 P& \6 w" M4 i3 w
 % hObject    handle to pushbuttonCrackRec (see GCBO)
 6 }" b0 }) I! y3 ^0 N% eventdata  reserved - to be defined in a future version of MATLAB8 a: T' ~% v# T4 {& V4 k5 w
 % handles    structure with handles and user data (see GUIDATA)+ c8 _" v& r6 }$ ]# ~; B1 v0 m, i
 if ~isempty(handles.Result)$ V5 M! ^$ ^5 i1 E( Y
 axes(handles.axes1); imshow(handles.Result.Image); title('原图像');2 E% u, x2 ~" S* z8 |6 L- q
 axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');
 6 Q1 D; y# D6 }9 {& q) v. W3 @1 C    axes(handles.axes3); imshow(handles.Result.BwFilter); title('二值图像滤波');& R- B! O& e" Q
 axes(handles.axes4); imshow(handles.Result.CrackRec); title('裂缝识别');
 $ F; u7 b5 {0 n0 J  [" l+ {end( s6 o+ l* x/ \# x
 0 ^: B  O, C! ^& G2 b  ~+ [* j
 $ [4 `* [0 c! K  S3 i& o
 % --- Executes on button press in pushbuttonCrackJudge.  E6 Z3 i" ~! D9 H$ w
 function pushbuttonCrackJudge_Callback(hObject, eventdata, handles)# w6 L: L2 w5 x+ ~3 |
 % hObject    handle to pushbuttonCrackJudge (see GCBO)/ Q: h) W  ], U# Z1 B6 H' t) Z# ]
 % eventdata  reserved - to be defined in a future version of MATLAB  S6 C) j  b/ ~* I
 % handles    structure with handles and user data (see GUIDATA)
 ( z4 f) u/ v# I! Y1 Mif ~isempty(handles.Result)
 3 s6 O& G5 A2 n- f' ~3 b    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');- B) |& i  U# h% l; a
 axes(handles.axes2); imshow(handles.Result.BwFilter); title('二值图像滤波');" }3 w$ V$ h( ^3 G8 C( L
 axes(handles.axes3); imshow(handles.Result.CrackRec); title('裂缝识别');
 : Y* D5 J5 o% n7 I) c2 `! S" r3 T    axes(handles.axes4); imshow(handles.Result.CrackJudge); title('裂缝判断');2 v7 Q  }% Q8 v2 y0 u3 U7 `6 p
 end/ C7 F% B/ D8 {2 [" D9 o3 f
 : Q, Q* y9 E# S6 p0 V( ]' F
 % --- Executes on button press in pushbuttonCrackLoc.% x0 U9 n7 K( Y8 G
 function pushbuttonCrackLoc_Callback(hObject, eventdata, handles)
 ) m0 M1 D$ @& R8 O; e9 v; ?% hObject    handle to pushbuttonCrackLoc (see GCBO)
 3 ^5 c, `/ b& c1 H% eventdata  reserved - to be defined in a future version of MATLAB; i( _6 K( @5 j# O+ y
 % handles    structure with handles and user data (see GUIDATA)
 7 M9 R! Z* g3 _- o0 vif ~isempty(handles.Result)
 ! K0 u2 I. \. K4 s    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');: F0 B7 i/ d, P
 axes(handles.axes2); imshow(handles.Result.CrackJudge); title('裂缝图像');. T( x" w6 `5 u
 axes(handles.axes3); imshow(handles.Result.CrackJudge); title(handles.Result.str);( X6 A/ t- @- ]# N9 A( ^+ Y8 V9 n" ]. L
 axes(handles.axes4); imshow(handles.Result.CrackJudge); title('裂缝标记图像');
 + u$ f$ `* _3 j1 n5 ^9 Q: {4 V    hold on;
 7 N' _5 n7 n- G6 `    rectangle('Position', handles.Result.rect, 'EdgeColor', 'g', 'LineWidth', 2);+ @  F: \  d* Q. ^
 hold off;
 S% R5 p9 h7 s7 V  yend
 , E7 B- g2 |5 ]4 _6 _
 e$ L2 F" D; Q8 j5 Z" ]" B% --- Executes on button press in pushbuttonProject.
 - U% u+ q# Q( T0 q6 hfunction pushbuttonProject_Callback(hObject, eventdata, handles)% K3 i9 o( e% {6 n6 x7 c$ k
 % hObject    handle to pushbuttonProject (see GCBO)
 : A4 t4 C6 h- L, V1 k" o' q% eventdata  reserved - to be defined in a future version of MATLAB
 6 e2 d. t7 t0 S/ A% handles    structure with handles and user data (see GUIDATA)
 % C8 g* v# Z9 w) d  Mif ~isempty(handles.Result)4 P9 J+ O0 J* t& ]! V$ f
 axes(handles.axes1); imshow(handles.Result.Image); title('原图像');, f/ Z! h; C$ ^6 s: ^
 axes(handles.axes2); imshow(handles.Result.CrackJudge); title('裂缝图像');: e; Q6 s7 X. z
 axes(handles.axes3); plot(1:size(handles.Result.Image, 1), handles.Result.Projectr);; v3 S. U0 g7 S- }
 title('行投影');4 |0 K& p) ]+ P& x4 J) D) ^6 K
 axes(handles.axes4); plot(1:size(handles.Result.Image, 2), handles.Result.Projectc);
 4 C! Y9 M0 n0 P( l% d2 r: O    title('列投影');
 * m5 @7 K! u- r7 F6 n$ _1 B1 V# H' i( vend5 o- t& @$ u3 w: r
 ) w5 z- B( G" x+ J, o! l
 " }3 A: g: E6 R8 k: i; b3 X( s) ~/ [
 % --- Executes on button press in pushbuttonClose.3 U, b3 T" U' L9 d( Y5 n& }; F$ D
 function pushbuttonClose_Callback(hObject, eventdata, handles)9 b4 ^& F& e+ J4 t% \; Y8 Q! X
 % hObject    handle to pushbuttonClose (see GCBO)
 * ^. }7 y( k9 f% eventdata  reserved - to be defined in a future version of MATLAB
 2 q% ]' R$ j; j, ^" R% handles    structure with handles and user data (see GUIDATA)4 U" J7 y4 F5 Y. g+ u" B1 G
 choice = questdlg('确定退出?', ...
 c2 ~6 ^$ w  ~  I    '退出', ...
 # f) b1 c- A/ ]2 a( T' U8 s    '是','否','否');
 . `6 [" l9 @, g3 Gswitch choice: G& I4 P4 G# J$ S: L4 M
 case '是'" y3 z+ v# ~3 Y
 close;
 5 q9 O, k* }, x" t  x; s: c5 m    otherwise0 o8 T% k  e8 B+ t" |7 f
 return;
 ( C, W3 N4 Z- jend- l; S8 ]% X- g: H1 z+ @% e
 ) ]$ v/ C% }' n: {# V
 ' G3 _, J5 U+ U: ]- ?' O" |
 
 , k  C  {0 w% m2 I/ {% --- Executes on button press in pushbuttonSaveResult.
 1 N3 O8 t7 @+ W8 Lfunction pushbuttonSaveResult_Callback(hObject, eventdata, handles)
 ( q1 R) M" P) n3 g7 F" U% hObject    handle to pushbuttonSaveResult (see GCBO)5 r5 O. V$ Q) I0 E0 H" `0 {) a
 % eventdata  reserved - to be defined in a future version of MATLAB, g0 N( t2 @* G( r8 V8 M
 % handles    structure with handles and user data (see GUIDATA)( c+ r1 A, O  r
 try- [2 s7 e- V; @* g) v" E& k0 Q! V+ l% p
 if ~isempty(handles.File)
 ) ?: T" g) F7 ]( V        raw = [];: u6 ?( m) u: d3 i4 T7 H9 ]2 x: S
 xlsfile = fullfile(pwd, 'Result/result.xls');
 & d) Q: X5 p% ~* p" ^        if exist(xlsfile, 'file')6 T$ a/ d# z1 T6 G: ~& f% a' F
 [num, txt, raw] = xlsread(xlsfile);
 ) ]+ Y3 |0 O! j        end
 : N9 E  K; L! T% X; s- }
 # M& u! j7 b) U; n( _5 t* l4 z! Y2 S        F = [];
 3 J! S7 c2 Q% y  }: G; t        F{1, 1} = '文件名';
 6 w  X4 x0 b& v/ R$ s        F{1, 2} = '阈值信息';3 x3 Q! L: o* k4 E3 Q: q
 F{1, 3} = '面积信息';
 {0 e$ J) F6 o  J5 O2 M! Y        F{1, 4} = '长度信息';
 . T1 i0 D1 h2 q" ]$ Q        F{1, 5} = '最大宽度信息';$ w! M" y; n- ]! J
 F{1, 6} = '最小宽度信息';5 Y# ~7 V+ Y4 ~7 B( `
 F{1, 7} = '形状信息';7 H! K- x& u/ y9 t$ ~" u1 v. F$ I$ B
 * K9 f( K4 G6 I
 F{2, 1} = handles.File;
 $ K8 R# M4 Z1 U0 f0 j! r: R        F{2, 2} = handles.Result.BwTh;4 }( r+ k4 s& t3 o
 F{2, 3} = handles.Result.BwArea;
 9 m' U: q, f9 U7 _        F{2, 4} = handles.Result.BwLength;" ~# w$ p3 m+ a: n1 y
 F{2, 5} = handles.Result.BwWidthMax;
 & X) y, @. y4 U4 M; r" r  l7 {$ X        F{2, 6} = max(handles.Result.BwWidthMin,0.01);  O& S2 y: q: a% N$ \' d. t
 F{2, 7} = handles.Result.str;7 v4 a; G% `% k6 |4 u
 
 3 V2 q9 ?3 p! ?+ F1 f" D        F = [raw; F];
 # Z' _5 s4 q* N4 [        xlswrite(xlsfile, F);: j* V# @) G; v9 n( H5 `4 B* N4 [
 ) i/ V+ y' V: f' J
 msgbox('保存结果成功!', '信息提示框');7 q/ X5 a2 ]; _. S
 end
 H; l# x% c* B: a& z, s$ vcatch6 v/ ^* t4 ^4 z, |3 P$ Y  k! r) }+ P5 A
 msgbox('保存结果失败,请检查程序!', '信息提示框');
 ! {5 p( b4 ^: i. [6 iend
 6 q% e6 J3 o+ M# r
 * R# l. J( U! s" A6 y. _ 6 V% K0 D) }% W7 D
 % --- Executes on button press in pushbuttonBridge.
 4 c& S8 M# H: N+ W( I% d* `) N- t$ C' k- m  qfunction pushbuttonBridge_Callback(hObject, eventdata, handles)
 % o) k- T5 M# g  s2 C+ `% hObject    handle to pushbuttonBridge (see GCBO)1 A. w& a" O. c9 R& s- H7 U
 % eventdata  reserved - to be defined in a future version of MATLAB
 # @- E7 L4 {1 W: U, x& _* }% handles    structure with handles and user data (see GUIDATA)
 * I1 }" L: F& v- q6 O3 h8 Rif ~isempty(handles.Result)7 e/ D6 p. V" H
 axes(handles.axes1); imshow(handles.Result.Image); title('原图像');) F, I- w) z: T; C% d$ Z4 D
 axes(handles.axes2); imshow(handles.Result.BwFilter); title('二值图像滤波');
 : f3 _9 e: M5 v; U! k, l    axes(handles.axes3); imshow(handles.Result.CrackJudge); title('裂缝判断');
 + b0 G. \( a" |  B; h    axes(handles.axes4); imshow(handles.Result.CrackBridge); title('裂缝拼接');
 * {% S6 p7 ~, c5 W3 _4 xend
 ) P: U! R# R1 v% |
 - r0 K7 z' L8 z  [: W 8 S) u2 S. `1 D3 x! \2 ?
 % --- Executes on button press in pushbuttonSaveImage.
 6 M% O. z* m. @9 u- ], C" E2 dfunction pushbuttonSaveImage_Callback(hObject, eventdata, handles)
 * H' V- z& |. y2 L5 a% hObject    handle to pushbuttonSaveImage (see GCBO)
 2 z7 A! i/ Q; m$ @! \/ t5 i% eventdata  reserved - to be defined in a future version of MATLAB4 U& ]; r) A+ n& V5 z
 % handles    structure with handles and user data (see GUIDATA)$ l; N- n# R/ h% y
 [filename, pathname] = uiputfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
 " d) ?( _# o( ^( E# F    '*.*','All Files' },'Save Image',...
 - l3 U" ^: v3 p2 O) k    fullfile(pwd, 'Result/result.png'));( N- Z, r, Z+ Z/ G0 V& Y
 if ~isequal(filename, 0)# x( v1 J3 t+ F
 imwrite(handles.Result.BwEnd, fullfile(pathname, filename));0 \* S2 @2 u& u2 \; k
 msgbox('保存图像成功!', '信息提示框');
 4 [7 U3 U* r( Hend  u! b% _% e% T0 K+ V* L
 
 ; ?. r% @1 E" O& v - n& ^. a, L2 n, _- G
 % --- Executes on button press in pushbuttonDiplay.( u8 ~; F, m1 O
 function pushbuttonDiplay_Callback(hObject, eventdata, handles)
 ! n2 M" t& ]% h5 w) P( y/ a% hObject    handle to pushbuttonDiplay (see GCBO)
 ( }  a" F  q# c* R- B% eventdata  reserved - to be defined in a future version of MATLAB1 z5 @% w! N- y0 ]
 % handles    structure with handles and user data (see GUIDATA)
 - C' I: K0 J9 l( i. lif ~isempty(handles.File)
 + x& H  `8 R+ s7 l1 C/ ^    F = [];+ F2 b( d. D; e3 Z- i1 n5 Y
 F{1} = sprintf('文件名:%s', handles.File);
 $ n0 q6 `. R4 ^& h+ o8 Q    F{2} = sprintf('阈值信息%.2f', handles.Result.BwTh);
 * v5 C3 R% _; h7 B    F{3} = sprintf('面积信息%.2f', handles.Result.BwArea);
 ' x: T+ S  M: A$ ~" V# c1 u    F{4} = sprintf('长度信息%.2f', handles.Result.BwLength);
 % [: ?# n0 A+ T- ~* h0 e/ |    F{5} = sprintf('最大宽度信息%.2f', handles.Result.BwWidthMax);; w4 B; y! `5 d/ j/ y
 F{6} = sprintf('最小宽度信息%.2f', max(handles.Result.BwWidthMin,0.01));
 ) o  x! [& P- z5 I: L    F{7} = sprintf('形状信息%s', handles.Result.str);
 5 M! T. x! U  J    listdlg('PromptString', '参数显示:',..., M3 N& E* ]$ l5 `% a7 z* y
 'Name', '参数信息', ...
 : h3 q2 y& G# g' y        'ListSize', [300, 150], ...1 s4 k- o/ G1 [# M  [, `; T
 'SelectionMode','single',...5 a; I( A8 ?7 ?' [
 'ListString', F);4 {- x0 z, s) N4 o- U
 end1 [! p+ }: W$ g: }/ Q- v* ]* l
 # _+ F3 z2 D6 c9 ~: R
 三、运行结果
 # a4 G9 j% _! v9 \, a- ~& y3 }- Z4 G$ `
 
  + `) g' v& R* {9 m$ D 
 / l9 {+ b+ _0 t% y" _  N
 ( w0 }# o/ d$ T" v6 r
 3 h# J* s+ P/ h* ?
 | 
 |