|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
7 f Z' ^0 x% t. y9 L7 X& U0 [6 n( T一、简介2 O, ~$ ~) ^; `( \( \3 U
高速公路路面病害养护和管理的重要部分就是路面裂缝的检测。近年来,路面裂缝自动检测技术已得到了广泛应用,而由于路面裂缝图像的复杂性,检测算法直接影响着检测结果的精确度。因此,本文将重点放在路面裂缝病害的检测上,为了提高检测的精度,分别从裂缝图像的去噪、图像的增强、图像的分割以及检测后路面裂缝图像的特征提取方面进行深入研究。 在路面裂缝图像中,由于裂缝信息与背景对比度偏低,难以将裂缝直接检测到。对于图像的预处理,首先对图像进行灰度校正,再对校正之后的图像滤波,本文提出了一种改进的中值滤波方法,对图像进行去噪,之后用基于模糊理论的图像增强原理对图像做进一步增强,有效提高了路面裂缝图像的对比度。 针对路面裂缝图像分割,本文分别用了阈值分割和基于形态学多尺度的思想,对于形状规则的裂缝采用的是阈值分割,对于裂缝形状不规则的图像,本文设计了一种多结构元素的抗噪型边缘检测算子,且依据不同形状的结构元素对裂缝边缘填充的几率不同,确定了自适应权重,使得算子检测到了各种类型的裂缝边缘,有效地提高了检测的精度。 对于经过分割后的路面裂缝图像中存在噪声和裂缝断裂的问题,本文对于断裂较窄的图像用形态学中的闭运算和开运算去处理,对于断裂较宽的图像,提出了一种基于生长的断裂裂缝块的连接方法。提高了连接的效率和准确率,使整个检测结果清晰完整。最终,从识别结果图中提取裂缝信息。根据得到的识别结果图,设定一系列判定条件,提取出裂缝的连通域,对裂缝的类型进行判断,最后计算出网状裂缝的面积及线性裂缝的长宽信息。/ E% J2 Y3 L3 N3 t3 A- w& O4 W
" U6 ^9 c9 d1 Z$ r二、源代码
# W0 w2 v+ j% P% z& V. Xfunction varargout = Gui_Main(varargin)( a h. {( K9 J6 \# ]1 d6 v
% GUI_MAIN M-file for Gui_Main.fig
6 l" f6 U. W% j. t2 d* F2 @% GUI_MAIN, by itself, creates a new GUI_MAIN or raises the existing
2 w f3 ?% M" U* y! K% singleton*.* m! L: x* R0 j: y2 h
%
% G, S5 t3 n9 S4 x0 f2 C% H = GUI_MAIN returns the handle to a new GUI_MAIN or the handle to
& [0 x2 h* @/ ]5 ^, R7 c0 e! b& E, u% the existing singleton*.
! @4 I p% T x%
+ I$ A6 l" H. b0 \- V" u0 u! O% GUI_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
) |& q- O" h$ |4 [5 v* f% function named CALLBACK in GUI_MAIN.M with the given input arguments.$ U6 ~9 w0 B3 f2 B
%; F. f7 \$ m( ~
% GUI_MAIN('Property','Value',...) creates a new GUI_MAIN or raises the
, o0 _+ n; j" h; K- Q1 r% existing singleton*. Starting from the left, property value pairs are
" G& z; {, V/ u2 }% applied to the GUI before Gui_Main_OpeningFcn gets called. An. r; K: j, D: U, `2 R4 ]/ q v, \
% unrecognized property name or invalid value makes property application
) A8 W; w9 N U% stop. All inputs are passed to Gui_Main_OpeningFcn via varargin.5 m- m P9 U0 N2 A# F
%
* O$ z5 C; h/ q% c% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one, n& X( a8 G2 v- K" {
% instance to run (singleton)".; ]" j8 i7 @8 F: ` f; G
%
, v7 B+ Y9 ]7 N6 C; U% See also: GUIDE, GUIDATA, GUIHANDLES
1 B% \0 U* X2 A0 c" m
1 R) H( _- [' P5 _8 j/ s% Edit the above text to modify the response to help Gui_Main
7 M+ I: _- B- [1 e0 U9 B& J7 I% U
3 q3 z; T4 T8 Y1 r5 D) }- @% Last Modified by GUIDE v2.5 29-Mar-2011 22:28:58/ M+ P& s$ X6 P. S7 H
+ L7 N2 a# |/ j3 a# l/ u* w9 H
% Begin initialization code - DO NOT EDIT
# p" @) F, G( N- N" vgui_Singleton = 1;
- [ O, I! {- n+ e9 sgui_State = struct('gui_Name', mfilename, ...
$ q0 @/ q) _9 m( z5 D3 d 'gui_Singleton', gui_Singleton, ...$ H7 ~; c9 V/ O
'gui_OpeningFcn', @Gui_Main_OpeningFcn, ...( s6 P/ x4 }# \0 ?9 h
'gui_OutputFcn', @Gui_Main_OutputFcn, ...
2 s! w( f: _1 }( x2 Y8 y) A1 H 'gui_LayoutFcn', [] , ...
5 H1 F; U: w# P* L! o% F 'gui_Callback', []);
+ ?) D* f0 M7 a% k; W' Qif nargin && ischar(varargin{1}). ?; H. e0 F1 ~. Z
gui_State.gui_Callback = str2func(varargin{1});7 s( f' u" B. G8 R2 {* }
end5 k; T6 J' F$ ?1 o
' R+ d+ ]! X4 |" G$ z" ^7 O9 y# F& |if nargout
5 W( ~& O5 s2 }- v+ b [varargout{1:nargout}] = gui_maiNFCn(gui_State, varargin{:});/ G; J. K6 t1 o; c) S0 w I
else3 V/ ~+ k' {; K: Z3 e4 O+ `
gui_mainfcn(gui_State, varargin{:});* `' Y$ t, s/ m- D4 b
end, Z4 t% @( J+ y3 |
% End initialization code - DO NOT EDIT
1 T# ~% e* `3 h: s) [7 k/ _, Z1 l " e! v. j4 F$ {' X* j9 b( D
B; K7 q7 R+ q8 {) m: Q% --- Executes just before Gui_Main is made visible.
; z& \# U! i9 D( g( d+ c: Y* V9 dfunction Gui_Main_OpeningFcn(hObject, eventdata, handles, varargin)1 h* h; g4 _( d( Y( V" z
% This function has no output args, see OutputFcn.
) p: B" O2 C0 _# c7 p% hObject handle to figure
, U# b: [& h7 c. f% eventdata reserved - to be defined in a future version of MATLAB
7 M C, b& @: `% handles structure with handles and user data (see GUIDATA)
4 p8 F! ?9 S+ Y) V6 s/ _) X% varargin command line arguments to Gui_Main (see VARARGIN)
0 n. v# k6 h d/ K 5 X9 S( n' {" L$ k
% Choose default command line output for Gui_Main) A) l* {2 j: |1 k6 ^( W# ]1 T
handles.output = hObject;( s z# v) h1 B3 o. w" |
handles.Result = [];9 P/ h2 u/ e; ^$ `+ z6 M
handles.File = [];
; |% w) J$ z9 A* Z! o% Update handles structure2 x* g( V+ U3 t, p A8 _
guidata(hObject, handles);" _! n: ^, v1 l% F
clc; warning off all;
/ `; a# x3 L1 b' O7 I! \$ j- |InitAxes(handles);
) V1 R, c0 m! ^9 I: z ! \) ~; [3 w" d% v3 o" z7 ~; z( b/ z
% UIWAIT makes Gui_Main wait for user response (see UIRESUME)9 X9 q7 r' o4 U3 i
% uiwait(handles.figure1);
2 n) R5 }: S8 D% Q0 Z0 }; g
. B& H" \% W0 e! S5 U3 y( J' E" T7 w ) k* z7 v' b/ Q% [1 m4 _2 a
% --- Outputs from this function are returned to the command line.
7 ~2 d) O% {& w0 U2 Ifunction varargout = Gui_Main_OutputFcn(hObject, eventdata, handles)
, P% C& O+ H( S# i i1 P% varargout cell array for returning output args (see VARARGOUT);$ F( w( L8 F9 B8 [3 q2 k
% hObject handle to figure( x) a5 U; }+ a1 D9 E. b
% eventdata reserved - to be defined in a future version of MATLAB
! e, x [, `8 ]1 V- v7 |7 D% handles structure with handles and user data (see GUIDATA)5 y! z$ l/ o0 _; F. {. z
( a% p8 z- y3 i1 ^7 k* l
% Get default command line output from handles structure; |1 o/ | r4 C. Q; {+ ]* r
varargout{1} = handles.output;' H' C2 r6 o: A& v( l6 d" s
! J D& G8 X. ?7 n; f1 b, T* {, | , f! k; M* O2 {* r. R8 l
% --- Executes on button press in pushbuttonOpenFile.6 n& e. u3 U- d
function pushbuttonOpenFile_Callback(hObject, eventdata, handles)& V$ ^% Y( \$ b! O. @, `& z1 D
% hObject handle to pushbuttonOpenFile (see GCBO)
8 N7 {8 Z. Q( p# ^1 B; ]% eventdata reserved - to be defined in a future version of MATLAB
- u W7 p9 Y, ~! [# X% handles structure with handles and user data (see GUIDATA)/ P4 o+ X2 V9 n5 ~! P6 X! |8 g' \. ]
[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
' e% D! o1 Y" ~2 B9 I '*.*','All Files' },'载入图像',...
- A( o, g; |; S) K fullfile(pwd, 'images'));6 j4 _, P) z' @2 n. o
if isequal(filename, 0) || isequal(pathname, 0)0 y7 a! u, {8 r+ l/ \9 D, N
return;
% D$ C; j+ _ P# O: d4 J/ l. yend
6 c( w7 E! ?& B" ]$ H! ~I = imread(fullfile(pathname, filename));2 z6 D4 q* K+ L6 K& g+ _* g. ^8 s
Result = Process_Main(I);
I; }* L3 v7 O, Lhandles.File = fullfile(pathname, filename);
) s/ V/ n, F% }handles.Result = Result;
# o$ r) c. m' A- s6 j. n* j" ]guidata(hObject, handles);
5 Q8 ]* g* q6 j+ w1 s* A; m6 U3 ~InitAxes(handles)
! y! D( e# O/ maxes(handles.axes1); imshow(handles.Result.Image); title('原图像');
" _ Q; x& G. m0 I6 k* _. y , R1 ]* j# O h- W5 {8 X
8 p% f. @4 \8 D" v% z: Q2 E: A
% --- Executes on button press in pushbuttonHisteq.
" V' U E" C0 s: ^+ x/ I# H6 ofunction pushbuttonHisteq_Callback(hObject, eventdata, handles)" b6 G7 c2 j! y; M# Z! P
% hObject handle to pushbuttonHisteq (see GCBO)$ ?% A5 Y- `7 d9 A- v4 Q! t3 y
% eventdata reserved - to be defined in a future version of MATLAB
* F; r) b# K7 A, | T6 q% handles structure with handles and user data (see GUIDATA)
) x6 ~$ H3 Y1 G, G8 T0 Qif ~isempty(handles.Result)& p& {0 ]& A; h) J$ J" L2 O( q
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
) s3 h/ f8 P) ~7 U/ ? axes(handles.axes2); imshow(handles.Result.hist); title('直方图均衡化图像');' S1 A7 B( C& [! Q; l) i. E7 u% ~7 `
end
# e/ w; w# @' ]) A # ] ~$ p- q/ c: ~
& l% |! J( M8 r! W
2 q( T! _% t3 Z+ S% --- Executes on button press in pushbuttonMedfilt.
$ ~) l/ h; L0 Y8 z1 h/ U2 \% tfunction pushbuttonMedfilt_Callback(hObject, eventdata, handles)8 N" M. f5 [$ c* D0 j. [& B
% hObject handle to pushbuttonMedfilt (see GCBO)
! j3 w; e; I" G% eventdata reserved - to be defined in a future version of MATLAB5 d% Z% s& Y8 z* s0 y; j
% handles structure with handles and user data (see GUIDATA), d+ _% M' {/ m! Z
if ~isempty(handles.Result)) R0 A; Z3 n) `% c' G( r
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');7 Q. p) [3 C M! E
axes(handles.axes2); imshow(handles.Result.Medfilt); title('中值滤波图像');* }9 w. R; q! b
end
) M# v& u+ O+ H4 J9 L" Q3 D' J4 r ( F# u; f( N0 s& R- J; p1 C
- g* j1 k6 k1 _: ~1 I: C5 O) h% --- Executes on button press in pushbuttonBw.9 s4 w: w; R6 M7 Y
function pushbuttonBw_Callback(hObject, eventdata, handles)
; D$ }5 @" L! N! }! h% hObject handle to pushbuttonBw (see GCBO)
5 `2 M, m/ m2 M2 u* f I( m% eventdata reserved - to be defined in a future version of MATLAB5 q1 @& |5 T5 S# c
% handles structure with handles and user data (see GUIDATA)$ A* y* N4 A& a; v
if ~isempty(handles.Result)
; {5 l( U: F! y) s! k; o- _ axes(handles.axes1); imshow(handles.Result.Image); title('原图像');$ D' |3 b6 E7 s! [9 _' j3 T
axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');
' R# [* T3 q+ U3 ]8 y+ kend, K" P6 Q7 F1 l+ i0 E& w
; I5 W* o K- o0 G
% --- Executes on button press in pushbuttonEnance.
+ v9 c+ ~) r/ F0 }function pushbuttonEnance_Callback(hObject, eventdata, handles)
" D$ p. m' \1 A' U% hObject handle to pushbuttonEnance (see GCBO)
) F2 V5 W2 _; H; j% eventdata reserved - to be defined in a future version of MATLAB3 s! ?( X2 Q# ?. M: R7 ?
% handles structure with handles and user data (see GUIDATA)0 R M$ @- d) {3 X0 t0 i0 v
if ~isempty(handles.Result)& ?: a& Y& A3 [' _
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');! K/ x; m4 n& \' {
axes(handles.axes2); imshow(handles.Result.Enance); title('增强图像');
7 X5 I( r3 _/ [, Vend
: p- n! B& ~# s( A) i * T4 Z( H: g7 ?4 D) t, n
% --- Executes on button press in pushbuttonBwfilter.+ S7 Z7 `+ b8 ^8 r7 {7 y
function pushbuttonBwfilter_Callback(hObject, eventdata, handles)
* O. s4 [; i! r( y$ Z: B! @% hObject handle to pushbuttonBwfilter (see GCBO)
f( O5 g' |; n2 ^4 V% eventdata reserved - to be defined in a future version of MATLAB, R5 x0 ]" \# |# J
% handles structure with handles and user data (see GUIDATA)
1 s1 V4 ^+ f$ V! d/ N% zif ~isempty(handles.Result)
- r, Z- ~) r4 y- Y$ M2 | axes(handles.axes1); imshow(handles.Result.Image); title('原图像');" o) v# c6 z( E- B7 _, s- Q( s7 y
axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');, o* h1 e/ u6 q+ C. d$ l, P' p
axes(handles.axes3); imshow(handles.Result.BwFilter); title('二值图像滤波');
- H* U i b) ~' S0 Mend& d4 A) b- N1 \, S$ U
k$ S, i9 b" N" Q! w6 h# w% --- Executes on button press in pushbuttonCrackRec.
6 s/ ~5 j: f4 A$ B) y. G$ wfunction pushbuttonCrackRec_Callback(hObject, eventdata, handles), d% i: h0 `" |" X* e$ m4 [
% hObject handle to pushbuttonCrackRec (see GCBO)0 L; [& a- `/ M. ^% k8 L
% eventdata reserved - to be defined in a future version of MATLAB0 o8 M- F: b0 ]2 ?, [8 z- d5 C$ [
% handles structure with handles and user data (see GUIDATA); |0 H$ \6 _/ i# p9 A: h+ g+ A
if ~isempty(handles.Result)$ {$ ^, u" w& l. \( O
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
: X) R' g+ ]6 D axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');
& {7 g! w5 M; a! i7 d# u# { axes(handles.axes3); imshow(handles.Result.BwFilter); title('二值图像滤波');. \/ }+ k7 p7 [+ u2 z* a
axes(handles.axes4); imshow(handles.Result.CrackRec); title('裂缝识别');) i+ f% i& D2 Y: n3 U# C
end
3 R, M2 X3 u3 o& A$ I 9 L6 e0 X: L, i3 d
0 T# Y9 ]/ c k# ~$ h% --- Executes on button press in pushbuttonCrackJudge.& ^0 d' F* O) `( o$ f8 F- c1 I
function pushbuttonCrackJudge_Callback(hObject, eventdata, handles)4 \& ?# ?9 H" R. d7 I% C c8 R' o: h
% hObject handle to pushbuttonCrackJudge (see GCBO)2 r" N% r+ r& f$ w8 h
% eventdata reserved - to be defined in a future version of MATLAB7 w: p$ m- G& E' Z ?6 L! F
% handles structure with handles and user data (see GUIDATA)$ a w0 s- H, ~ {
if ~isempty(handles.Result); H* Y F0 s% W7 m4 M2 m
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');: \& Z% A6 h0 \) r' H- [+ `$ r- e
axes(handles.axes2); imshow(handles.Result.BwFilter); title('二值图像滤波');' { t' A3 n' u( m
axes(handles.axes3); imshow(handles.Result.CrackRec); title('裂缝识别');9 W# H# k$ U3 D. l
axes(handles.axes4); imshow(handles.Result.CrackJudge); title('裂缝判断');
5 ], s; I8 u+ R6 g2 N uend- j; a* z* q( z5 M1 n; c
2 O! ~; U+ X& f4 l1 H% f! d( W8 ~
% --- Executes on button press in pushbuttonCrackLoc.
) ~4 w P4 b# ]5 e$ r, e% R* tfunction pushbuttonCrackLoc_Callback(hObject, eventdata, handles)
4 h: E4 O5 [! g3 N' H/ H- X% hObject handle to pushbuttonCrackLoc (see GCBO)' j' W4 m0 H: q2 B
% eventdata reserved - to be defined in a future version of MATLAB
0 y9 I5 f7 g( ^ s, p2 f% handles structure with handles and user data (see GUIDATA)
" X+ b! g$ B& q; T& tif ~isempty(handles.Result)
) E' X7 i% I0 T# i0 \ axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
# z- Z% m" w, c, x9 m1 S/ L6 Y/ _ axes(handles.axes2); imshow(handles.Result.CrackJudge); title('裂缝图像');
% B i1 ?% A f9 W! V axes(handles.axes3); imshow(handles.Result.CrackJudge); title(handles.Result.str);* h& p7 O4 ^; {$ l" `2 X
axes(handles.axes4); imshow(handles.Result.CrackJudge); title('裂缝标记图像');; E" c2 I4 u6 y7 `7 S" y
hold on;. y! V6 f2 b+ h5 t9 a& c
rectangle('Position', handles.Result.rect, 'EdgeColor', 'g', 'LineWidth', 2);
( T# v) @( m3 I1 m9 ?: W" W hold off;
) ^7 j( {- f% q7 @- Z2 y( _; pend! t7 X$ W# A% f1 D4 B3 O1 l
! F$ J& @( B' ~' s% --- Executes on button press in pushbuttonProject.
6 t3 J) @5 H) N- r& g( O' F, v! Kfunction pushbuttonProject_Callback(hObject, eventdata, handles)( O8 S, P, G: e4 K4 _ M3 v) M
% hObject handle to pushbuttonProject (see GCBO)
; n" w/ V! |! d3 H' l% eventdata reserved - to be defined in a future version of MATLAB
, H4 j( C2 y. T1 ?. F% handles structure with handles and user data (see GUIDATA)5 C* i: r' @4 M) M
if ~isempty(handles.Result): H2 X+ o4 L; T4 M2 h
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
: j( q# N- r* i* D/ H, |' E axes(handles.axes2); imshow(handles.Result.CrackJudge); title('裂缝图像');7 c; s: N" Z9 V
axes(handles.axes3); plot(1:size(handles.Result.Image, 1), handles.Result.Projectr);6 M/ F& P+ K# {
title('行投影');
4 ^9 Z+ m1 J9 ]8 z) o axes(handles.axes4); plot(1:size(handles.Result.Image, 2), handles.Result.Projectc);. A( Q& y2 L5 q6 H& ` H
title('列投影');
6 C4 i; m3 x* o' gend* c& y1 L+ N7 h% H1 M
' ^$ f+ n" P8 {8 O+ ^4 N* |, a O
3 p1 G+ Y% n$ d0 x9 I9 o% --- Executes on button press in pushbuttonClose.9 `1 N/ r$ m9 [
function pushbuttonClose_Callback(hObject, eventdata, handles) E: u z& F3 n0 `. O: ^
% hObject handle to pushbuttonClose (see GCBO)
( W) X( s5 i* t# `' a% eventdata reserved - to be defined in a future version of MATLAB
+ s8 Y w3 y8 Y+ w* J( i h, i% handles structure with handles and user data (see GUIDATA)9 H1 k: W+ U$ V! d( ^6 h
choice = questdlg('确定退出?', ...% K. |. E0 L6 ?
'退出', ...* b1 G+ R [) s$ [* H. }# T
'是','否','否');
, N1 N6 Q, y0 R, iswitch choice+ W ?, V1 w( e
case '是'- e4 d F, h3 Y/ Z- |! _( c
close;
7 v1 H& X5 E' ~! K# P9 {4 C otherwise- T" v& z& |$ M1 S d6 X4 }; \- F
return;! N9 l; F: ?" |) v$ i( x
end5 t& {2 E* J8 d3 Y% V
" R% c5 M7 d$ o/ u7 \- V+ @2 {# O; C
$ p& K9 y) V& e1 r* G
. i# Y4 v7 C3 m% i" s- Y% --- Executes on button press in pushbuttonSaveResult.
, t' i! C+ {/ j E4 L, gfunction pushbuttonSaveResult_Callback(hObject, eventdata, handles)
$ C+ M" z# v5 Q0 d, [4 p% hObject handle to pushbuttonSaveResult (see GCBO)
. N, R! k) b* v) E: C% eventdata reserved - to be defined in a future version of MATLAB
. G( D# H0 s+ R% H- |2 ]* ~1 N b% handles structure with handles and user data (see GUIDATA)! E. D4 I Q+ X3 n. L; T2 ]
try
& s, A! T& [! v2 y) m" s if ~isempty(handles.File)/ z6 M+ T5 _: G& d
raw = [];7 U) \" V5 Z1 i
xlsfile = fullfile(pwd, 'Result/result.xls');
4 R' v. ~6 j/ c% e1 s5 X if exist(xlsfile, 'file')- e y; Q' S1 K7 |) B
[num, txt, raw] = xlsread(xlsfile);
- r) d" D5 n/ q9 l& T/ Q4 s3 s end
" _% C7 T- d* f1 c! t / R0 x3 a0 l- k" C
F = [];
% e/ c9 r" }; ^; Z, m F{1, 1} = '文件名';0 O0 n: t [2 m, Z0 ~% ~- Q( c
F{1, 2} = '阈值信息';
! L5 R! V" e" }7 c F{1, 3} = '面积信息';" x# O: f5 `6 Y2 i* d! a
F{1, 4} = '长度信息';
9 h) q0 i0 y5 r+ |3 p8 p: e F{1, 5} = '最大宽度信息';) s; h" e9 k* b0 g8 f8 Y
F{1, 6} = '最小宽度信息';
# |6 P z9 Y7 W F{1, 7} = '形状信息';5 s, y- N, R! f N
% k4 @% `% M& ~' s
F{2, 1} = handles.File;( T% r% j9 ~( V1 w7 o+ [
F{2, 2} = handles.Result.BwTh;# x# p, A( a3 N- F
F{2, 3} = handles.Result.BwArea;
" [( L" L, S# b+ G6 a: n9 {6 ? F{2, 4} = handles.Result.BwLength; B% N e% ~: k, K+ B
F{2, 5} = handles.Result.BwWidthMax;
% e3 u0 g6 z# b+ G1 T) Q9 I F{2, 6} = max(handles.Result.BwWidthMin,0.01);1 b2 F M. ]+ h; N9 a" f
F{2, 7} = handles.Result.str;% n) C A: L4 N; d( y
' C! T) F3 s4 R
F = [raw; F];: s2 G! T/ s1 S. i* N9 k+ s8 c+ R
xlswrite(xlsfile, F);
3 e+ R9 C$ i# T- L; f- |- B# w2 ^
x" P# H& @; [! J& [2 z. u2 n0 V msgbox('保存结果成功!', '信息提示框');
, V$ C! B* }" Y end
/ R1 O( U4 k/ Y0 q. M: f+ Rcatch8 E, H; U9 U) @5 ~8 V$ a/ D
msgbox('保存结果失败,请检查程序!', '信息提示框');
# C1 R+ f' O8 bend
9 ~; @9 D& K" L. |7 E4 t( n4 m: _
& Z, M4 l* b6 @8 k' o. n5 a$ e " M! G6 Y$ q! @1 P" U' Z% K. D8 T8 n; C
% --- Executes on button press in pushbuttonBridge.
) \5 \' @/ d( {1 Afunction pushbuttonBridge_Callback(hObject, eventdata, handles)8 l$ i: v2 m! l& E' W: u* `- \
% hObject handle to pushbuttonBridge (see GCBO)( {+ C3 C( A% R7 X3 P( ]. f% P& ` i
% eventdata reserved - to be defined in a future version of MATLAB$ n( H# o* U p. y( W( `
% handles structure with handles and user data (see GUIDATA)
! Q1 o$ b& F6 U; Bif ~isempty(handles.Result)
1 Y6 v1 a( ~) S" R; r' r2 C+ S, ] axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
) U. y+ M. j0 R axes(handles.axes2); imshow(handles.Result.BwFilter); title('二值图像滤波');! \* S% Y7 a; [ b. C r
axes(handles.axes3); imshow(handles.Result.CrackJudge); title('裂缝判断');
5 e4 Q: n: X& K8 J6 m axes(handles.axes4); imshow(handles.Result.CrackBridge); title('裂缝拼接');( v5 y/ m( c( Q2 H
end
- I7 ~: S6 v/ R' R" ? 9 J, x2 {! u3 L6 b8 Z, a2 g
& R1 v7 ^5 U7 Z R& b, {& Q. Z% --- Executes on button press in pushbuttonSaveImage.
6 n9 j2 j* i" l) Y4 ]function pushbuttonSaveImage_Callback(hObject, eventdata, handles)0 E/ O5 F2 O# H7 K4 Q* _
% hObject handle to pushbuttonSaveImage (see GCBO): \0 \" a R" ], H; N( b
% eventdata reserved - to be defined in a future version of MATLAB# w( A& Z# s( }2 A
% handles structure with handles and user data (see GUIDATA)
) U8 W# C% \+ |/ Y$ t4 Z[filename, pathname] = uiputfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...! o r- j1 j* h% A* ]6 i0 N4 K8 B" N n
'*.*','All Files' },'Save Image',...
2 Z) @2 u# q. h. P C i5 _8 x' q- l fullfile(pwd, 'Result/result.png'));* ?7 P! ?5 j: V" {6 W
if ~isequal(filename, 0)
/ u" e; E% x- a9 T) f8 E9 f- e imwrite(handles.Result.BwEnd, fullfile(pathname, filename));$ L8 w. @$ S4 L0 n, {
msgbox('保存图像成功!', '信息提示框');) h/ V* h% c3 m; d' v5 o
end
\, r( V+ C. E; j$ C. L
. H9 p/ y: C5 A8 Z; r, Y" a+ D
3 u% s+ x8 C+ L# {, `% --- Executes on button press in pushbuttonDiplay.3 f, R- n* x S* V) s
function pushbuttonDiplay_Callback(hObject, eventdata, handles)
3 ^! y5 m+ Y8 j' U' _1 {% hObject handle to pushbuttonDiplay (see GCBO). F( y! p: Y8 J2 i8 v, x5 m$ c
% eventdata reserved - to be defined in a future version of MATLAB$ l3 p0 f, I0 n5 P! Z
% handles structure with handles and user data (see GUIDATA)
) [9 j- C% D2 O" A' @if ~isempty(handles.File)
- l, {6 h$ p# g! Q5 D& a ^ F = [];
- h* Y* P3 ?8 K7 p3 j5 p2 c* M F{1} = sprintf('文件名:%s', handles.File);
; ?/ [9 P8 _, `! L F{2} = sprintf('阈值信息%.2f', handles.Result.BwTh);8 n# s) F/ d; T) i- `* H
F{3} = sprintf('面积信息%.2f', handles.Result.BwArea);
7 b0 r) _* k/ S% N F{4} = sprintf('长度信息%.2f', handles.Result.BwLength);4 |+ }, @9 f4 ?9 `$ d. a _
F{5} = sprintf('最大宽度信息%.2f', handles.Result.BwWidthMax);
3 O& h0 S8 @1 p2 G1 y F{6} = sprintf('最小宽度信息%.2f', max(handles.Result.BwWidthMin,0.01));
& e }; }0 T. p4 ^ F{7} = sprintf('形状信息%s', handles.Result.str);
J5 L$ l r$ q0 X' H! m, I% }+ ^ listdlg('PromptString', '参数显示:',...% }* ^$ I( C, P! B5 ~; S; S$ W
'Name', '参数信息', ... @' f4 ~' d2 e/ y3 v( l
'ListSize', [300, 150], ...- X& _6 g: K9 l* m3 b- g W
'SelectionMode','single',...
2 m# V4 b, \; w 'ListString', F);
. Q: z; G% o6 l5 fend
I! e) k% Q; O* @5 b* G+ j! n9 n
8 E4 f3 F/ ^. a5 Q1 A三、运行结果
+ p! \; M8 }5 L2 W9 j* I( P' P8 g; Q9 G x& a) v4 o0 J1 @ v0 T1 c
- i! t' e) m- L4 d! Z/ Z- ?
% K n( V- d7 q! Y! v
5 E$ T. V, k$ U5 l* C, G4 s r8 y8 b7 W8 q4 p! P6 t4 c! g
|
|