|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
8 ]0 x" E. e& n
一、简介
M% C# X" x* K' @/ p+ g/ Z& B) y高速公路路面病害养护和管理的重要部分就是路面裂缝的检测。近年来,路面裂缝自动检测技术已得到了广泛应用,而由于路面裂缝图像的复杂性,检测算法直接影响着检测结果的精确度。因此,本文将重点放在路面裂缝病害的检测上,为了提高检测的精度,分别从裂缝图像的去噪、图像的增强、图像的分割以及检测后路面裂缝图像的特征提取方面进行深入研究。 在路面裂缝图像中,由于裂缝信息与背景对比度偏低,难以将裂缝直接检测到。对于图像的预处理,首先对图像进行灰度校正,再对校正之后的图像滤波,本文提出了一种改进的中值滤波方法,对图像进行去噪,之后用基于模糊理论的图像增强原理对图像做进一步增强,有效提高了路面裂缝图像的对比度。 针对路面裂缝图像分割,本文分别用了阈值分割和基于形态学多尺度的思想,对于形状规则的裂缝采用的是阈值分割,对于裂缝形状不规则的图像,本文设计了一种多结构元素的抗噪型边缘检测算子,且依据不同形状的结构元素对裂缝边缘填充的几率不同,确定了自适应权重,使得算子检测到了各种类型的裂缝边缘,有效地提高了检测的精度。 对于经过分割后的路面裂缝图像中存在噪声和裂缝断裂的问题,本文对于断裂较窄的图像用形态学中的闭运算和开运算去处理,对于断裂较宽的图像,提出了一种基于生长的断裂裂缝块的连接方法。提高了连接的效率和准确率,使整个检测结果清晰完整。最终,从识别结果图中提取裂缝信息。根据得到的识别结果图,设定一系列判定条件,提取出裂缝的连通域,对裂缝的类型进行判断,最后计算出网状裂缝的面积及线性裂缝的长宽信息。- |7 h) `* k ?2 C
/ A$ U% s& R7 A! v& G. b二、源代码& @7 x; j$ `' G+ t/ M3 a
function varargout = Gui_Main(varargin)
0 h" {3 W J; g. d' {" ?+ x/ @% GUI_MAIN M-file for Gui_Main.fig% u% g1 B( D) i+ I
% GUI_MAIN, by itself, creates a new GUI_MAIN or raises the existing7 m) k4 z) W) L" c( U# Y
% singleton*.
1 H. y( A( G- J; y `$ P' X }9 y( a%2 M( {% m2 M# C" O! K9 U) `6 }$ u D
% H = GUI_MAIN returns the handle to a new GUI_MAIN or the handle to/ {- \) l9 f: g( A' {
% the existing singleton*.
9 w( v0 A0 G& H%* k0 s4 ^5 L% ]5 k8 p4 y- ^9 N& p
% GUI_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
& h+ u" Q! z) U" S. a, U' {0 D% function named CALLBACK in GUI_MAIN.M with the given input arguments.0 u1 P+ J) v/ e
%
* {+ r" o2 ], j: @! o6 i4 g( \: \# Y6 D% GUI_MAIN('Property','Value',...) creates a new GUI_MAIN or raises the. B2 k* r" j9 r/ g4 F/ E
% existing singleton*. Starting from the left, property value pairs are) c( U+ ^; ~9 _1 M' X$ E
% applied to the GUI before Gui_Main_OpeningFcn gets called. An8 Z. ~ K/ F j2 v6 c
% unrecognized property name or invalid value makes property application$ t" x7 R! C1 _1 |7 I0 }0 I
% stop. All inputs are passed to Gui_Main_OpeningFcn via varargin.
& T( H/ Y7 M9 m: w8 V8 U& n2 R%( {" s# H8 K% q
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one6 P4 w* @* \9 g. X( S
% instance to run (singleton)".
4 R/ M8 [) K! K$ y1 t%
! f" W p' y1 H7 N% See also: GUIDE, GUIDATA, GUIHANDLES
. }; Q; m# \# J8 H! b% M7 b% X/ W
3 ?# `7 H+ M4 ~3 z1 \% Edit the above text to modify the response to help Gui_Main
" C5 x0 w0 j2 g. E' C
- x* }* P) x& T, k9 K! `: b3 J% Last Modified by GUIDE v2.5 29-Mar-2011 22:28:58
; y* @( V* C8 I) M" q7 F8 P& R ) ?2 B0 c* o. L9 s# \1 G
% Begin initialization code - DO NOT EDIT
+ ~) E1 e: [0 N8 |9 Q' zgui_Singleton = 1;) A* j7 U) @ W. ^& k
gui_State = struct('gui_Name', mfilename, ...
( x5 e8 R0 k! l, o 'gui_Singleton', gui_Singleton, ...# ^ |; m2 o. E
'gui_OpeningFcn', @Gui_Main_OpeningFcn, ...$ d6 e& L8 H4 d% T: Y9 ^6 f- F
'gui_OutputFcn', @Gui_Main_OutputFcn, ...% v0 G8 B0 j' ~- ? V0 G
'gui_LayoutFcn', [] , ...
: T9 g/ ]( v, K 'gui_Callback', []); E- ]' h. R) X, z0 G
if nargin && ischar(varargin{1})
5 X. U% r7 z6 A# Q% z; v0 K6 v gui_State.gui_Callback = str2func(varargin{1});- {9 B) N, U* p- Z( A H! I
end$ V/ I5 t" ^2 T& V# z
3 @9 q! k1 B+ w8 e, D; A3 lif nargout
) Y" E0 W8 Q/ g [varargout{1:nargout}] = gui_maiNFCn(gui_State, varargin{:});" e6 I& I) H! b
else+ O1 S c+ J' D6 x2 e2 s
gui_mainfcn(gui_State, varargin{:});
* {; k( r/ m/ s8 p3 E* ^, r1 i! tend
0 z/ k7 T( G G% End initialization code - DO NOT EDIT
; q: l t& A* i9 m( G 7 o9 o D+ x) g& |# A+ k
1 B. A) n, l0 @- Z% --- Executes just before Gui_Main is made visible.
6 n0 z: a$ }% T9 i* Y3 Qfunction Gui_Main_OpeningFcn(hObject, eventdata, handles, varargin)
Q9 A; M8 Z4 W) F% This function has no output args, see OutputFcn.
% }( k o# E# `& j- h- ~: A4 s0 } G% hObject handle to figure1 G3 n. c, s6 x
% eventdata reserved - to be defined in a future version of MATLAB$ ?0 D# W% S- L+ C4 d7 I
% handles structure with handles and user data (see GUIDATA)
# F: H6 h3 z! ? G8 E; E% varargin command line arguments to Gui_Main (see VARARGIN), d7 ^, W7 w: I$ T+ r) Z
2 n9 }2 P$ o6 ?, }/ D% Choose default command line output for Gui_Main
! a) V2 N. S( P( {+ ^handles.output = hObject;' b( K$ R: w6 J5 X: F. d& x
handles.Result = [];+ i+ I4 G8 a. v3 e+ L4 Q+ ?0 B
handles.File = [];
) r4 w G6 t0 W* d% ]+ ?- v% Update handles structure z: P! q) ~7 T1 v3 M/ T( K
guidata(hObject, handles);! K4 G- G; n1 W
clc; warning off all;
+ z% A0 r3 }( j9 W7 ?InitAxes(handles);& I% V- X' a7 c
* `4 |3 h x8 ~+ f% R3 B9 Q
% UIWAIT makes Gui_Main wait for user response (see UIRESUME)+ O& d9 H: H; W/ g4 H+ v0 s2 y
% uiwait(handles.figure1);
$ P' W6 a4 d) A9 y X; z) H7 l5 A9 `
8 Q h4 w! y2 n2 q, q& X3 Q6 L* T( D4 o0 x% --- Outputs from this function are returned to the command line.
: O4 A) t& D- U. Gfunction varargout = Gui_Main_OutputFcn(hObject, eventdata, handles)8 M' x5 C' v$ j+ w4 ^! J# v& M
% varargout cell array for returning output args (see VARARGOUT);
& e1 ` |. R! m0 I1 F% M( T P% hObject handle to figure/ l/ p8 X9 U# Y5 T; K
% eventdata reserved - to be defined in a future version of MATLAB
" V7 p+ l6 a$ Y- t% handles structure with handles and user data (see GUIDATA)
O2 Y7 a: Y0 i0 L- K
- E* I9 ?# U7 J- q, T# N; m% Get default command line output from handles structure
5 u8 h2 i" T" ?+ ^3 } {" rvarargout{1} = handles.output;
% N) b/ `0 W3 [% H 0 y' r: }; C% J( g9 L; b2 A0 N
, @2 d1 b1 H4 B8 p! s% y0 o+ H" b6 N
% --- Executes on button press in pushbuttonOpenFile.
3 S7 y& a& v; m" V7 A2 Qfunction pushbuttonOpenFile_Callback(hObject, eventdata, handles)
0 I! q' v9 P, k) R% hObject handle to pushbuttonOpenFile (see GCBO) a7 s# N1 I$ X- W P
% eventdata reserved - to be defined in a future version of MATLAB
- _+ g, O/ \, K$ M7 u/ R% handles structure with handles and user data (see GUIDATA). A3 j% Y- V4 ~
[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...4 T4 ^) `- C, g% @ E
'*.*','All Files' },'载入图像',...$ J8 L2 b/ W0 R1 T) {
fullfile(pwd, 'images'));& ?! V" f2 Q! p. D; p4 w
if isequal(filename, 0) || isequal(pathname, 0)4 p6 T9 ^$ H( a0 V
return;
- `+ u+ _- I [* S Hend
/ x# _/ r/ O6 F- c! f; HI = imread(fullfile(pathname, filename));
) L7 s; W9 g oResult = Process_Main(I);: M0 T' v, \: d0 o9 b
handles.File = fullfile(pathname, filename);
% c9 C8 U5 E& B8 B3 ]4 R2 U1 Ihandles.Result = Result;
4 _1 C$ [, s( S! Uguidata(hObject, handles);
9 O; P7 R* U: c+ i5 A# ?InitAxes(handles). C9 T. G: X4 @8 U; D& u
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
2 b6 l3 u q3 _ + H! i: h9 `' g' l2 ^# i
1 R1 t% G# K5 R, T' B! U' j% --- Executes on button press in pushbuttonHisteq.! s: w4 N- a+ c: o
function pushbuttonHisteq_Callback(hObject, eventdata, handles)3 a" v& v+ ?: ^( v: O( Q$ w
% hObject handle to pushbuttonHisteq (see GCBO)
c; N- C/ x1 U- p$ N- v1 P! v% eventdata reserved - to be defined in a future version of MATLAB
! Q6 E/ Z7 k8 q# l, ?; r% handles structure with handles and user data (see GUIDATA)% j" n3 E5 ]7 L' R- Y
if ~isempty(handles.Result)
5 }5 I+ H* r; I6 n axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
, ?( F8 s% D7 q, m axes(handles.axes2); imshow(handles.Result.hist); title('直方图均衡化图像');
7 j6 K7 @8 y: ?4 cend$ q7 g" w H% N* d7 Y4 K2 q
; b/ W8 X8 G! c9 T& ?5 Q% D # l. l3 S; U4 b4 V0 X
' T" f) j8 E& j( u5 C5 z6 [ Q& b
% --- Executes on button press in pushbuttonMedfilt.
' C. S; f( z7 c1 A5 ?- R3 e- sfunction pushbuttonMedfilt_Callback(hObject, eventdata, handles)# R3 e3 i% X; {, U' B6 }. F
% hObject handle to pushbuttonMedfilt (see GCBO)& y- [ I( F" s- @
% eventdata reserved - to be defined in a future version of MATLAB% }# \& V- y& I% h3 @
% handles structure with handles and user data (see GUIDATA), v- Q% j* [+ V4 W% H9 R/ R6 i
if ~isempty(handles.Result)5 N( r! [' p0 i+ _' y# y, C, R
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
. T( ?$ h2 z, Q! S d axes(handles.axes2); imshow(handles.Result.Medfilt); title('中值滤波图像');) f# u. o4 x/ y5 F* [1 y1 s
end
8 `/ Z' Z: |9 W: `* M6 b
9 S" @3 p6 u- @( ?' a; t" G) P 4 F# h6 F' K& J) u7 F# h
% --- Executes on button press in pushbuttonBw.0 p' l# k, M+ ?, h
function pushbuttonBw_Callback(hObject, eventdata, handles)6 l/ F& n J+ S; n3 S0 k s
% hObject handle to pushbuttonBw (see GCBO)
/ b& r, y# T- p* R% eventdata reserved - to be defined in a future version of MATLAB
* m7 Y3 s9 N: l3 b9 H% handles structure with handles and user data (see GUIDATA)' ?! W5 E3 `% N8 o& ^6 ]) r$ @. [
if ~isempty(handles.Result)
* c6 m' o" v1 T' [" K+ {! J7 D axes(handles.axes1); imshow(handles.Result.Image); title('原图像'); j p7 R+ l) \9 O7 C2 \7 ^
axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');5 I- }' E$ R- Q- R
end
' A2 Z Q T5 b: D2 R1 [3 `& ~/ B
# u4 ^2 w9 O K# E9 T% --- Executes on button press in pushbuttonEnance.7 [2 o) u4 ?% a" N' [
function pushbuttonEnance_Callback(hObject, eventdata, handles)
( p" X7 ]2 ^4 d" Z- z% k; a% hObject handle to pushbuttonEnance (see GCBO)) n% n7 a* Y: \& g _. ?7 ]
% eventdata reserved - to be defined in a future version of MATLAB- e' T! g. V* w5 t9 F3 J5 Q$ a
% handles structure with handles and user data (see GUIDATA)
$ a/ ?: y( h& qif ~isempty(handles.Result)
8 F2 c- ~7 L- v$ X axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
6 P6 Z& L0 V9 b& H! V0 O9 B axes(handles.axes2); imshow(handles.Result.Enance); title('增强图像');1 o6 x2 s' V# [, K6 v8 F: ]
end$ u; j, }4 B& c. Z3 ?% Z+ j o, X
! B# D' N0 E4 n2 G& W
% --- Executes on button press in pushbuttonBwfilter.
- q0 Y: B& q: u/ K/ Xfunction pushbuttonBwfilter_Callback(hObject, eventdata, handles)
% K, c: H! c- ?* f9 R% b+ H% hObject handle to pushbuttonBwfilter (see GCBO)
. Q6 F* ^7 |, q, W J% eventdata reserved - to be defined in a future version of MATLAB
# {) ]/ o8 i/ t$ z( W% handles structure with handles and user data (see GUIDATA)3 g. M2 P3 N, B" `, d9 s! M4 z' k
if ~isempty(handles.Result)
" ~' F- k7 n' j' g1 O% e axes(handles.axes1); imshow(handles.Result.Image); title('原图像');" I7 F$ `# \+ v \2 X9 ?# c
axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');
' m3 }4 c# e7 Q5 n axes(handles.axes3); imshow(handles.Result.BwFilter); title('二值图像滤波');
# K B w7 [& W% ~end
0 T( ^: A# I6 c4 r' \- v' x0 J9 e $ g5 ?/ v* h/ G, D9 P4 \8 y& |
% --- Executes on button press in pushbuttonCrackRec.# v; k7 o5 ^; j1 p/ b* g
function pushbuttonCrackRec_Callback(hObject, eventdata, handles)/ C# w* K1 s/ S7 [
% hObject handle to pushbuttonCrackRec (see GCBO). X4 W" z0 ^. q3 @; ~! ]$ T9 r* h, a E
% eventdata reserved - to be defined in a future version of MATLAB
3 J5 [# e+ Z+ g9 K% handles structure with handles and user data (see GUIDATA)
* A/ }1 X" x- O0 }8 |0 `* x5 \% f+ Nif ~isempty(handles.Result)
. X& b+ q# [8 C( ?4 M- [+ E axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
0 b# m( C% ?5 B! \+ s j& P axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');$ ^) i, @- H' Y( |
axes(handles.axes3); imshow(handles.Result.BwFilter); title('二值图像滤波');% Z* b0 L# s& a3 e
axes(handles.axes4); imshow(handles.Result.CrackRec); title('裂缝识别');
0 ]8 n/ Z* d1 v# k+ lend
5 l7 x- g6 [5 \& G* c0 B- j ) V! h4 @( h. a& q. _/ x" i: z
; p8 |# K8 O+ H& [$ d
% --- Executes on button press in pushbuttonCrackJudge.
6 y- r5 N) ?% @7 b3 l) G5 Cfunction pushbuttonCrackJudge_Callback(hObject, eventdata, handles)
, }; i) p, q( i9 C: e% hObject handle to pushbuttonCrackJudge (see GCBO)9 q) ^, r5 M3 B
% eventdata reserved - to be defined in a future version of MATLAB+ U$ b9 y" P' z3 |
% handles structure with handles and user data (see GUIDATA)
2 N8 O3 I5 z1 S3 v, ]if ~isempty(handles.Result)7 _! O4 F% z) q* I; O6 `! t
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
# |; j0 f8 z6 o3 x0 [ axes(handles.axes2); imshow(handles.Result.BwFilter); title('二值图像滤波');" y: y* J2 A; X% M) p
axes(handles.axes3); imshow(handles.Result.CrackRec); title('裂缝识别');
~5 d V, q) t8 Q; e axes(handles.axes4); imshow(handles.Result.CrackJudge); title('裂缝判断');
2 j3 S3 h7 ?; ^, K: t4 zend; C O- t2 }8 p; Y$ ~: l1 Z
8 \4 p" z" |) b, B; O; _2 p% --- Executes on button press in pushbuttonCrackLoc.5 C% X9 o, { u0 |# ]1 m
function pushbuttonCrackLoc_Callback(hObject, eventdata, handles)9 F, o8 V4 t h2 V
% hObject handle to pushbuttonCrackLoc (see GCBO)
( R0 k* [+ d! B- T% eventdata reserved - to be defined in a future version of MATLAB0 b! r; y0 A' [ d+ [
% handles structure with handles and user data (see GUIDATA)' n9 p3 i! \* _8 O* j+ H6 H- [0 D
if ~isempty(handles.Result)8 t" J9 e5 k. X0 v2 h; b2 N2 @
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
. V$ y+ x( H9 j: A4 i9 k1 K axes(handles.axes2); imshow(handles.Result.CrackJudge); title('裂缝图像');: g! |6 Q! Y9 l; l1 K* |( @+ b
axes(handles.axes3); imshow(handles.Result.CrackJudge); title(handles.Result.str);4 f7 Z7 s' e: R8 ^
axes(handles.axes4); imshow(handles.Result.CrackJudge); title('裂缝标记图像');- O2 Z; j2 N0 _8 N
hold on;
, b5 ?; X7 B5 o' n. N# o3 A! } rectangle('Position', handles.Result.rect, 'EdgeColor', 'g', 'LineWidth', 2);
8 M0 I7 u# r9 c4 y2 K6 R hold off;: F9 R' F2 R! R: W9 M5 ~
end$ I7 ^# I6 h% u2 e2 ~
V1 F( Q) F6 R) e1 F0 k1 H
% --- Executes on button press in pushbuttonProject.2 u# q. N4 X9 s% T) j
function pushbuttonProject_Callback(hObject, eventdata, handles)
) g2 W7 U# J/ G, g) c% hObject handle to pushbuttonProject (see GCBO)
/ P" w; r) }) j, u% eventdata reserved - to be defined in a future version of MATLAB
% \4 q1 _* {2 a5 |% handles structure with handles and user data (see GUIDATA)
, H; Y A( s+ z1 R4 j Cif ~isempty(handles.Result)
+ c' P. w+ T' D( q0 D8 x( @ axes(handles.axes1); imshow(handles.Result.Image); title('原图像');" }1 \: C1 Z% F6 p
axes(handles.axes2); imshow(handles.Result.CrackJudge); title('裂缝图像');
9 E! i& A' `' m' M, J- X W& H axes(handles.axes3); plot(1:size(handles.Result.Image, 1), handles.Result.Projectr);$ b7 \3 K+ p4 j! d* H5 r
title('行投影');9 v0 ~# E" ?: y& \
axes(handles.axes4); plot(1:size(handles.Result.Image, 2), handles.Result.Projectc);, H+ ^! R4 U+ U! [8 ^3 i0 s5 g
title('列投影');
5 j% @, o4 t0 P* }$ Hend
3 E* i l* a9 R& ?
. Z6 E1 Z2 R- q% i j2 [
# R* x- {! l5 a% h% --- Executes on button press in pushbuttonClose.
4 C$ [9 P1 J$ v# p. y: g: }function pushbuttonClose_Callback(hObject, eventdata, handles)
4 j$ t/ m' I8 l& g) f ?6 q7 q% hObject handle to pushbuttonClose (see GCBO)
# z9 {; T+ P0 O* i% eventdata reserved - to be defined in a future version of MATLAB& g+ _ Q! Q# P* L0 H
% handles structure with handles and user data (see GUIDATA)
* T# D% J! n8 |2 Xchoice = questdlg('确定退出?', ...
, Z; t; n4 r( s3 q3 X O5 ` '退出', ...
, h* A) f! E- h. ?2 z# U '是','否','否');
( m2 p! Y1 h0 xswitch choice0 c! u+ r* n$ |1 c
case '是'4 w! e2 y; Q- ` b
close;
# k4 v5 l( B7 Q/ o7 g- } otherwise
- r2 n8 X, s' o7 w% |- `) I" j$ v return;
0 R- _3 ]; `* Z% I5 ]$ s' tend, N" b0 n! B2 w! A* w( T8 b
+ w; N: r- `, ?+ J
3 d" p+ f7 p4 s6 e2 i) [' H& l0 W
6 I7 ~( w8 U' [6 S# p7 j% --- Executes on button press in pushbuttonSaveResult.; z+ n+ g7 Z0 _( ?/ R. M
function pushbuttonSaveResult_Callback(hObject, eventdata, handles)2 J5 L7 W; K. W8 P" O0 }4 x
% hObject handle to pushbuttonSaveResult (see GCBO)
s8 t( D8 |: z9 m6 m% y5 O% eventdata reserved - to be defined in a future version of MATLAB1 U% R8 `1 Q. d. n2 s( D
% handles structure with handles and user data (see GUIDATA); l: M2 o0 K% W) Z
try
7 o! [$ o" M* H/ I3 v if ~isempty(handles.File)( w, p, ?( j8 v& c8 P6 w
raw = [];% F2 M1 t- `: t+ e) O
xlsfile = fullfile(pwd, 'Result/result.xls');
# U3 C7 [' x+ C. F9 p: z if exist(xlsfile, 'file'), @7 M; y, D- L' x! D
[num, txt, raw] = xlsread(xlsfile);
( W$ ]. t* ^0 Q8 w. H end: N9 s8 l6 U6 R% o
/ W3 M/ Z3 y' s# N' h# Q/ Z) ~; T F = [];
2 ?0 D1 e. q; b7 Z F{1, 1} = '文件名';
% v5 c! v. Q/ Z3 g- u8 P$ F; k+ N3 ^8 ` F{1, 2} = '阈值信息';( q7 j+ f" l4 ^( Z/ C. P9 S
F{1, 3} = '面积信息';
5 D0 a& |" P. Q F{1, 4} = '长度信息';
2 l: o2 |7 q$ G7 |/ S! D% ~ F{1, 5} = '最大宽度信息';& b; {2 h+ v: p3 ]$ l
F{1, 6} = '最小宽度信息';7 A7 J: Q' @; Q0 E4 Z! A
F{1, 7} = '形状信息';
# o7 J: P- @1 W7 ] 5 q) e" s2 \4 V1 {5 l, J
F{2, 1} = handles.File;
* R+ s1 v2 y( q F{2, 2} = handles.Result.BwTh;9 t& q" l6 [, L: E& r
F{2, 3} = handles.Result.BwArea;3 n" k. V0 O7 T1 S: k* R
F{2, 4} = handles.Result.BwLength;
% j; m3 V% Q2 Q7 t. J$ } F{2, 5} = handles.Result.BwWidthMax;
& h! {6 _" ?7 g7 A, c! J( v F{2, 6} = max(handles.Result.BwWidthMin,0.01);9 j* E" ?) H! r w* M
F{2, 7} = handles.Result.str;
, H) X& [: Q& \# ?! n3 W# U n: i, S / S8 T2 d# u3 \ K+ q
F = [raw; F];
% x' T% p3 R+ p7 Q xlswrite(xlsfile, F);
" d" |7 q) t5 \! L% X1 W
7 i: J- J5 x3 r+ D9 C msgbox('保存结果成功!', '信息提示框');
8 R7 t; U8 p$ V. j/ T: ~" H end
! j, \; I6 a: P8 v1 T5 tcatch' Z4 N8 w2 h* ]& @8 G1 A8 r" K( ~
msgbox('保存结果失败,请检查程序!', '信息提示框');
5 `' E. }% h- g& Cend, v4 `; n. O/ J2 V" i4 ^
, A% Q5 p+ K" M: X7 j$ k4 _$ Y
8 x. R! e& ]6 ]% J% --- Executes on button press in pushbuttonBridge.+ M* m, o6 p! f# |, v9 M
function pushbuttonBridge_Callback(hObject, eventdata, handles)+ ~" [0 i( i/ h: N$ A0 k
% hObject handle to pushbuttonBridge (see GCBO)
2 v/ p5 j' W4 O/ l, ~% eventdata reserved - to be defined in a future version of MATLAB
3 d1 P9 A! x2 M) u+ M% handles structure with handles and user data (see GUIDATA)
3 k0 |5 Q0 u0 Gif ~isempty(handles.Result)# s/ p6 @' h2 e N
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
, A* a+ f3 d( m, i! k7 { axes(handles.axes2); imshow(handles.Result.BwFilter); title('二值图像滤波');
0 e3 G' M, |0 z4 k* k+ r4 ` axes(handles.axes3); imshow(handles.Result.CrackJudge); title('裂缝判断');
/ f/ r' _2 S# {% C. \ axes(handles.axes4); imshow(handles.Result.CrackBridge); title('裂缝拼接');
2 ^4 P2 Y) w% Bend
% K2 R- U [. X
! k2 d- ?, {) x) K7 `
; A+ _9 J) L- E* i8 I% --- Executes on button press in pushbuttonSaveImage.
* X$ P: g3 [8 z+ E3 A* `function pushbuttonSaveImage_Callback(hObject, eventdata, handles)# e K! e0 W. G) m7 Z+ ~
% hObject handle to pushbuttonSaveImage (see GCBO)
, |; _# M% t5 j- l6 X5 T: D% eventdata reserved - to be defined in a future version of MATLAB
+ {/ X& ^2 t: N! k% handles structure with handles and user data (see GUIDATA)0 V2 T! |9 c: A) T0 J* n( w
[filename, pathname] = uiputfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...- t/ t& R2 @5 b& W* |$ e
'*.*','All Files' },'Save Image',...
6 f, a6 e7 g$ v, e) j fullfile(pwd, 'Result/result.png'));
0 c4 z/ Y1 c' Iif ~isequal(filename, 0)
$ _2 y; ^; ]2 H2 ` [# E imwrite(handles.Result.BwEnd, fullfile(pathname, filename));
5 z3 F0 Y& k, m8 Q6 N9 }* o' L l msgbox('保存图像成功!', '信息提示框');
1 S! Q% ?: T9 A5 Cend
8 T3 k2 W3 o9 ~; J% o- c" q3 S& N
: z3 {: |+ |3 F$ O: D
; w! L3 R9 N# r h) x r" C7 |% --- Executes on button press in pushbuttonDiplay.2 W" |9 Z4 o5 @* {
function pushbuttonDiplay_Callback(hObject, eventdata, handles)4 y' e8 A& R0 P8 l) R+ i
% hObject handle to pushbuttonDiplay (see GCBO)& E$ h% S7 E0 d: Y; C+ A7 S: o! W
% eventdata reserved - to be defined in a future version of MATLAB
7 c( V9 | R3 e+ k! i% J2 a% handles structure with handles and user data (see GUIDATA)
Q; V r. ~* y3 jif ~isempty(handles.File), N% w. G( T) r
F = [];" \9 _2 q+ e2 |1 K: `8 p
F{1} = sprintf('文件名:%s', handles.File);
1 @" X( p3 K" p* U. B F{2} = sprintf('阈值信息%.2f', handles.Result.BwTh);* ?7 F! o; ]2 r1 s% X v. X2 S9 ^
F{3} = sprintf('面积信息%.2f', handles.Result.BwArea);
% I+ W/ Q0 L8 h5 T F{4} = sprintf('长度信息%.2f', handles.Result.BwLength);5 ~. m* @% M" F# d* u0 Y
F{5} = sprintf('最大宽度信息%.2f', handles.Result.BwWidthMax);
* m; p: v& \& d) b F{6} = sprintf('最小宽度信息%.2f', max(handles.Result.BwWidthMin,0.01));
* C6 E( Q& U( K; Y( D2 z F{7} = sprintf('形状信息%s', handles.Result.str);1 y$ U3 q8 @' z& H z
listdlg('PromptString', '参数显示:',...
- Z/ _, M8 n W" }1 h( j" J* }+ _9 t 'Name', '参数信息', .... i5 V2 x2 {; p/ ^0 S. Y
'ListSize', [300, 150], ...
. u; y( D; D" \0 J$ \+ V3 h. H# f# M 'SelectionMode','single',...
' @6 ]- X" P1 Q4 _, P8 U 'ListString', F);8 |; R: \# G& S2 r5 Q3 K
end9 }5 x# }; o0 v6 W0 U9 V* ?
/ V: m, B/ f" F2 W9 s J
三、运行结果; z2 ]: v$ V3 F! X X- p
+ `9 h* Q0 F5 s( c9 P+ u, ]7 @
- [, i5 |, \2 J2 X% F
3 b- n s, a0 A6 O5 B; [2 b4 [+ l
u& Q; h+ H8 N
3 B' O7 O% ]1 h: V5 M0 J" O |
|