-
Notifications
You must be signed in to change notification settings - Fork 13
/
Main_Interface.m
1060 lines (914 loc) · 38.3 KB
/
Main_Interface.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = Main_Interface(varargin)
% MAIN_INTERFACE MATLAB code for Main_Interface.fig
% MAIN_INTERFACE, by itself, creates a new MAIN_INTERFACE or raises the existing
% singleton*.
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Main_Interface_OpeningFcn, ...
'gui_OutputFcn', @Main_Interface_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 Main_Interface is made visible.
function Main_Interface_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% Set the colors indicating a selected/unselected tab
handles.unselectedTabColor=get(handles.tab1text,'BackgroundColor');
handles.selectedTabColor=handles.unselectedTabColor-0.1;
% Set units to normalize for easier handling
set(handles.tab1text,'Units','normalized')
set(handles.tab2text,'Units','normalized')
set(handles.tab3text,'Units','normalized')
set(handles.tab1Panel,'Units','normalized')
set(handles.tab2Panel,'Units','normalized')
set(handles.tab3Panel,'Units','normalized')
% Create tab labels (as many as you want according to following code template)
% Tab 1
pos1=get(handles.tab1text,'Position');
handles.a1=axes('Units','normalized',...
'Box','on',...
'XTick',[],...
'YTick',[],...
'Color',handles.selectedTabColor,...
'Position',[pos1(1) pos1(2) pos1(3) pos1(4)+0.01],...
'ButtonDownFcn','simpletab(''a1bd'',gcbo,[],guidata(gcbo))');
handles.t1=text('String','Basic',...
'Units','normalized',...
'Position',[(pos1(3)-pos1(1)+0.6)/2,pos1(2)/2+pos1(4)+0.1],...
'HorizontalAlignment','left',...
'VerticalAlignment','bottom',...
'Margin',0.001,...
'FontSize',12,...
'Backgroundcolor',handles.selectedTabColor,...
'ButtonDownFcn','simpletab(''t1bd'',gcbo,[],guidata(gcbo))');
% Tab 2
pos2=get(handles.tab2text,'Position');
pos2(1)=pos1(1)+pos1(3);
handles.a2=axes('Units','normalized',...
'Box','on',...
'XTick',[],...
'YTick',[],...
'Color',handles.unselectedTabColor,...
'Position',[pos2(1) pos2(2) pos2(3) pos2(4)+0.01],...
'ButtonDownFcn','simpletab(''a2bd'',gcbo,[],guidata(gcbo))');
handles.t2=text('String','Impression',...
'Units','normalized',...
'Position',[pos2(3)/2+0.1,pos2(2)/2+pos2(4)+0.1],...
'HorizontalAlignment','left',...
'VerticalAlignment','bottom',...
'Margin',0.001,...
'FontSize',12,...
'Backgroundcolor',handles.unselectedTabColor,...
'ButtonDownFcn','simpletab(''t2bd'',gcbo,[],guidata(gcbo))');
% Tab 3
pos3=get(handles.tab3text,'Position');
pos3(1)=pos2(1)+pos2(3);
handles.a3=axes('Units','normalized',...
'Box','on',...
'XTick',[],...
'YTick',[],...
'Color',handles.unselectedTabColor,...
'Position',[pos3(1) pos3(2) pos3(3) pos3(4)+0.01],...
'ButtonDownFcn','simpletab(''a3bd'',gcbo,[],guidata(gcbo))');
handles.t3=text('String','Analysis',...
'Units','normalized',...
'Position',[pos3(3)/2+0.15,pos3(2)/2+pos3(4)+0.1],...
'HorizontalAlignment','left',...
'VerticalAlignment','bottom',...
'Margin',0.001,...
'FontSize',12,...
'Backgroundcolor',handles.unselectedTabColor,...
'ButtonDownFcn','simpletab(''t3bd'',gcbo,[],guidata(gcbo))');
% Manage panels (place them in the correct position and manage visibilities)
pan1pos=get(handles.tab1Panel,'Position');
set(handles.tab2Panel,'Position',pan1pos)
set(handles.tab3Panel,'Position',pan1pos)
set(handles.tab2Panel,'Visible','off')
set(handles.tab3Panel,'Visible','off')
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Main_Interface wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Main_Interface_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
varargout{1} = handles.output;
% --------------------------------------------------------------------
function file_Callback(hObject, eventdata, handles)
% hObject handle to file (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function openfile_Callback(hObject, eventdata, handles)
% hObject handle to openfile (see GCBO)
[filename,pathname]=uigetfile(...
{'*.bmp;*.jpg;*.png;*.jpeg','image files(*.bmp;*.jpg;*.png;*.jpeg)';...
'*.*','all file(*.*)'},...
'pick an image');
if isequal(filename,0)||isequal(pathname,0)
return;
end
axes(handles.axes1);
fpath=strcat(pathname,filename);
imgsrc=imread(fpath);
setappdata(handles.axes1,'imgsrc',imgsrc);
imshow(imgsrc);
axes(handles.axes2);
imgsize=size(imgsrc);
if numel(imgsize)>2
grayPic=rgb2gray(imgsrc);%实现图像矩阵的归一化操作
else
grayPic=imgsrc;
end
setappdata(handles.axes1,'grayPic',grayPic);
setappdata(handles.axes1,'ProcessPic',grayPic);
imshow(grayPic);
imwrite(grayPic,['E:\0_Working\MATLAB\Picture_Processing_Design\GUI\','grayPic','.jpg']);
axes(handles.axes7);
ProcessPic=getappdata(handles.axes1,'ProcessPic');
setappdata(handles.axes1,'ProcessPic1',ProcessPic);
imshow(ProcessPic);
setappdata(handles.axes1,'img_next',ProcessPic);
setappdata(handles.axes1,'img_last',ProcessPic);
flag0=0;
setappdata(handles.axes1,'flag0',flag0);
set(handles.openfile,'Enable','on');
% --------------------------------------------------------------------
function savefile_Callback(hObject, eventdata, handles)
% hObject handle to savefile (see GCBO)
[filename,pathname]=uiputfile(...
{'*.bmp','BMP files';'*.jpg','JPG files';'*.jpeg','JPEG files'},...
'pick an image');
if isequal(filename,0)||isequal(pathname,0)
return;
else
fpath=strcat(pathname,filename);
end
w=getappdata(handles.axes1,'ProcessPic');
imwrite(w,fpath);
% --- Executes on button press in pushbutton_Reset.
function pushbutton_Reset_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_Reset (see GCBO)
axes(handles.axes7);
ProcessPic=getappdata(handles.axes1,'grayPic');
setappdata(handles.axes1,'ProcessPic',ProcessPic);
setappdata(handles.axes1,'ProcessPic1',ProcessPic);
setappdata(handles.axes1,'img_next',ProcessPic);
setappdata(handles.axes1,'img_last',ProcessPic);
flag0=0;
setappdata(handles.axes1,'flag0',flag0);
imshow(ProcessPic);
set(handles.savefile,'Enable','on');
% --- Executes on button press in boundary_detection.
function boundary_detection_Callback(hObject, eventdata, handles)
% hObject handle to boundary_detection (see GCBO)
axes(handles.axes7);
var=get(handles.Img_boundary_algorithm,'value');
b_t=str2num(get(handles.edit_boundary_threshold,'string'));
ProcessPic=getappdata(handles.axes1,'ProcessPic');
imgedge=ProcessPic;
switch var
case 2
imgedge=edge(ProcessPic,'roberts',b_t);%为保留图像的边缘一个像素
case 3
imgedge=edge(ProcessPic,'prewitt',b_t);%为保留图像的边缘一个像素
case 4
imgedge=edge(ProcessPic,'sobel',b_t);%为保留图像的边缘一个像素
case 5
imgedge=edge(ProcessPic,'log',b_t);%为保留图像的边缘一个像素
case 6
imgedge=edge(ProcessPic,'canny',b_t);%为保留图像的边缘一个像素
otherwise
imgedge=ProcessPic;
end
imshow(imgedge);
setappdata(handles.axes1,'ProcessPic',imgedge);
setappdata(handles.axes1,'ProcessPic1',imgedge);
if getappdata(handles.axes1,'flag0')
img_last=getappdata(handles.axes1,'img_last');
else
img_last=getappdata(handles.axes1,'img_next');
end
setappdata(handles.axes1,'img_next',imgedge);
setappdata(handles.axes1,'img_last',img_last);
set(handles.savefile,'Enable','on');
function Img_boundary_algorithm_Callback(hObject, eventdata, handles)
% hObject handle to Img_boundary_algorithm (see GCBO)
function Img_boundary_algorithm_CreateFcn(hObject, eventdata, handles)
% hObject handle to Img_boundary_algorithm (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_boundary_threshold_Callback(hObject, eventdata, handles)
% hObject handle to edit_boundary_threshold (see GCBO)
function edit_boundary_threshold_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_boundary_threshold (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in image_with_noise.
function image_with_noise_Callback(hObject, eventdata, handles)
% hObject handle to image_with_noise (see GCBO)
axes(handles.axes7);
var=get(handles.Img_noise_algorithm,'value');
n_p=str2num(get(handles.edit6_noise_parameter,'string'));
ProcessPic=getappdata(handles.axes1,'ProcessPic');
if isbw(ProcessPic)
ProcessPic=double(ProcessPic);
end
imgnoise=ProcessPic;
switch var
case 2
imgnoise=imnoise(ProcessPic,'gaussian',0,n_p);%为保留图像加噪
case 3
imgnoise=imnoise(ProcessPic,'poisson');%为保留图像加噪
case 4
imgnoise=imnoise(ProcessPic,'salt & pepper',n_p);%为保留图像加噪
case 5
imgnoise=imnoise(ProcessPic,'speckle',n_p);%为保留图像加噪
otherwise
imgnoise=ProcessPic;
end
imshow(imgnoise);
setappdata(handles.axes1,'ProcessPic',imgnoise);
setappdata(handles.axes1,'ProcessPic1',imgnoise);
if getappdata(handles.axes1,'flag0')
img_last=getappdata(handles.axes1,'img_last');
else
img_last=getappdata(handles.axes1,'img_next');
end
setappdata(handles.axes1,'img_next',imgnoise);
setappdata(handles.axes1,'img_last',img_last);
set(handles.savefile,'Enable','on');
function Img_noise_algorithm_Callback(hObject, eventdata, handles)
% hObject handle to Img_noise_algorithm (see GCBO)
function Img_noise_algorithm_CreateFcn(hObject, eventdata, handles)
% hObject handle to Img_noise_algorithm (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit6_noise_parameter_Callback(hObject, eventdata, handles)
% hObject handle to edit6_noise_parameter (see GCBO)
function edit6_noise_parameter_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6_noise_parameter (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in image_denoising.
function image_denoising_Callback(hObject, eventdata, handles)
% hObject handle to image_denoising (see GCBO)
axes(handles.axes7);
var=get(handles.Img_denoise_algorithm,'value');
f_w=str2num(get(handles.edit7_filter_window,'string'));
ProcessPic=getappdata(handles.axes1,'ProcessPic');
imgdenoise=ProcessPic;
switch var
case 2
imgdenoise=medfilt2(ProcessPic,[f_w f_w]);%中值滤波
case 3
imgdenoise=filter2(fspecial('average',f_w),ProcessPic)/255;%均值滤波
case 4
imgdenoise=wiener2(ProcessPic,[f_w f_w]);%二维自适应维纳滤波
otherwise
imgdenoise=ProcessPic;
end
imshow(imgdenoise,[]);
setappdata(handles.axes1,'ProcessPic',imgdenoise);
setappdata(handles.axes1,'ProcessPic1',imgdenoise);
if getappdata(handles.axes1,'flag0')
img_last=getappdata(handles.axes1,'img_last');
else
img_last=getappdata(handles.axes1,'img_next');
end
setappdata(handles.axes1,'img_next',imgdenoise);
setappdata(handles.axes1,'img_last',img_last);
set(handles.savefile,'Enable','on');
function Img_denoise_algorithm_Callback(hObject, eventdata, handles)
% hObject handle to Img_denoise_algorithm (see GCBO)
function Img_denoise_algorithm_CreateFcn(hObject, eventdata, handles)
% hObject handle to Img_denoise_algorithm (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit7_filter_window_Callback(hObject, eventdata, handles)
% hObject handle to edit7_filter_window (see GCBO)
function edit7_filter_window_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7_filter_window (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in image_enhancement.
function image_enhancement_Callback(hObject, eventdata, handles)
% hObject handle to image_enhancement (see GCBO)
axes(handles.axes7);
ProcessPic=getappdata(handles.axes1,'ProcessPic');
var=get(handles.Img_enhance_way,'value');
enhance_p=str2num(get(handles.edit5_enhance_parameter,'string'));
if isbw(ProcessPic)
ProcessPic=double(ProcessPic);
end
imgenhance=ProcessPic;
switch var
case 2
imgenhance=histeq(ProcessPic,enhance_p); %灰度直方图均衡化
case 3
ProcessPic=double(ProcessPic);
H=[0 1 0,1 enhance_p,0 1 0];
J=conv2(ProcessPic,H,'same');
imgenhance=ProcessPic-J; %线性锐化滤波
case 4
H=fspecial('sobel');
imgenhance=filter2(H,ProcessPic); %Sobel算子锐化处理
case 5
ProcessPic=double(ProcessPic);
[IX,IY]=gradient(ProcessPic); %求图像梯度
gm=sqrt(IX.*IX+IY.*IY);
J=find(gm>=enhance_p); %确定位置
imgenhance(J)=gm(J); %梯度法锐化
case 6
f=double(ProcessPic);[r,c]=size(f);
F=fft2(f);G=fftshift(F);
d0=enhance_p; %半径范围
n=2;%巴特沃斯阶次
a=0.5;b=2.0; %高频强调滤波传递函数系数
mu=floor(r/2);mv=floor(c/2);
for u=1:r
for v=1:c
d=sqrt((u-mu)^2+(v-mv)^2);
Hlpbtw=1/(1+0.414*(d/d0)^(2*n));
Hhpbtw=1-Hlpbtw;
Hhfebtw=a+b*Hhpbtw;
Ghfebtw(u,v)=Hhfebtw*G(u,v);
end
end
ghfebtw=ifftshift(Ghfebtw);
imgenhance=uint8(real(ifft2(ghfebtw)));
otherwise
imgenhance=ProcessPic;
end
setappdata(handles.axes1,'ProcessPic',imgenhance);
setappdata(handles.axes1,'ProcessPic1',imgenhance);
imshow(imgenhance,[]);
if getappdata(handles.axes1,'flag0')
img_last=getappdata(handles.axes1,'img_last');
else
img_last=getappdata(handles.axes1,'img_next');
end
setappdata(handles.axes1,'img_next',imgenhance);
setappdata(handles.axes1,'img_last',img_last);
set(handles.savefile,'Enable','on');
function Img_enhance_way_Callback(hObject, eventdata, handles)
% hObject handle to Img_enhance_way (see GCBO)
function Img_enhance_way_CreateFcn(hObject, eventdata, handles)
% hObject handle to Img_enhance_way (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit5_enhance_parameter_Callback(hObject, eventdata, handles)
% hObject handle to edit5_enhance_parameter (see GCBO)
function edit5_enhance_parameter_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5_enhance_parameter (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton_rotate.
function pushbutton_rotate_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_rotate (see GCBO)
axes(handles.axes7);
var=get(handles.Img_rotate_way,'value');
rotate_angle=str2num(get(handles.Img_rotate_angle,'string'));
ProcessPic1=getappdata(handles.axes1,'ProcessPic1');
ProcessPic=getappdata(handles.axes1,'ProcessPic');
imgrotate=ProcessPic;
[height,width]=size(imgrotate);
switch var
case 2
imgrotate=imrotate(ProcessPic1,rotate_angle,'bilinear');
case 3
tform=maketform('affine',[-1 0 0;0 1 0;width 0 1]);
imgrotate=imtransform(ProcessPic,tform,'nearest');%经过水平镜像变换后的图像
setappdata(handles.axes1,'ProcessPic1',imgrotate);
case 4
tform2=maketform('affine',[1 0 0;0 -1 0;0 height 1]);
imgrotate=imtransform(ProcessPic,tform2,'nearest');%经过竖直镜像变换后的图像
setappdata(handles.axes1,'ProcessPic1',imgrotate);
otherwise
imgrotate=ProcessPic;
end
setappdata(handles.axes1,'ProcessPic',imgrotate);
imshow(imgrotate);
if getappdata(handles.axes1,'flag0')
img_last=getappdata(handles.axes1,'img_last');
else
img_last=getappdata(handles.axes1,'img_next');
end
setappdata(handles.axes1,'img_next',imgrotate);
setappdata(handles.axes1,'img_last',img_last);
set(handles.savefile,'Enable','on');
function Img_rotate_angle_Callback(hObject, eventdata, handles)
% hObject handle to Img_rotate_angle (see GCBO)
function Img_rotate_angle_CreateFcn(hObject, eventdata, handles)
% hObject handle to Img_rotate_angle (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Img_rotate_way_Callback(hObject, eventdata, handles)
% hObject handle to Img_rotate_way (see GCBO)
function Img_rotate_way_CreateFcn(hObject, eventdata, handles)
% hObject handle to Img_rotate_way (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton_scaling.
function pushbutton_scaling_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_scaling (see GCBO)
axes(handles.axes7);
var=get(handles.Img_interpolation_algorithm,'value');
scaling_times=str2num(get(handles.edit9_scaling_times,'string'));
ProcessPic=getappdata(handles.axes1,'ProcessPic');
imgscaling=ProcessPic;
switch var
case 2
imgscaling=imresize(ProcessPic,scaling_times,'nearest');
case 3
imgscaling=imresize(ProcessPic,scaling_times,'bilinear');
case 4
imgscaling=imresize(ProcessPic,scaling_times,'bicubic');
otherwise
imgscaling=ProcessPic;
end
setappdata(handles.axes1,'ProcessPic',imgscaling);
setappdata(handles.axes1,'ProcessPic1',imgscaling);
imshow(imgscaling);
if getappdata(handles.axes1,'flag0')
img_last=getappdata(handles.axes1,'img_last');
else
img_last=getappdata(handles.axes1,'img_next');
end
setappdata(handles.axes1,'img_next',imgscaling);
setappdata(handles.axes1,'img_last',img_last);
set(handles.savefile,'Enable','on');
function Img_interpolation_algorithm_Callback(hObject, eventdata, handles)
% hObject handle to Img_interpolation_algorithm (see GCBO)
function Img_interpolation_algorithm_CreateFcn(hObject, eventdata, handles)
% hObject handle to Img_interpolation_algorithm (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit9_scaling_times_Callback(hObject, eventdata, handles)
% hObject handle to edit9_scaling_times (see GCBO)
function edit9_scaling_times_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit9_scaling_times (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Img_segmentation.
function Img_segmentation_Callback(hObject, eventdata, handles)
% hObject handle to Img_segmentation (see GCBO)
axes(handles.axes7);
var=get(handles.Img_segment_algorithm,'value');
ProcessPic=getappdata(handles.axes1,'ProcessPic');
Imgsegmentation=ProcessPic;
switch var
case 2 %极小值阈值分割
[h,x]=imhist(ProcessPic);
h=smooth(h,7);
%求出阈值T
df1=diff(h);%一阶差分
df2=diff(df1);%二阶差分
[m,n]=size(df2);
T=0;
for i=1:m
if(abs(df1(i+1))<=0.15 && df2(i)>0)
T=x(i+2);%确定阈值
break;
end
end
Imgsegmentation=im2bw(ProcessPic,T/255);%转为二值图像
case 3 %迭代最佳阈值分割
ZMAX=max(max(ProcessPic)); %取出最大灰度值
ZMIN=min(min(ProcessPic)); %取出最小灰度值
TK=(ZMAX+ZMIN)/2;
bcal=1;
ISIZE=size(ProcessPic); %读出图像大小,m/n
while(bcal)
iForeground=0; %定义前景和背景数
iBackground=0;
ForegroundSum=0; %定义前景和背景灰度总和
BackgroundSum=0;
for i=1:ISIZE(1) %循环部分求解读下%
for j=1:ISIZE(2)
tmp=ProcessPic(i,j);
if(tmp>=TK)
iForeground=iForeground+1;
ForegroundSum=ForegroundSum+double(tmp); %前景灰度值
else
iBackground=iBackground+1;
BackgroundSum=BackgroundSum+double(tmp);
end
end
end
ZO=ForegroundSum/iForeground; %计算前景和背景的平均值
ZB=BackgroundSum/iBackground;
TKTmp=uint8(ZO+ZB)/2;
if(TKTmp==TK )
bcal=0;
else
TK=TKTmp;
end %当阈值不再变化的时候,说明迭代结束
end
Imgsegmentation=im2bw(ProcessPic,double(TK)/255);
case 4 %OSTU算法目的就是计算出一连通区域的阈值,然后对该区域二值化
counts = imhist(ProcessPic);
[m,n] = size(ProcessPic);
level = otsu(counts, m*n);
output = ProcessPic;
output(output<level) = 0;
output(output>=level) = 255;
Imgsegmentation=output;
otherwise
Imgsegmentation=ProcessPic;
end
setappdata(handles.axes1,'ProcessPic',Imgsegmentation);
setappdata(handles.axes1,'ProcessPic1',Imgsegmentation);
imshow(Imgsegmentation,[]);
if getappdata(handles.axes1,'flag0')
img_last=getappdata(handles.axes1,'img_last');
else
img_last=getappdata(handles.axes1,'img_next');
end
setappdata(handles.axes1,'img_next',Imgsegmentation);
setappdata(handles.axes1,'img_last',img_last);
set(handles.savefile,'Enable','on');
function Img_segment_algorithm_Callback(hObject, eventdata, handles)
% hObject handle to Img_segment_algorithm (see GCBO)
function Img_segment_algorithm_CreateFcn(hObject, eventdata, handles)
% hObject handle to Img_segment_algorithm (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit10_Callback(hObject, eventdata, handles)
% hObject handle to edit10 (see GCBO)
% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit10 (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes when figure1 is resized.
function figure1_SizeChangedFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% --- Executes on button press in pushbutton_last.
function pushbutton_last_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_last (see GCBO)
axes(handles.axes7);
img_last=getappdata(handles.axes1,'img_last');
flag0=1;
setappdata(handles.axes1,'flag0',flag0);
setappdata(handles.axes1,'ProcessPic',img_last);
imshow(img_last,[]);
set(handles.savefile,'Enable','on');
% --- Executes on button press in pushbutton_next.
function pushbutton_next_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_next (see GCBO)
axes(handles.axes7);
img_next=getappdata(handles.axes1,'img_next');
flag0=0;
setappdata(handles.axes1,'flag0',flag0);
setappdata(handles.axes1,'ProcessPic',img_next);
imshow(img_next,[]);
set(handles.savefile,'Enable','on');
% --- Executes during object creation, after setting all properties.
function tab1Panel_CreateFcn(hObject, eventdata, handles)
% hObject handle to tab1Panel (see GCBO)
function tab2Panel_CreateFcn(hObject, eventdata, handles)
% hObject handle to tab2Panel (see GCBO)
function tab3Panel_CreateFcn(hObject, eventdata, handles)
% hObject handle to tab3Panel (see GCBO)
function tab1text_CreateFcn(hObject, eventdata, handles)
% hObject handle to tab1text (see GCBO)
function tab2text_CreateFcn(hObject, eventdata, handles)
% hObject handle to tab2text (see GCBO)
function tab3text_CreateFcn(hObject, eventdata, handles)
% hObject handle to tab3text (see GCBO)
% Text object 1 callback (tab 1)
function t1bd(hObject,eventdata,handles)
set(hObject,'BackgroundColor',handles.selectedTabColor)
set(handles.t2,'BackgroundColor',handles.unselectedTabColor)
set(handles.t3,'BackgroundColor',handles.unselectedTabColor)
set(handles.a1,'Color',handles.selectedTabColor)
set(handles.a2,'Color',handles.unselectedTabColor)
set(handles.a3,'Color',handles.unselectedTabColor)
set(handles.tab1Panel,'Visible','on')
set(handles.tab2Panel,'Visible','off')
set(handles.tab3Panel,'Visible','off')
% Text object 2 callback (tab 2)
function t2bd(hObject,eventdata,handles)
set(hObject,'BackgroundColor',handles.selectedTabColor)
set(handles.t1,'BackgroundColor',handles.unselectedTabColor)
set(handles.t3,'BackgroundColor',handles.unselectedTabColor)
set(handles.a2,'Color',handles.selectedTabColor)
set(handles.a1,'Color',handles.unselectedTabColor)
set(handles.a3,'Color',handles.unselectedTabColor)
set(handles.tab2Panel,'Visible','on')
set(handles.tab1Panel,'Visible','off')
set(handles.tab3Panel,'Visible','off')
% Text object 3 callback (tab 3)
function t3bd(hObject,eventdata,handles)
set(hObject,'BackgroundColor',handles.selectedTabColor)
set(handles.t1,'BackgroundColor',handles.unselectedTabColor)
set(handles.t2,'BackgroundColor',handles.unselectedTabColor)
set(handles.a3,'Color',handles.selectedTabColor)
set(handles.a1,'Color',handles.unselectedTabColor)
set(handles.a2,'Color',handles.unselectedTabColor)
set(handles.tab3Panel,'Visible','on')
set(handles.tab1Panel,'Visible','off')
set(handles.tab2Panel,'Visible','off')
% Axes object 1 callback (tab 1)
function a1bd(hObject,eventdata,handles)
set(hObject,'Color',handles.selectedTabColor)
set(handles.a2,'Color',handles.unselectedTabColor)
set(handles.a3,'Color',handles.unselectedTabColor)
set(handles.t1,'BackgroundColor',handles.selectedTabColor)
set(handles.t2,'BackgroundColor',handles.unselectedTabColor)
set(handles.t3,'BackgroundColor',handles.unselectedTabColor)
set(handles.tab1Panel,'Visible','on')
set(handles.tab2Panel,'Visible','off')
set(handles.tab3Panel,'Visible','off')
% Axes object 2 callback (tab 2)
function a2bd(hObject,eventdata,handles)
set(hObject,'Color',handles.selectedTabColor)
set(handles.a1,'Color',handles.unselectedTabColor)
set(handles.a3,'Color',handles.unselectedTabColor)
set(handles.t2,'BackgroundColor',handles.selectedTabColor)
set(handles.t1,'BackgroundColor',handles.unselectedTabColor)
set(handles.t3,'BackgroundColor',handles.unselectedTabColor)
set(handles.tab2Panel,'Visible','on')
set(handles.tab1Panel,'Visible','off')
set(handles.tab3Panel,'Visible','off')
% Axes object 3 callback (tab 3)
function a3bd(hObject,eventdata,handles)
set(hObject,'Color',handles.selectedTabColor)
set(handles.a1,'Color',handles.unselectedTabColor)
set(handles.a2,'Color',handles.unselectedTabColor)
set(handles.t3,'BackgroundColor',handles.selectedTabColor)
set(handles.t1,'BackgroundColor',handles.unselectedTabColor)
set(handles.t2,'BackgroundColor',handles.unselectedTabColor)
set(handles.tab3Panel,'Visible','on')
set(handles.tab1Panel,'Visible','off')
set(handles.tab2Panel,'Visible','off')
% --- Executes on slider movement.
function slider_light_Callback(hObject, eventdata, handles)
% hObject handle to slider_light (see GCBO)
axes(handles.axes7);
editstr=get(handles.slider_light,'value');
set(handles.edit_light,'string',num2str(editstr));
ProcessPic1=getappdata(handles.axes1,'ProcessPic1');
if isbw(ProcessPic1)
ProcessPic1=double(ProcessPic1);
end
img_light=imadjust(ProcessPic1,[0 1-editstr],[0 1]);
imshow(img_light);
setappdata(handles.axes1,'ProcessPic',img_light);
setappdata(handles.axes1,'img_next',img_light);
setappdata(handles.axes1,'img_last',ProcessPic1);
set(handles.savefile,'Enable','on');
% --- Executes during object creation, after setting all properties.
function slider_light_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider_light (see GCBO)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function edit_light_Callback(hObject, eventdata, handles)
% hObject handle to edit_light (see GCBO)
axes(handles.axes7);
editstr=get(handles.edit_light,'string');
set(handles.slider_light,'value',str2num(editstr));
ProcessPic1=getappdata(handles.axes1,'ProcessPic1');
img_light=imadjust(ProcessPic1,[0 1-str2num(editstr)],[0 1]);
setappdata(handles.axes1,'ProcessPic',img_light);
imshow(img_light);
setappdata(handles.axes1,'img_next',img_light);
setappdata(handles.axes1,'img_last',ProcessPic1);
set(handles.savefile,'Enable','on');
% --- Executes during object creation, after setting all properties.
function edit_light_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_light (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on slider movement.
function slider_contrast_Callback(hObject, eventdata, handles)
% hObject handle to slider_contrast (see GCBO)
axes(handles.axes7);
editstr=get(handles.slider_contrast,'value');
set(handles.edit_contrast,'string',num2str(editstr));
ProcessPic1=getappdata(handles.axes1,'ProcessPic1');
ProcessPic1=double(ProcessPic1);
editstr=editstr*100;
img_constrast=1./(1 + (125./ (ProcessPic1 + eps)) .^editstr);
setappdata(handles.axes1,'ProcessPic',img_constrast);
imshow(img_constrast);
setappdata(handles.axes1,'img_next',img_constrast);
setappdata(handles.axes1,'img_last',ProcessPic1);
set(handles.savefile,'Enable','on');
% --- Executes during object creation, after setting all properties.
function slider_contrast_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider_contrast (see GCBO)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function edit_contrast_Callback(hObject, eventdata, handles)
% hObject handle to edit_contrast (see GCBO)
axes(handles.axes7);
editstr=get(handles.edit_contrast,'string');
set(handles.slider_contrast,'value',str2num(editstr));
ProcessPic1=getappdata(handles.axes1,'ProcessPic1');
ProcessPic1=double(ProcessPic1);
editstr=editstr*100;
img_constrast=1./(1 + (125./ (ProcessPic1 + eps)) .^editstr);
imshow(img_constrast);
setappdata(handles.axes1,'ProcessPic',img_constrast);
setappdata(handles.axes1,'img_next',img_constrast);
setappdata(handles.axes1,'img_last',ProcessPic1);
set(handles.savefile,'Enable','on');
% --- Executes during object creation, after setting all properties.
function edit_contrast_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_contrast (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Ing_negative.
function Ing_negative_Callback(hObject, eventdata, handles)
% hObject handle to Ing_negative (see GCBO)
axes(handles.axes7);
ProcessPic=getappdata(handles.axes1,'ProcessPic');
if isbw(ProcessPic)
ProcessPic=double(ProcessPic);
end
img_negative=imadjust(ProcessPic,[0 1],[1 0]);
setappdata(handles.axes1,'ProcessPic',img_negative);
setappdata(handles.axes1,'ProcessPic1',img_negative);
imshow(img_negative);
if getappdata(handles.axes1,'flag0')
img_last=getappdata(handles.axes1,'img_last');
else
img_last=getappdata(handles.axes1,'img_next');
end
setappdata(handles.axes1,'img_next',img_negative);
setappdata(handles.axes1,'img_last',img_last);
set(handles.savefile,'Enable','on');
% --- Executes on slider movement.
function slider_compress_Callback(hObject, eventdata, handles)
% hObject handle to slider_compress (see GCBO)
function slider_compress_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider_compress (see GCBO)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function edit_compress_Callback(hObject, eventdata, handles)
% hObject handle to edit_compress (see GCBO)
function edit_compress_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_compress (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Img_gray_level.
function Img_gray_level_Callback(hObject, eventdata, handles)
% hObject handle to Img_gray_level (see GCBO)
axes(handles.axes9);
ProcessPic=getappdata(handles.axes1,'ProcessPic');
h = imhist(ProcessPic);
h1 = h(1:1:256);
horz = 1:1:256;
bar(horz, h1);
set(gca, 'xtick', 0:50:255);
% --- Executes on button press in Img_frequency.
function Img_frequency_Callback(hObject, eventdata, handles)
% hObject handle to Img_frequency (see GCBO)
axes(handles.axes9);
ProcessPic=getappdata(handles.axes1,'ProcessPic');
f = fft2(ProcessPic);
f = fftshift(log(1+abs(f)));
imshow(log(abs(f)),[]); %显示变换后的系数分布
colormap(jet(64));
colorbar;
% --- Executes on button press in Img_fourier.
function Img_fourier_Callback(hObject, eventdata, handles)
% hObject handle to Img_fourier (see GCBO)
axes(handles.axes9);
ProcessPic=getappdata(handles.axes1,'ProcessPic');
f=im2double(ProcessPic);
F=fft2(f);
F2=fftshift(F);
F3=log(1+abs(F2));
imshow(F3,[]);
%imshow(log(abs(F3)),[]); %显示变换后的系数分布
colormap(jet(64));
colorbar;
% --- Executes on button press in Img_size.
function Img_size_Callback(hObject, eventdata, handles)
% hObject handle to Img_size (see GCBO)
axes(handles.axes7);
ProcessPic=getappdata(handles.axes1,'ProcessPic');
img_w=str2num(get(handles.edit_imgwidth,'string'));
img_h=str2num(get(handles.edit_imghight,'string'));
[h,w]=size(ProcessPic);
if get(handles.Img_size_lock,'value')
if img_h >= img_w
img_w=round(w*img_h/h);
set(handles.edit_imgwidth,'string',num2str(img_w));
else
img_h=round(h*img_w/w);
set(handles.edit_imghight,'string',num2str(img_h));
end
img_resize=imresize(ProcessPic,[img_h img_w]);
else
img_resize=imresize(ProcessPic,[img_h img_w]);
end
imshow(img_resize);
setappdata(handles.axes1,'ProcessPic',img_resize);
if getappdata(handles.axes1,'flag0')
img_last=getappdata(handles.axes1,'img_last');
else
img_last=getappdata(handles.axes1,'img_next');
end
setappdata(handles.axes1,'img_next',img_resize);
setappdata(handles.axes1,'img_last',img_last);
set(handles.savefile,'Enable','on');
function edit_imgwidth_Callback(hObject, eventdata, handles)
% hObject handle to edit_imgwidth (see GCBO)
function edit_imgwidth_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_imgwidth (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_imghight_Callback(hObject, eventdata, handles)
% hObject handle to edit_imghight (see GCBO)
function edit_imghight_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_imghight (see GCBO)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Img_size_lock_Callback(hObject, eventdata, handles)
% hObject handle to Img_size_lock (see GCBO)