-
Notifications
You must be signed in to change notification settings - Fork 2
/
superresolution.m
1765 lines (1470 loc) · 63.7 KB
/
superresolution.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
%% -----------------------------------------------------------------------
% SUPERRESOLUTION - 超分辨率图像重建图形用户界面
% Copyright (C) 2016 Laboratory of Zhejiang University
% UPDATED From Laboratory of Audiovisual Communications (LCAV)
%
function varargout = superresolution(varargin)
% Begin GUIinitialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @superresolution_OpeningFcn, ...
'gui_OutputFcn', @superresolution_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
%%%%%%%%%%%%%%%%%%
% Initialisation %
%%%%%%%%%%%%%%%%%%
% --- Executes just before superresolution is made visible.
function superresolution_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to superresolution (see VARARGIN)
% Global variables of the program
% --- 设置本程序的全局变量
%% -----------------------------------------------------------------------
global IMAGESNUMBER; % 输入的图片数
global IMAGESDATA; % 图片的名称以及路径
global IMAGESSTRING; % 列表中图片的名字
global IMAGES; % 输入图片
global IMAGESINFO; % 图片信息,例如像素深度
global PARAMETERSWILLBEGIVEN % 用户是否决定给定参数
global ISPARAMETERSGIVENBYUSER % 确定用户是否选择参数
global PARAMETERSGIVENBYUSER % 用户所给定参数
global TEMPRESULT % temp结果
global DESTGIVEN2; % destgiven2
global CLEARLIST; % 清空列表
global IMAGESCREATED; % 图片创建
global CIPATH;
global CINAMES;
global MAINHANDLES;
% --- 初始化本程序的全局变量
IMAGESNUMBER = 0; % 图片的初始数目为0
IMAGESDATA = []; % 图片的初始数据为空
IMAGESSTRING = {}; % 初始字符串为空
IMAGES = {}; % 初始输入图片为空
IMAGESINFO = {}; % 图片信息初始化为空
PARAMETERSWILLBEGIVEN = false; % 初始化为用户不给定参数
ISPARAMETERSGIVENBYUSER = false; % 初始化为用户不选择参数
PARAMETERSGIVENBYUSER = {}; % 初始参数为空
TEMPRESULT = []; % 初始化为空
DESTGIVEN2 = false; % destgiven2初始false
CLEARLIST = false; % 初始不清空列表
IMAGESCREATED = false; % 图片初始不创建
CIPATH = [];
CINAMES = {};
MAINHANDLES = handles;
% Initialize imagePreview
axes(handles.imagePreview);
set(handles.imagePreview,'Visible', 'off');
% Choose default command line output for superresolution
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% Display EPFL logo on the bottom right of the UI
axes(handles.logo_axes);
imshow('cse.tif');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Add a new image and save its informations %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function addImageFile(handles)
global IMAGESNUMBER;
global IMAGESDATA;
global IMAGESSTRING;
global PARAMETERSWILLBEGIVEN;
global ISPARAMETERSGIVENBYUSER;
global PARAMETERSGIVENBYUSER;
global CLEARLIST;
% get the image
[fnameMult, pname] = uigetfile('*.tif', 'Choose an image', 'MultiSelect', 'on');
if iscell(fnameMult)
nbr = size(fnameMult,2);
elseif isnumeric(fnameMult)
if fnameMult == 0
nbr = 0;
end
elseif isstr(fnameMult)
nbr = 1;
fnameMult = {fnameMult};
end
if CLEARLIST
IMAGESDATA = {};
IMAGESSTRING = {};
CLEARLIST = false;
end
if nbr > 0
set(handles.listImages, 'FontAngle', 'normal');
for i = 1:nbr
fname = fnameMult{1,i};
% activation of the list
set(handles.listImages, 'Max', 1);
set(handles.listImages, 'Enable', 'on');
set(handles.listImages, 'Value', 1);
% save the informations
IMAGESNUMBER = IMAGESNUMBER + 1;
IMAGESDATA(IMAGESNUMBER).name = fname;
IMAGESDATA(IMAGESNUMBER).path = pname;
IMAGESSTRING{IMAGESNUMBER} = fname;
set(handles.listImages, 'String', IMAGESSTRING);
% activate the selection of the image if it is the first image
if IMAGESNUMBER == 1
selectImage(handles, fname, pname);
end
% earase parameters
removeParameters(handles);
% activate the button for removing images
set(handles.removeButton, 'Enable', 'on');
set(handles.removeAllButton, 'Enable', 'on');
set(handles.removeMenu, 'Enable', 'on');
set(handles.removeAllMenu, 'Enable', 'on');
% activate the other buttons if enough images
if IMAGESNUMBER >= 1
set(handles.radiobutton1, 'Enable', 'on');
set(handles.radiobutton2, 'Enable', 'on');
set(handles.popupmenu2, 'Enable', 'on');
set(handles.radiobutton6, 'Enable', 'on');
set(handles.radiobutton7, 'Enable', 'on');
set(handles.checkbox1, 'Enable', 'on');
set(handles.radio_rec_full, 'Enable', 'on');
set(handles.radio_rec_part, 'Enable', 'on');
if get(handles.radio_rec_part, 'Value')
set(handles.text_rec_part, 'Enable', 'on');
end
set(handles.saveHR_checkbox, 'Enable', 'on');
set(handles.saveInCurrentDir_radiobutton, 'Enable', 'on');
set(handles.radiobutton9, 'Enable', 'on');
if get(handles.radiobutton9, 'Value')
set(handles.text14, 'Enable', 'on');
set(handles.chooseDest_pushbutton, 'Enable', 'on');
end
if(PARAMETERSWILLBEGIVEN)
set(handles.popupmenu1, 'Enable', 'off');
if(ISPARAMETERSGIVENBYUSER)
set(handles.removeparameters, 'Enable', 'on');
set(handles.resultButton, 'Enable', 'on');
set(handles.resultMenu, 'Enable', 'on');
else
set(handles.enterparameters, 'Enable', 'on');
set(handles.resultButton, 'Enable', 'off');
set(handles.resultMenu, 'Enable', 'off');
end
else
set(handles.popupmenu1, 'Enable', 'on');
set(handles.resultButton, 'Enable', 'on');
set(handles.resultMenu, 'Enable', 'on');
end
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Add the created images to the list %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function addCreatedImages(handles)
global IMAGESNUMBER;
global IMAGESDATA;
global IMAGESSTRING;
global PARAMETERSWILLBEGIVEN;
global ISPARAMETERSGIVENBYUSER;
global PARAMETERSGIVENBYUSER;
global CLEARLIST;
global MAINHANDLES;
handles = MAINHANDLES;
load CINAMES;
load CIPATH;
% get the image
fnameMult = CINAMES;
pname = CIPATH;
if iscell(fnameMult)
nbr = size(fnameMult,2);
elseif isnumeric(fnameMult)
if fnameMult == 0
nbr = 0;
end
elseif isstr(fnameMult)
nbr = 1;
fnameMult = {fnameMult};
end
removeAllImages(handles);
IMAGESDATA = {};
IMAGESSTRING = {};
CLEARLIST = false;
handles = MAINHANDLES;
if nbr > 0
set(handles.listImages, 'FontAngle', 'normal');
for i = 1:nbr
fname = fnameMult{1,i};
% activation of the list
set(handles.listImages, 'Max', 1);
set(handles.listImages, 'Enable', 'on');
set(handles.listImages, 'Value', 1);
% save the informations
IMAGESNUMBER = IMAGESNUMBER + 1;
IMAGESDATA(IMAGESNUMBER).name = fname;
IMAGESDATA(IMAGESNUMBER).path = pname;
IMAGESSTRING{IMAGESNUMBER} = fname;
set(handles.listImages, 'String', IMAGESSTRING);
% activate the selection of the image if it is the first image
if IMAGESNUMBER == 1
selectImage(handles, fname, pname);
end
% earase parameters
removeParameters(handles);
% activate the button for removing images
set(handles.removeButton, 'Enable', 'on');
set(handles.removeAllButton, 'Enable', 'on');
set(handles.removeMenu, 'Enable', 'on');
set(handles.removeAllMenu, 'Enable', 'on');
% activate the other buttons if enough images
if IMAGESNUMBER >= 1
set(handles.radiobutton1, 'Enable', 'on');
set(handles.radiobutton2, 'Enable', 'on');
set(handles.popupmenu2, 'Enable', 'on');
set(handles.radiobutton6, 'Enable', 'on');
set(handles.radiobutton7, 'Enable', 'on');
set(handles.checkbox1, 'Enable', 'on');
set(handles.radio_rec_full, 'Enable', 'on');
set(handles.radio_rec_part, 'Enable', 'on');
if get(handles.radio_rec_part, 'Value')
set(handles.text_rec_part, 'Enable', 'on');
end
set(handles.saveHR_checkbox, 'Enable', 'on');
set(handles.saveInCurrentDir_radiobutton, 'Enable', 'on');
set(handles.radiobutton9, 'Enable', 'on');
if get(handles.radiobutton9, 'Value')
set(handles.text14, 'Enable', 'on');
set(handles.chooseDest_pushbutton, 'Enable', 'on');
end
if(PARAMETERSWILLBEGIVEN)
set(handles.popupmenu1, 'Enable', 'off');
if(ISPARAMETERSGIVENBYUSER)
set(handles.removeparameters, 'Enable', 'on');
set(handles.resultButton, 'Enable', 'on');
set(handles.resultMenu, 'Enable', 'on');
else
set(handles.enterparameters, 'Enable', 'on');
set(handles.resultButton, 'Enable', 'off');
set(handles.resultMenu, 'Enable', 'off');
end
else
set(handles.popupmenu1, 'Enable', 'on');
set(handles.resultButton, 'Enable', 'on');
set(handles.resultMenu, 'Enable', 'on');
end
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Remove an image and its informations %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function removeImageFile(handles, toRemove)
global IMAGESNUMBER;
global IMAGESDATA;
global IMAGESSTRING;
global DESTGIVEN2;
global CLEARLIST;
% earase parameters
removeParameters(handles);
% remove the image from the data list
IMAGESDATA(:,toRemove) = [];
% remove the image from the string list
charString = char(IMAGESSTRING);
charString(toRemove,:) = [];
IMAGESSTRING = cellstr(charString);
IMAGESNUMBER = IMAGESNUMBER - 1;
% activate the selection of the nearest image
if IMAGESNUMBER >= 1
if toRemove >= IMAGESNUMBER
toDisplay = IMAGESNUMBER;
else
toDisplay = toRemove;
end
set(handles.listImages, 'Value', toDisplay);
set(handles.listImages, 'String', IMAGESSTRING);
fname = IMAGESDATA(toDisplay).name;
pname = IMAGESDATA(toDisplay).path;
selectImage(handles, fname, pname);
else
set(handles.listImages, 'Max', 2);
IMAGESSTRING = {'Press the "Add" button to', 'add images', '', 'OR', '',...
'Press the "Create LR images', 'from a HR image" button to',...
'create your own set of Low', 'Resolution images from a given',...
'High Resolution image'};
set(handles.listImages, 'String', IMAGESSTRING);
set(handles.listImages, 'Value', [4]);
set(handles.listImages, 'Enable', 'inactive');
CLEARLIST = true;
IMAGESNUMBER = 0;
IMAGESDATA = [];
IMAGES = [];
removeParameters(handles);
set(handles.imageName, 'String', '');
set(handles.imageSize, 'String', '');
% displayImage;
axes(handles.imagePreview);
image([]);
set(handles.imagePreview,'Visible', 'off');
set(handles.resultButton, 'Enable', 'off');
set(handles.resultMenu, 'Enable', 'off');
set(handles.enterparameters, 'Enable', 'off');
set(handles.removeparameters, 'Enable', 'off');
set(handles.popupmenu1, 'Enable', 'off');
set(handles.radiobutton1, 'Enable', 'off');
set(handles.radiobutton2, 'Enable', 'off');
set(handles.popupmenu2, 'Enable', 'off');
set(handles.radiobutton6, 'Enable', 'off');
set(handles.radiobutton7, 'Enable', 'off');
set(handles.checkbox1, 'Enable', 'off');
set(handles.radio_rec_full, 'Enable', 'off');
set(handles.radio_rec_part, 'Enable', 'off');
set(handles.text_rec_part, 'Enable', 'off');
set(handles.saveHR_checkbox, 'Enable', 'off');
set(handles.saveInCurrentDir_radiobutton, 'Enable', 'off');
set(handles.radiobutton9, 'Enable', 'off');
set(handles.text14, 'Enable', 'off');
set(handles.chooseDest_pushbutton, 'Enable', 'off');
set(handles.removeButton, 'Enable', 'off');
set(handles.removeAllButton, 'Enable', 'off');
set(handles.removeMenu, 'Enable', 'off');
set(handles.removeAllMenu, 'Enable', 'off');
set(handles.zoomPreview, 'Enable', 'off');
set(handles.listImages, 'FontAngle', 'italic');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Remove all images and their informations %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function removeAllImages(handles)
global IMAGESNUMBER;
global IMAGESDATA;
global IMAGESSTRING;
global IMAGES;
global CLEARLIST;
global MAINHANDLES;
CLEARLIST = true;
IMAGESNUMBER = 0;
IMAGESDATA = [];
IMAGESSTRING = {'Press the "Add" button to', 'add images', '', 'OR', '',...
'Press the "Create LR images', 'from a HR image" button to',...
'create your own set of Low', 'Resolution images from a given',...
'High Resolution image'};
IMAGES = [];
removeParameters(handles);
handles = MAINHANDLES;
set(handles.listImages, 'FontAngle', 'italic');
set(handles.resultButton, 'Enable', 'off');
set(handles.resultMenu, 'Enable', 'off');
set(handles.listImages, 'Max', 2);
set(handles.listImages, 'Value', [4]);
set(handles.listImages, 'String', IMAGESSTRING);
set(handles.listImages, 'Enable', 'inactive');
set(handles.imageName, 'String', '');
set(handles.imageSize, 'String', '');
axes(handles.imagePreview);
image([]);
set(handles.imagePreview,'Visible', 'off');
set(handles.removeButton, 'Enable', 'off');
set(handles.removeAllButton, 'Enable', 'off');
set(handles.removeMenu, 'Enable', 'off');
set(handles.enterparameters, 'Enable', 'off');
set(handles.removeparameters, 'Enable', 'off');
set(handles.radiobutton1, 'Enable', 'off');
set(handles.radiobutton2, 'Enable', 'off');
set(handles.popupmenu2, 'Enable', 'off');
set(handles.zoomPreview, 'Enable', 'off');
set(handles.radiobutton6, 'Enable', 'off');
set(handles.radiobutton7, 'Enable', 'off');
set(handles.checkbox1, 'Enable', 'off');
set(handles.radio_rec_full, 'Enable', 'off');
set(handles.radio_rec_part, 'Enable', 'off');
set(handles.text_rec_part, 'Enable', 'off');
set(handles.saveHR_checkbox, 'Enable', 'off');
set(handles.saveInCurrentDir_radiobutton, 'Enable', 'off');
set(handles.radiobutton9, 'Enable', 'off');
set(handles.text14, 'Enable', 'off');
set(handles.chooseDest_pushbutton, 'Enable', 'off');
MAINHANDLES = handles;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Display an image in an axe %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function displayImage(handles, filePath, destination)
handles.imSource = imread(filePath);
axes(destination);
imshow(handles.imSource);
set(destination,'Visible', 'off');
set(handles.zoomPreview, 'Enable', 'on');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Check that the images are correct %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function test = testImages(handles)
global IMAGESNUMBER;
global IMAGESDATA;
global IMAGES;
global IMAGESINFO;
global IMAGESSTRING;
test = true;
IMAGES = {};
IMAGESINFO = {};
IMAGES{1} = imread([IMAGESDATA(1).path '/' IMAGESDATA(1).name]);
IMAGESINFO{1} = imfinfo([IMAGESDATA(1).path '/' IMAGESDATA(1).name]);
for i=2:IMAGESNUMBER
tempImage = imread([IMAGESDATA(i).path '/' IMAGESDATA(i).name]);
tempInfo = imfinfo([IMAGESDATA(i).path '/' IMAGESDATA(i).name]);
if not(size(IMAGES{1}) == size(tempImage))
errordlg(['Image ' IMAGESSTRING{i} ' has not the same size as image ' IMAGESSTRING{1}], 'Size error');
test = false;
break;
elseif not(IMAGESINFO{1}.BitDepth == tempInfo.BitDepth)
errordlg(['Image ' IMAGESSTRING{i} ' is not the same type as image ' IMAGESSTRING{1}], 'Size error');
test = false;
break;
else
IMAGES{i} = tempImage;
IMAGESINFO{i} = tempInfo;
end
end
test;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Select an image by clicking on it %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function selectImage(handles, fname, pname)
displayImage(handles, [pname filesep fname], handles.imagePreview);
set(handles.imageName, 'String', fname);
info = imfinfo([pname filesep fname]);
set(handles.imageSize, 'String', [num2str(info.Width) ' x ' num2str(info.Height)]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Enter the motion parameters %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function enterParameters(handles)
global IMAGESNUMBER;
global ISPARAMETERSGIVENBYUSER
global PARAMETERSGIVENBYUSER
tempTest = true;
tempRotations = {};
tempTranslationx = {};
tempTranslationy = {};
canceled = false;
try
% getting the rotation parameters
for i=1:IMAGESNUMBER
prompt(i) = {strcat('Rotation image', int2str(i))};
end
title = 'Please, enter the rotation parameters';
lines = 1;
tempRotations = inputdlg(prompt,title,lines);
% test rotation parameters
if size(tempRotations,1) > 0
for i=1:size(tempRotations,1)
if(size(tempRotations{i},1) == 0 || str2num(tempRotations{i}) > 10 || str2num(tempRotations{i}) < -10)
tempTest = false;
end
end
if(tempTest)
PARAMETERSGIVENBYUSER{1} = tempRotations;
end
else
tempTest = false;
canceled = true;
end
% getting the x translation parameters
if(tempTest)
for i=1:IMAGESNUMBER
prompt(i) = {strcat('Translation x of image', int2str(i))};
end
title = 'Please, enter the translation x parameters';
lines = 1;
tempTranslationx = inputdlg(prompt,title,lines);
% test rotation parameters
if size(tempTranslationx,1) > 0
for i=1:size(tempTranslationx,1)
if(size(tempTranslationx{i},1) == 0 | str2num(tempTranslationx{i}) > 10 | str2num(tempTranslationx{i}) < -10)
tempTest = false;
end
end
if(tempTest)
PARAMETERSGIVENBYUSER{2} = tempTranslationx;
end
else
tempTest = false;
canceled = true;
end
end
% getting the y translation parameters
if(tempTest)
for i=1:IMAGESNUMBER
prompt(i) = {strcat('Translation y of image', int2str(i))};
end
title = 'Please, enter the translation y parameters';
lines = 1;
tempTranslationy = inputdlg(prompt,title,lines);
% test translation y parameters
if size(tempTranslationy,1) > 0
for i=1:size(tempTranslationy,1)
if(size(tempTranslationy{i},1) == 0 | str2num(tempTranslationy{i}) > 10 | str2num(tempTranslationy{i}) < -10)
tempTest = false;
end
end
if(tempTest)
PARAMETERSGIVENBYUSER{3} = tempTranslationy;
end
else
tempTest = false;
canceled = true;
end
end
if(tempTest)
set(handles.rotationlist, 'String', PARAMETERSGIVENBYUSER{1});
set(handles.shiftxlist, 'String', PARAMETERSGIVENBYUSER{2});
set(handles.shiftylist, 'String', PARAMETERSGIVENBYUSER{3});
ISPARAMETERSGIVENBYUSER = true;
set(handles.enterparameters, 'Enable', 'off');
set(handles.removeparameters, 'Enable', 'on');
set(handles.popupmenu1, 'Enable', 'off');
set(handles.resultButton, 'Enable', 'on');
set(handles.resultMenu, 'Enable', 'on');
for i=1:IMAGESNUMBER
phi(i) = str2num(PARAMETERSGIVENBYUSER{1}{i});
deltax(i,1) = str2num(PARAMETERSGIVENBYUSER{2}{i});
deltay(i,1) = str2num(PARAMETERSGIVENBYUSER{3}{i});
end
PARAMETERSGIVENBYUSER{1} = phi;
PARAMETERSGIVENBYUSER{2} = deltax;
PARAMETERSGIVENBYUSER{3} = deltay;
else
if (size(tempRotations,1) > 0 & (canceled == false))
errordlg('One parameter in not correct');
PARAMETERSGIVENBYUSER = {};
end
end
catch
errordlg('One parameter in not correct');
PARAMETERSGIVENBYUSER = {};
end
%%%%%%%%%%%%%%%%%%%%%%%%%
% Remove all parameters %
%%%%%%%%%%%%%%%%%%%%%%%%%
function removeParameters(handles)
global ISPARAMETERSGIVENBYUSER;
global PARAMETERSGIVENBYUSER;
global PARAMETERSWILLBEGIVEN;
global MAINHANDLES;
handles = MAINHANDLES;
PARAMETERSGIVENBYUSER = {};
ISPARAMETERSGIVENBYUSER = false;
set(handles.rotationlist, 'String', {});
set(handles.shiftxlist, 'String', {});
set(handles.shiftylist, 'String', {});
set(handles.removeparameters, 'Enable', 'off');
set(handles.resultButton, 'Enable', 'off');
set(handles.resultMenu, 'Enable', 'off');
if (PARAMETERSWILLBEGIVEN)
set(handles.enterparameters, 'Enable', 'on');
else
set(handles.enterparameters, 'Enable', 'off');
end
MAINHANDLES = handles;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Generate the output image %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function generateImage(handles)
global IMAGESNUMBER;
global IMAGESDATA;
global ISPARAMETERSGIVENBYUSER;
global PARAMETERSWILLBEGIVEN;
global PARAMETERSGIVENBYUSER;
global TEMPRESULT;
global IMAGES;
global IMAGESINFO;
global DESTGIVEN2;
% choose the case
if (ISPARAMETERSGIVENBYUSER == true & get(handles.radiobutton1, 'Value') == 0)
registration = 'manual';
else
switch get(handles.popupmenu1,'Value')
case 1
registration = 'vandewalle';
case 2
registration = 'marcel';
case 3
registration = 'lucchese';
case 4
registration = 'keren';
otherwise
disp('Unknown registration method.');
end %switch
end %if
switch get(handles.popupmenu2,'Value')
case 1
reconstruction = 'interpolation';
case 2
reconstruction = 'papoulis-gerchberg';
case 3
reconstruction = 'iteratedBP'; %iterated back projection
case 4
reconstruction = 'robustSR'; %Robust super resolution
case 5
reconstruction = 'pocs'; %A kind of POCS technique...
case 6
reconstruction = 'normConv';
otherwise
disp('Unknown registration method.');
end
h = waitbar(0, 'Preprocessing images');
set(h, 'Name', 'Please wait...');
% preprocessing images
for i=1:IMAGESNUMBER
waitbar(i/IMAGESNUMBER, h, 'Preprocessing images');
im{i} = IMAGES{i};
im{i} = double(im{i})/(2^(IMAGESINFO{i}.BitDepth/IMAGESINFO{i}.SamplesPerPixel));
imColor{i} = im{i};
if (size(size(IMAGES{1}), 2) == 3)
im{i} = rgb2gray(im{i});
end
%% select part of the image or full image to reconstruct
% full image
if (get(handles.radio_rec_full, 'Value') == 1)
im_part{i} = imColor{i};
else
% only part of the high resolution image will be reconstructed
% because of memory limitations and to show the details appropriately
part = get(handles.text_rec_part, 'String');
part = str2double(part);
half_rem_size = round(size(im{i})*(1-part/100)/2);
im_part{i} = ...
imColor{i}(1+half_rem_size(1):end-half_rem_size(1),...
1+half_rem_size(2):end-half_rem_size(2),:);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
waitbar(0, h);
if(get(handles.checkbox1, 'Value') == 1)
% multiply the images with a Tukey window for more accurate registration
% (by making them circularly symmetric)
s_im=size(im{1});
w1=window(@tukeywin,s_im(1),0.25);
w2=window(@tukeywin,s_im(2),0.25)';
w=w1*w2;
for i=1:IMAGESNUMBER
waitbar(i/(IMAGESNUMBER), h, 'Multiplying images with Tukey window...');
im{i} = [zeros(32,s_im(2)+64); ...
zeros(s_im(1),32) im{i}.*w zeros(s_im(1),32); ...
zeros(32,s_im(2)+64)];
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close(h);
% motion estimation
filename1 = 'xx';
filename2 = 'yy';
if get(handles.radiobutton6, 'Value') == 0 %'estimate shift+rotation' is selected
switch registration
case 'manual'
filename1 = 'Man';
% user
for i=1:IMAGESNUMBER
phi_est = PARAMETERSGIVENBYUSER{1};
delta_est = [PARAMETERSGIVENBYUSER{2} PARAMETERSGIVENBYUSER{3}];
end
case 'vandewalle'
filename1 = 'VA';
% patrick
[delta_est, phi_est] = estimate_motion(im,0.6,25);
case 'marcel'
filename1 = 'MA';
% marcel
[delta_est, phi_est] = marcel(im,2);
case 'lucchese'
filename1 = 'LU';
% lucchese
[delta_est, phi_est] = lucchese(im,2);
case 'keren'
filename1 = 'KE';
% keren
[delta_est, phi_est] = keren(im);
end
else %if 'estimate shift only' is selected
switch registration
case 'manual'
filename1 = 'Man';
% user
for i=1:IMAGESNUMBER
phi_est = PARAMETERSGIVENBYUSER{1};
delta_est = [PARAMETERSGIVENBYUSER{2} PARAMETERSGIVENBYUSER{3}];
end
case 'vandewalle'
filename1 = 'VA';
% patrick
delta_est = estimate_shift(im,25);
phi_est = zeros(size(delta_est,1), 1);
case 'marcel'
filename1 = 'MA';
% marcel
delta_est = marcel_shift(im,2);
phi_est = zeros(size(delta_est,1), 1);
case 'lucchese'
filename1 = 'LU';
% lucchese
delta_est = marcel_shift(im,2);
phi_est = zeros(size(delta_est,1), 1);
case 'keren'
filename1 = 'KE';
% keren
delta_est = keren_shift(im);
phi_est = zeros(size(delta_est,1), 1);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% signal reconstruction
% get interpolation factor
factor = get(handles.text_interp_factor, 'String');
factor = str2double(factor);
im_temp = {};
im_color1 = {};
im_color2 = {};
if (size(size(IMAGES{1}), 2) == 3)
for i=1:IMAGESNUMBER
im_temp{i} = rgb2ycbcr(im_part{i});
im_part{i} = im_temp{i}(:,:,1);
end
cb_temp = im_temp{1}(:,:,2);
cr_temp = im_temp{1}(:,:,3);
im_color1 = imresize(cb_temp, factor, 'bicubic');
im_color2 = imresize(cr_temp, factor, 'bicubic');
end
% reconstruct high resolution image
switch reconstruction
case 'interpolation'
filename2 = 'IN';
im_result = interpolation(im_part,delta_est,phi_est,factor);
case 'papoulis-gerchberg'
filename2 = 'PG';
im_result = papoulisgerchberg(im_part,delta_est,factor);
case 'iteratedBP'
filename2 = 'BP';
im_result = iteratedbackprojection(im_part, delta_est, phi_est, factor);
case 'robustSR'
filename2 = 'RS';
im_result = robustSR(im_part, delta_est, phi_est, factor);
case 'pocs'
filename2 = 'PO';
im_result = pocs(im_part,delta_est,factor);
case 'normConv'
correctNoise = get(handles.noise_checkbox, 'Value');
twoPass = get(handles.twopass_checkbox, 'Value');
filename2 = ['NC' num2str(correctNoise) num2str(twoPass)];
im_result = n_conv(im_part,delta_est,phi_est,factor,correctNoise,twoPass);%Last two parameters are booleans for: noiseCorrect and TwoPass
otherwise
errordlg('Unknown reconstruction technique');
end
if (size(size(IMAGES{1}), 2) == 3)
temp_result_ycbcr(:,:,1) = im_result;
temp_result_ycbcr(:,:,2) = im_color1;
temp_result_ycbcr(:,:,3) = im_color2;
im_result = ycbcr2rgb(temp_result_ycbcr);
end
%% Auto Save
autoSave = get(handles.saveHR_checkbox,'Value');
tempPath = get(handles.text14,'String');
if(autoSave)
if(DESTGIVEN2 && get(handles.radiobutton9, 'Value'))
for i = 1:99 % Check if file name already exist, and increment...
if(exist([tempPath '/' 'result_' filename1 '_' filename2 '_' num2str(i) '.tif'], 'file') == 0)
fileName = ['result_' filename1 '_' filename2 '_' num2str(i) '.tif'];
break
end
end
imwrite(im_result, [tempPath '/' fileName]);
else
for i = 1:99 % Check if file name already exist, and increment...
if(exist(['result_' filename1 '_' filename2 '_' num2str(i) '.tif'], 'file') == 0)
fileName = ['result_' filename1 '_' filename2 '_' num2str(i) '.tif'];
break
end
end
imwrite(im_result, fileName);
end
end
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(99);
set(99, 'NumberTitle', 'off')
set(99, 'Name', 'High Resolution Image')
imshow(im_result);
% display parameters
set(handles.rotationlist, 'String', phi_est);
set(handles.shiftxlist, 'String', delta_est(:,1));
set(handles.shiftylist, 'String', delta_est(:,2));
set(handles.rotationlist, 'Enable', 'on');
set(handles.shiftxlist, 'Enable', 'on');
set(handles.shiftylist, 'Enable', 'on');
PARAMETERSGIVENBYUSER{1} = phi_est;
PARAMETERSGIVENBYUSER{2} = delta_est(:,1);
PARAMETERSGIVENBYUSER{3} = delta_est(:,2);
registration = 'manual';
PARAMETERSWILLBEGIVEN = true;
set(handles.popupmenu1, 'Enable', 'off');
ISPARAMETERSGIVENBYUSER = true;
set(handles.removeparameters, 'Enable', 'on');
set(handles.radiobutton2, 'Value', 1.0);
%%%%%%%%%%%%%%%%%%%%%%%%%
% Generate input images %
%%%%%%%%%%%%%%%%%%%%%%%%%
function generateInputImages(handles)
generation();
uiwait();
%%%%%%%%%%%%%%%%%%%%%%
% Callback functions %
%%%%%%%%%%%%%%%%%%%%%%
% --- Outputs from this function are returned to the command line.
function varargout = superresolution_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in addButton.
function addButton_Callback(hObject, eventdata, handles)
% hObject handle to addButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
addImageFile(handles);
% --- Executes on button press in removeButton.
function removeButton_Callback(hObject, eventdata, handles)
% hObject handle to removeButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imageNumber = get((handles.listImages), 'Value');
removeImageFile(handles, imageNumber);
% --- Executes on selection change in listImages.
function listImages_Callback(hObject, eventdata, handles)
% hObject handle to listImages (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns listImages contents as cell array
% contents{get(hObject,'Value')} returns selected item from
% listImages
global IMAGESDATA;
if get(hObject,'Value') >=1
fname = IMAGESDATA(get(hObject,'Value')).name;
pname = IMAGESDATA(get(hObject,'Value')).path;
selectImage(handles, fname, pname);
end
% --- Executes during object creation, after setting all properties.
function listImages_CreateFcn(hObject, eventdata, handles)