-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFogBank_GUI_v2.m
3057 lines (2346 loc) · 134 KB
/
FogBank_GUI_v2.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
% Disclaimer: IMPORTANT: This software was developed at the National Institute of Standards and Technology by employees of the Federal Government in the course of their official duties. Pursuant to title 17 Section 105 of the United States Code this software is not subject to copyright protection and is in the public domain. This is an experimental system. NIST assumes no responsibility whatsoever for its use by other parties, and makes no guarantees, expressed or implied, about its quality, reliability, or any other characteristic. We would appreciate acknowledgment if the software is used. This software can be redistributed and/or modified freely provided that any derivative works bear some notice that they are derived from it, and any modified versions bear some notice that they have been modified.
% Updated by Laurent GUERARD 19-08-2016 to make it work on Matlab R2015b
function FogBank_GUI_v2()
tmp = matlab.desktop.editor.getActive;
cd(fileparts(tmp.Filename));
if ~isdeployed
addpath([pwd filesep 'Fogbanksrc']);
addpath([pwd filesep 'Fogbankimgs']);
addpath([pwd filesep 'Fogbankdoc']);
end
% Global Params
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid'); % suppress warnings if the sliders min and max values are both 1
raw_images_path = [pwd filesep 'test' filesep];
raw_images_common_name = '';
raw_image_files = [];
nb_frames = 0;
current_frame_nb = 1;
load_seed_mask_path = raw_images_path;
load_seed_mask_common_name = raw_images_common_name;
use_load_seed_mask = false;
seed_img_files = [];
% used in foreground mask and object separation panels
min_object_size = 1000;
img = [];
foreground_mask = [];
colormap_options = {'gray','jet','hsv','hot','cool'};
contour_color_options = {'Red', 'Green', 'Blue', 'Black', 'White'};
threshold_operator_modifiers = {'>','<','>=','<='};
seed_threshold_operator_modifiers = {'<','<='};
threshold_modifiers = {'Pixel','Percentile'};
grayscale_modifiers = {'Intensity','Gradient','Std','Entropy'};
fg_adjust_contrast_display_raw_image = false;
os_adjust_contrast_display_raw_image = false;
% Figure setup
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
GUI_Name = 'FogBank';
% if the GUI is already open, don't open another copy, bring the current copy to the front
open_fig_handle = findobj('type','figure','name',GUI_Name);
if ~isempty(open_fig_handle)
% figure(open_fig_handle);
% return;
close(open_fig_handle);
end
% Define General colors
lt_gray = [0.86,0.86,0.86];
dark_gray = [0.7,0.7,0.7];
green_blue = [0.0,0.3,0.4];
% purple_color = [0.6,0.6,0.9];
% Get user screen size
SC = get(0, 'ScreenSize');
MaxMonitorX = SC(3);
MaxMonitorY = SC(4);
% Set the figure window size values
main_tabFigScale = 0.5; % Change this value to adjust the figure size
gui_ratio = 0.6;
gui_width = round(MaxMonitorX*main_tabFigScale);
gui_height = gui_width*gui_ratio;
% MaxWindowY = round(MaxMonitorY*main_tabFigScale);
% if MaxWindowX <= MaxWindowY, MaxWindowX = round(1.6*MaxWindowY); end
offset = 0;
if (SC(2) ~= 1)
offset = abs(SC(2));
end
XPos = (MaxMonitorX-gui_width)/2 - offset;
YPos = (MaxMonitorY-gui_height)/2 + offset;
hctfig = figure(...
'units', 'pixels',...
'Position',[ XPos, YPos, gui_width, gui_height ],...
'Name',GUI_Name,...
'Toolbar','figure',...
'NumberTitle','off');
% Tab Setup
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
TabLabels = {'Main'; 'Foreground Mask'; 'Object Separation'};
%-----------------------------------------------------------------------------------------
% Option Tabs
%-----------------------------------------------------------------------------------------
tab_label_text_size = 0.5;
% Create main menu tab, 'Main'
h_tabpanel(1) = uipanel('Units', 'normalized', 'Parent', hctfig, 'Visible', 'on', 'Backgroundcolor', lt_gray,'BorderWidth',0, 'Position', [0,0,1,1] );
h_tabpb(1) = push_button(hctfig, [0 0.95 .307 0.05], TabLabels(1), 'center', 'k', dark_gray, tab_label_text_size, 'serif', 'bold', 'on', {@first_tab_callback} );
% Create main menu tab, 'Foreground Segmentation'
h_tabpanel(2) = uipanel('Units', 'normalized', 'Parent', hctfig,'Visible', 'off', 'Backgroundcolor', lt_gray,'BorderWidth',0,'Position', [0,0,1,1]);
h_tabpb(2) = push_button(hctfig, [.307 0.95 .307 0.05], TabLabels(2), 'center', 'k', dark_gray, tab_label_text_size, 'serif', 'bold', 'off', {@second_tab_callback} );
% Create main menu tab, 'Object Seperation'
h_tabpanel(3) = uipanel('Units', 'normalized','Parent', hctfig, 'Visible', 'off', 'Backgroundcolor', lt_gray, 'BorderWidth',0, 'Position', [0,0,1,1]);
h_tabpb(3) = push_button(hctfig, [.614 0.95 .307 0.05], TabLabels(3), 'center', 'k', dark_gray, tab_label_text_size, 'serif', 'bold', 'off', {@third_tab_callback} );
% Create main menu tab, 'Help'
push_button(hctfig, [0.92 0.95 0.08 0.05], 'Help', 'center', 'k', dark_gray, tab_label_text_size, 'serif', 'bold', 'on', {@Open_Help_PDF_callback} );
function first_tab_callback(varargin)
set(h_tabpb(1), 'Backgroundcolor', lt_gray);
set(h_tabpanel(1), 'Visible', 'on');
set(h_tabpb(2), 'Backgroundcolor', dark_gray);
set(h_tabpanel(2), 'Visible', 'off');
set(h_tabpb(3), 'Backgroundcolor', dark_gray);
set(h_tabpanel(3), 'Visible', 'off');
initMainImagePanel();
end
function second_tab_callback(varargin)
set(h_tabpb(1), 'Backgroundcolor', dark_gray);
set(h_tabpanel(1), 'Visible', 'off');
set(h_tabpb(2), 'Backgroundcolor', lt_gray);
set(h_tabpanel(2), 'Visible', 'on');
set(h_tabpb(3), 'Backgroundcolor', dark_gray);
set(h_tabpanel(3), 'Visible', 'off');
initFgImagePanel();
set(h_tabpb(3), 'enable', 'on');
end
function third_tab_callback(varargin)
set(h_tabpb(1), 'Backgroundcolor', dark_gray);
set(h_tabpanel(1), 'Visible', 'off');
set(h_tabpb(2), 'Backgroundcolor', dark_gray);
set(h_tabpanel(2), 'Visible', 'off');
set(h_tabpb(3), 'Backgroundcolor', lt_gray);
set(h_tabpanel(3), 'Visible', 'on');
initOsImagePanel();
end
function Open_Help_PDF_callback(varargin)
winopen('GUI_Help.pdf');
end
% Main Tab
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
component_height = .05;
main_tab_panel = sub_panel(h_tabpanel(1), [0 0 1 1], '', 'lefttop', 'k', lt_gray, 14, 'serif');
set(main_tab_panel, 'borderwidth', 0);
display_panel = sub_panel(main_tab_panel, [.01 .02 .7 .93], ['Image: <' '>'], 'lefttop', green_blue, lt_gray, 14, 'serif');
options_panel = sub_panel(main_tab_panel, [.72 .02 .27 .93], 'Data', 'lefttop', green_blue, lt_gray, 14, 'serif');
axes('Parent', options_panel, 'Units', 'normalized', 'Position', [.05 0 .9 .25]);
axis image;
axis off
try
imshow('NIST_Logo.tif');
catch err
warning('Unable to load and show NIST logo.');
end
push_button(options_panel, [.88 .96 .1 component_height], '?', 'center', 'k', 'default', .6, 'sans serif', 'bold', 'on', {@main_help_callback});
function main_help_callback(varargin)
winopen('Main_Tab.pdf');
end
label(options_panel, [.01 .89 .99 component_height], 'Raw Images Path:', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
input_dir_editbox = editbox(options_panel, [.01 .85 .98 component_height], raw_images_path, 'left', 'k', 'w', .6, 'normal');
push_button(options_panel, [.5 .795 .485 component_height], 'Browse', 'center', 'k', 'default', 0.5, 'sans serif', 'bold', 'on', {@choose_raw_images_callback} );
label(options_panel, [.01 .69 .95 .05], 'Raw Common Name:', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
common_name_editbox = editbox(options_panel, [.01 .65 .98 component_height], '', 'left', 'k', 'w', .6, 'normal');
function choose_raw_images_callback(varargin)
% get directory
sdir = uigetdir(pwd,'Select Image(s)');
if sdir ~= 0
try
raw_images_path = validate_filepath(sdir);
catch err
if (strcmp(err.identifier,'validate_filepath:notFoundInPath')) || ...
(strcmp(err.identifier,'validate_filepath:argChk'))
errordlg('Invalid directory selected');
return;
else
rethrow(err);
end
end
set(input_dir_editbox, 'String', raw_images_path);
end
end
push_button(options_panel, [.1 .49 .8 1.5*component_height], 'Load Images', 'center', 'k', dark_gray, 0.6, 'sans serif', 'bold', 'on', {@initImages} );
function initImages(varargin)
% get path and common name info from gui
raw_images_path = get(input_dir_editbox, 'string');
if raw_images_path(end) ~= filesep
raw_images_path = [raw_images_path filesep];
end
raw_images_common_name = get(common_name_editbox, 'string');
raw_image_files = dir([raw_images_path '*' raw_images_common_name '*.tif']);
nb_frames = length(raw_image_files);
if nb_frames <= 0
errordlg('Chosen img folder doesn''t contain any .tif images.');
return;
end
% explore the possibility that this single image contains a sequence internally
if nb_frames == 1
stats = imfinfo([raw_images_path raw_image_files(1).name]);
if numel(stats) > 1
nb_frames = numel(stats);
raw_image_files = repmat(raw_image_files, nb_frames,1);
end
end
% Get first img to check its size
current_frame_nb = 1;
img = loadCurrentImage();
% if img is very large, send the user a warning
if numel(img) > 10^7
response = questdlg('Images are large! Visualization might be slow, Continue?', ...
'Notice','Yes','Cancel','Cancel');
% Handle response
switch response
case 'Yes'
% continue displaying images
case 'Cancel'
return; % if the user did not select yes for continue, abort visualization
end
end
destroyMasks();
initMainImagePanel();
set(h_tabpb(2), 'enable', 'on');
end
function I = loadCurrentImage(nb)
if nargin == 0
nb = current_frame_nb;
end
if numel(imfinfo([raw_images_path raw_image_files(nb).name])) > 1
I = imread([raw_images_path raw_image_files(nb).name], 'Index', nb);
else
I = imread([raw_images_path raw_image_files(nb).name]);
end
end
function initMainImagePanel(varargin)
% Create Slider for img display
image_slider_edit = uicontrol('style','slider',...
'Parent',display_panel,...
'unit','normalized',...
'Min',1,'Max',nb_frames,'Value',current_frame_nb, ...
'position',[.01 0.01 0.6 0.05],...
'SliderStep', [1, 1]/max((nb_frames - 1),1), ... % Map SliderStep to whole number, Actual step = SliderStep * (Max slider value - Min slider value)
'callback',{@imgSliderCallback});
% Edit: Cell Numbers to show
goto_user_frame_edit = uicontrol('style','Edit',...
'Parent',display_panel,...
'unit','normalized',...
'position',[.63 0.01 0.1 0.05],...
'HorizontalAlignment','center',...
'String',num2str(current_frame_nb),...
'FontUnits', 'normalized',...
'fontsize',.5,...
'fontweight','normal',...
'backgroundcolor', 'w',...
'callback',{@gotoFrameCallback});
% # of frames label
uicontrol('style','text',...
'Parent',display_panel,...
'unit','normalized',...
'position',[.74 .005 .09 .05],...
'HorizontalAlignment','left',...
'String',['of ' num2str(nb_frames)],...
'FontUnits', 'normalized',...
'fontsize',.6,...
'backgroundcolor', lt_gray,...
'fontweight','normal');
function imgSliderCallback(varargin)
current_frame_nb = ceil(get(image_slider_edit, 'value'));
set(goto_user_frame_edit, 'String', num2str(current_frame_nb));
destroyMasks();
img = loadCurrentImage();
update_main_img();
end
function gotoFrameCallback(varargin)
new_frame_nb = str2double(get(goto_user_frame_edit, 'String'));
if isnan(new_frame_nb)
errordlg('Invalid frame, please input a valid number.');
set(goto_user_frame_edit, 'String', num2str(current_frame_nb));
return;
end
% constrain the new frame number to the existing frame numbers
new_frame_nb = min(new_frame_nb, nb_frames);
new_frame_nb = max(1, new_frame_nb);
current_frame_nb = new_frame_nb;
set(goto_user_frame_edit, 'string', num2str(current_frame_nb));
set(image_slider_edit, 'value', current_frame_nb);
destroyMasks();
img = loadCurrentImage();
update_main_img();
end
img = loadCurrentImage();
update_main_img();
end
main_img_disp_axis = axes('Parent', display_panel, 'Units','normalized', 'Position', [.001 .1 .999 .90]);
axis off; axis image;
function update_main_img(varargin)
% Read corresponding images
set(display_panel, 'Title', ['Image: <' raw_image_files(current_frame_nb).name '>']);
img = double(img);
delete(get(main_img_disp_axis, 'Children'));
imshow(img, [], 'parent', main_img_disp_axis);
end
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
% Foreground Mask
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
fg_colormap_selected_option = colormap_options{1};
fg_countour_color_selected_opt = contour_color_options{1};
fg_display_contour = true;
fg_display_raw_image = true;
fg_import_masks = false;
fg_strel_disk_radius = 2;
morphological_operations = {'None','Dilate','Erode','Close','Open'};
fg_morph_operation = morphological_operations{1};
fg_min_object_size = min_object_size;
fg_min_hole_size = 2*fg_min_object_size;
greedy_range = 50;
foreground_mask_panel = sub_panel(h_tabpanel(2), [0 0 1 1], '', 'lefttop', 'k', lt_gray, 14, 'serif');
set(foreground_mask_panel, 'borderwidth', 0);
fg_display_panel = sub_panel(foreground_mask_panel, [.01 .02 .7 .93], ['Image: <' '>'], 'lefttop', green_blue, lt_gray, 14, 'serif');
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
% Foereground EGT Panel
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
fg_options_panel = sub_panel(foreground_mask_panel, [.72 .02 .27 .93], 'Options', 'lefttop', green_blue, lt_gray, 14, 'serif');
push_button(fg_options_panel, [.88 .96 .1 component_height], '?', 'center', 'k', 'default', .6, 'sans serif', 'bold', 'on', {@fg_help_callback});
function fg_help_callback(varargin)
winopen('Foreground_Tab.pdf');
end
fg_import_checkbox = checkbox(fg_options_panel, [.05 .94 .8 component_height], 'Import Foreground Mask(s)', 'center', 'k', lt_gray, .6, 'sans serif', 'normal', {@fg_import_checkbox_Callback});
set(fg_import_checkbox, 'value',fg_import_masks);
function fg_import_checkbox_Callback(varargin)
if fg_import_masks
fg_import_masks = logical(get(fg_import_checkbox2, 'value'));
else
fg_import_masks = logical(get(fg_import_checkbox, 'value'));
end
set(fg_import_checkbox, 'value',fg_import_masks);
set(fg_import_checkbox2, 'value',fg_import_masks);
if fg_import_masks
set(fg_options_panel, 'visible','off');
set(fg_options_panel2, 'visible','on');
else
set(fg_options_panel, 'visible','on');
set(fg_options_panel2, 'visible','off');
end
end
y = 0.88;
label(fg_options_panel, [.05 y .95 component_height], 'Min Object Area', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
fg_min_object_size_edit = editbox_check(fg_options_panel, [.05 y-.04 .8 component_height], num2str(fg_min_object_size), 'left', 'k', 'w', .6, 'normal', @fg_min_object_size_Callback);
label(fg_options_panel, [.88 y-.04 .1 component_height], 'px', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
function bool = fg_min_object_size_Callback(varargin)
bool = false;
temp = str2double(get(fg_min_object_size_edit, 'String'));
if isnan(temp) || temp < 0
errordlg('Invalid Min Object Size');
return;
end
fg_min_object_size = temp;
bool = true;
end
y = .76;
label(fg_options_panel, [.05 y .95 component_height], 'Fill Holes Smaller Than', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
fg_min_hole_size_edit = editbox_check(fg_options_panel, [.05 y-.04 .8 component_height], num2str(fg_min_hole_size), 'left', 'k', 'w', .6, 'normal', @fg_min_hole_size_Callback);
label(fg_options_panel, [.88 y-.04 .1 component_height], 'px', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
function bool = fg_min_hole_size_Callback(varargin)
bool = false;
temp = str2double(get(fg_min_hole_size_edit, 'String'));
if isnan(temp) || temp < 0
errordlg('Invalid Min Hole Size');
return;
end
fg_min_hole_size = temp;
bool = true;
end
y = .64;
label(fg_options_panel, [.05 y .95 component_height], 'Morphological Operation', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
fg_morph_dropdown = popupmenu(fg_options_panel, [.05 y-.035 .38 component_height], morphological_operations, 'k', 'w', .6, 'normal', @fg_morph_Callback);
label(fg_options_panel, [.43 y-.04 .34 component_height], 'with radius:', 'center', 'k', lt_gray, .6, 'sans serif', 'normal');
fg_strel_radius_edit = editbox_check(fg_options_panel, [.77 y-.035 .18 component_height], num2str(fg_strel_disk_radius), 'right', 'k', 'w', .6, 'normal', @fg_strel_radius_Callback);
function fg_morph_Callback(varargin)
temp = get(fg_morph_dropdown, 'value');
fg_morph_operation = morphological_operations{temp};
end
function bool = fg_strel_radius_Callback(varargin)
bool = false;
temp = round(str2double(get(fg_strel_radius_edit, 'string')));
if temp < 0
errordlg('Invalid strel radius');
return;
end
fg_strel_disk_radius = temp;
bool = true;
end
y = .52;
label(fg_options_panel, [.05 y .95 component_height], 'Greedy', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
% Create Slider for img display
fg_greedy_slider_num = 0;
fg_greedy_edit = uicontrol('style','slider',...
'Parent',fg_options_panel,...
'unit','normalized',...
'Min',-greedy_range,'Max',greedy_range,'Value',fg_greedy_slider_num, ...
'position',[.05 y-.04 .8 component_height],...
'SliderStep', [1, 1]/(greedy_range - -greedy_range), ... % Map SliderStep to whole number, Actual step = SliderStep * (Max slider value - Min slider value)
'callback',{@fgGreedySliderCallback});
fg_slider_num_label = label(fg_options_panel, [.875 y-.04 .1 component_height], fg_greedy_slider_num, 'center', 'k', lt_gray, .6, 'sans serif', 'normal');
function fgGreedySliderCallback(varargin)
fg_greedy_slider_num = ceil(get(fg_greedy_edit, 'value'));
set(fg_slider_num_label, 'String', num2str(fg_greedy_slider_num));
end
push_button(fg_options_panel, [.1 .35 .78 1.2*component_height], 'Update Preview', 'center', 'k', dark_gray, 0.5, 'sans serif', 'bold', 'on', {@fg_update_image});
label(fg_options_panel, [.05 .26 .95 component_height], 'ColorMap:', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
fg_colormap_dropdown = popupmenu(fg_options_panel, [.05 .22 .91 component_height], colormap_options, 'k', 'w', .6, 'normal', @fg_colormap_Callback);
function fg_colormap_Callback(varargin)
temp = get(fg_colormap_dropdown, 'value');
fg_colormap_selected_option = colormap_options(temp);
fg_colormap_selected_option = fg_colormap_selected_option{1};
fg_update_display();
end
fg_contour_checkbox = checkbox(fg_options_panel, [.05 .14 .54 component_height], 'Display Contour', 'center', 'k', lt_gray, .6, 'sans serif', 'normal', {@fg_contour_checkbox_Callback});
set(fg_contour_checkbox, 'value',fg_display_contour);
function fg_contour_checkbox_Callback(varargin)
fg_display_contour = logical(get(fg_contour_checkbox, 'value'));
if(nb_frames <= 0)
return;
else
fg_update_display();
end
end
fg_contour_color_dropdown = popupmenu(fg_options_panel, [.66 .14 .3 component_height], contour_color_options, 'k', 'w', .6, 'normal', @contour_color_callback);
function contour_color_callback(varargin)
temp1 = get(fg_contour_color_dropdown, 'value');
fg_countour_color_selected_opt = contour_color_options(temp1);
fg_update_display();
end
fg_raw_image_checkbox = checkbox(fg_options_panel, [.05 .08 .65 component_height], 'Display Raw Image', 'center', 'k', lt_gray, .6, 'sans serif', 'normal', {@fg_raw_image_checkbox_Callback});
set(fg_raw_image_checkbox, 'value',fg_display_raw_image);
function fg_raw_image_checkbox_Callback(varargin)
fg_display_raw_image = logical(get(fg_raw_image_checkbox, 'value'));
if(nb_frames <= 0)
return;
else
fg_update_display();
end
end
Adjust_Contrast_raw_image_checkbox1 = checkbox(fg_options_panel, [.05 .03 .65 component_height], 'Adjust Contrast', 'center', 'k', lt_gray, .6, 'sans serif', 'normal', {@Adjust_Contrast_raw_image_checkbox_Callback});
set(Adjust_Contrast_raw_image_checkbox1, 'value',fg_adjust_contrast_display_raw_image);
function Adjust_Contrast_raw_image_checkbox_Callback(varargin)
fg_adjust_contrast_display_raw_image = logical(get(Adjust_Contrast_raw_image_checkbox1, 'value'));
if(nb_frames <= 0)
return;
else
fg_update_display();
end
end
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
% Foreground Mask Load Panel
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
fg_options_panel2 = sub_panel(foreground_mask_panel, [.72 .02 .27 .93], 'Options', 'lefttop', green_blue, lt_gray, 14, 'serif');
if fg_import_masks
set(fg_options_panel, 'visible','off');
set(fg_options_panel2, 'visible','on');
else
set(fg_options_panel, 'visible','on');
set(fg_options_panel2, 'visible','off');
end
push_button(fg_options_panel2, [.88 .96 .1 component_height], '?', 'center', 'k', 'default', .6, 'sans serif', 'bold', 'on', {@fg_help_callback});
fg_import_checkbox2 = checkbox(fg_options_panel2, [.05 .94 .8 component_height], 'Import Foreground Mask(s)', 'center', 'k', lt_gray, .6, 'sans serif', 'normal', {@fg_import_checkbox_Callback});
set(fg_import_checkbox2, 'value',fg_import_masks);
fg_mask_path = [pwd filesep 'test' filesep];
fg_common_name = '';
fg_img_files = [];
label(fg_options_panel2, [.01 .86 .99 component_height], 'Foreground Mask Path:', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
fg_input_dir_editbox = editbox(fg_options_panel2, [.01 .8 .98 component_height], fg_mask_path, 'left', 'k', 'w', .6, 'normal');
push_button(fg_options_panel2, [.5 .74 .485 component_height], 'Browse', 'center', 'k', 'default', 0.5, 'sans serif', 'bold', 'on', {@choose_fg_images_callback} );
label(fg_options_panel2, [.01 .62 .95 component_height], 'Foreground Mask Common Name:', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
fg_common_name_editbox = editbox(fg_options_panel2, [.01 .58 .98 component_height], fg_common_name, 'left', 'k', 'w', .6, 'normal');
function choose_fg_images_callback(varargin)
% get directory
sdir = uigetdir(pwd,'Select Image(s)');
if sdir ~= 0
try
fg_mask_path = validate_filepath(sdir);
catch err
if (strcmp(err.identifier,'validate_filepath:notFoundInPath')) || ...
(strcmp(err.identifier,'validate_filepath:argChk'))
errordlg('Invalid directory selected');
return;
else
rethrow(err);
end
end
set(fg_input_dir_editbox, 'String', fg_mask_path);
end
end
% Update Button
push_button(fg_options_panel2, [.1 .35 .78 1.2*component_height], 'Update Foreground Mask', 'center', 'k', dark_gray, .5, 'sans serif', 'bold', 'on', {@fg_update_image});
label(fg_options_panel2, [.05 .26 .95 component_height], 'ColorMap:', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
fg_colormap2_dropdown = popupmenu(fg_options_panel2, [.05 .22 .91 component_height], colormap_options, 'k', 'w', .6, 'normal', @fg_colormap2_Callback);
function fg_colormap2_Callback(varargin)
temp = get(fg_colormap2_dropdown, 'value');
fg_colormap_selected_option = colormap_options(temp);
fg_colormap_selected_option = fg_colormap_selected_option{1};
fg_update_display();
end
fg_contour2_checkbox = checkbox(fg_options_panel2, [.05 .14 .54 component_height], 'Display Contour', 'center', 'k', lt_gray, .6, 'sans serif', 'normal', {@fg_contour2_checkbox_Callback});
set(fg_contour2_checkbox, 'value',fg_display_contour);
function fg_contour2_checkbox_Callback(varargin)
fg_display_contour = logical(get(fg_contour2_checkbox, 'value'));
if(nb_frames <= 0)
return;
else
fg_update_display();
end
end
fg_contour_color2_dropdown = popupmenu(fg_options_panel2, [.66 .14 .3 component_height], contour_color_options, 'k', 'w', .6, 'normal', @contour_color2_callback);
function contour_color2_callback(varargin)
temp1 = get(fg_contour_color2_dropdown, 'value');
fg_countour_color_selected_opt = contour_color_options(temp1);
fg_update_display();
end
fg_raw_image2_checkbox = checkbox(fg_options_panel2, [.05 .08 .65 component_height], 'Display Raw Image', 'center', 'k', lt_gray, .6, 'sans serif', 'normal', {@fg_raw_image2_checkbox_Callback});
set(fg_raw_image2_checkbox, 'value',fg_display_raw_image);
function fg_raw_image2_checkbox_Callback(varargin)
fg_display_raw_image = logical(get(fg_raw_image2_checkbox, 'value'));
if(nb_frames <= 0)
return;
else
fg_update_display();
end
end
Adjust_Contrast_raw_image2_checkbox1 = checkbox(fg_options_panel2, [.05 .03 .65 component_height], 'Adjust Contrast', 'center', 'k', lt_gray, .6, 'sans serif', 'normal', {@Adjust_Contrast2_raw_image_checkbox_Callback});
set(Adjust_Contrast_raw_image2_checkbox1, 'value',fg_adjust_contrast_display_raw_image);
function Adjust_Contrast2_raw_image_checkbox_Callback(varargin)
fg_adjust_contrast_display_raw_image = logical(get(Adjust_Contrast_raw_image2_checkbox1, 'value'));
if(nb_frames <= 0)
return;
else
fg_update_display();
end
end
% ---------------------------------------------------------------------------------------
% Display Panel
% setup the display panel for the foreground tab
function bool = Foreground_Options_validate(varargin)
bool = false;
fg_morph_Callback();
fg_strel_radius_Callback();
if ~fg_min_object_size_Callback(), return, end
if ~fg_min_hole_size_Callback(), return, end
bool = true;
end
function initFgImagePanel(varargin)
% Create Slider for img display
image_slider_edit = uicontrol('style','slider',...
'Parent',fg_display_panel,...
'unit','normalized',...
'Min',1,'Max',nb_frames,'Value',current_frame_nb, ...
'position',[.01 0.01 0.6 0.05],...
'SliderStep', [1, 1]/max((nb_frames - 1),1), ... % Map SliderStep to whole number, Actual step = SliderStep * (Max slider value - Min slider value)
'callback',{@imgSliderCallback});
% Edit: Cell Numbers to show
goto_user_frame_edit = uicontrol('style','Edit',...
'Parent',fg_display_panel,...
'unit','normalized',...
'position',[.63 0.01 0.1 0.05],...
'HorizontalAlignment','center',...
'String',num2str(current_frame_nb),...
'FontUnits', 'normalized',...
'fontsize',.5,...
'fontweight','normal',...
'backgroundcolor', 'w',...
'callback',{@gotoFrameCallback});
% # of frames label
uicontrol('style','text',...
'Parent',fg_display_panel,...
'unit','normalized',...
'position',[.74 .005 .09 .05],...
'HorizontalAlignment','left',...
'String',['of ' num2str(nb_frames)],...
'FontUnits', 'normalized',...
'fontsize',.6,...
'backgroundcolor', lt_gray,...
'fontweight','normal');
function imgSliderCallback(varargin)
current_frame_nb = ceil(get(image_slider_edit, 'value'));
set(goto_user_frame_edit, 'String', num2str(current_frame_nb));
destroyMasks();
img = loadCurrentImage();
fg_update_image();
end
function gotoFrameCallback(varargin)
new_frame_nb = str2double(get(goto_user_frame_edit, 'String'));
if isnan(new_frame_nb)
errordlg('Invalid frame, please input a valid number.');
set(goto_user_frame_edit, 'String', num2str(current_frame_nb), 'Index', current_frame_nb);
return;
end
% constrain the new frame number to the existing frame numbers
new_frame_nb = min(new_frame_nb, nb_frames);
new_frame_nb = max(1, new_frame_nb);
current_frame_nb = new_frame_nb;
set(goto_user_frame_edit, 'string', num2str(current_frame_nb));
set(image_slider_edit, 'value', current_frame_nb);
destroyMasks();
img = loadCurrentImage();
fg_update_image();
end
img = loadCurrentImage();
fg_update_image();
end
fg_axis = axes('Parent', fg_display_panel, 'Units','normalized', 'Position', [.001 .1 .999 .90]);
axis off; axis image;
colors_vector = 0;
% recompute foreground mask and update display, used for img slider and goto frame input
function fg_update_image(varargin)
computeFgMask();
if isempty(img) || isempty(foreground_mask)
return;
end
delete(get(fg_axis, 'Children'));
[disp_I, colors_vector] = superimpose_colormap_contour(img, foreground_mask, colormap([fg_colormap_selected_option '(65000)']), fg_countour_color_selected_opt, fg_display_raw_image, fg_display_contour, fg_adjust_contrast_display_raw_image, colors_vector);
imshow(disp_I, 'Parent', fg_axis);
end
% updates foreground img display without recomputing the mask, used for displaying raw img, img contours, and colormaps
function fg_update_display(varargin)
delete(get(fg_axis, 'Children'));
[disp_I, colors_vector] = superimpose_colormap_contour(img, foreground_mask, colormap([fg_colormap_selected_option '(65000)']), fg_countour_color_selected_opt, fg_display_raw_image, fg_display_contour, fg_adjust_contrast_display_raw_image, colors_vector);
imshow(disp_I, 'Parent', fg_axis);
% set(fg_axis,'nextplot','replacechildren'); % maintains zoom when clicking through slider
end
% Computes the foreground mask
% NOTE: also used in object separation slider to recompute the foreground mask when the img is changed
function computeFgMask(varargin)
if ~Foreground_Options_validate(), return, end
set(fg_display_panel, 'Title', ['Image: <' raw_image_files(current_frame_nb).name '>']);
BW = get_Foreground_Mask();
if ~isempty(BW)
foreground_mask = BW;
end
end
function BW = get_Foreground_Mask()
if fg_import_masks
% load the required image
fg_mask_path = get(fg_input_dir_editbox, 'String');
if fg_mask_path(end) ~= filesep
fg_mask_path = [fg_mask_path filesep];
end
fg_common_name = get(fg_common_name_editbox, 'String');
% validate that the number of images matches
fg_img_files = dir([fg_mask_path '*' fg_common_name '*.tif']);
nb_fg_frames = length(fg_img_files);
if nb_fg_frames == 1
stats = imfinfo([fg_mask_path fg_img_files(current_frame_nb).name]);
if numel(stats) > 1
nb_fg_frames = numel(stats);
fg_img_files = repmat(fg_img_files, nb_fg_frames, 1);
end
end
if nb_fg_frames ~= nb_frames
errordlg('Chosen foreground image folder doesn''t have the same number of .tif images as the images being segmented.');
return;
end
set(fg_display_panel, 'Title', ['Image: <' fg_img_files(current_frame_nb).name '>']);
if numel(imfinfo([fg_mask_path fg_img_files(current_frame_nb).name])) > 1
BW = imread([fg_mask_path fg_img_files(current_frame_nb).name], 'Index', current_frame_nb);
else
BW = imread([fg_mask_path fg_img_files(current_frame_nb).name]);
end
BW = logical(BW);
% check that the image is the same size
if size(img,1) ~= size(BW,1) || size(img,2) ~= size(BW,2)
BW = [];
errordlg('Loaded foreground image is a different size than the image being segmented.');
return;
end
else
BW = EGT_Segmentation(img,fg_min_object_size,fg_min_hole_size, fg_greedy_slider_num);
fg_morph_operation = lower(regexprep(fg_morph_operation, '\W', ''));
BW = morphOp(img, BW, fg_morph_operation, fg_strel_disk_radius);
BW = fill_holes(BW, fg_min_hole_size);
BW = bwareaopen(BW ,fg_min_object_size,8);
end
end
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
% Object Separation Tab
%-----------------------------------------------------------------------------------------
%-----------------------------------------------------------------------------------------
os_display_use_border = false;
os_display_use_seed = false;
os_display_use_mitotic = false;
os_display_contour = true;
os_display_raw_image = true;
fogbank_input_options = {'Grayscale Image','Distance Transform from Seeds', 'Distance Transform from Background','Gradient'};
fog_bank_directions = {'Min -> Max','Max -> Min'};
os_selected_colormap_opt = colormap_options{1};
os_display_labeled_text = false;
os_text_location = 0;
use_distance_transform_in_fogbank_flag = false;
fogbank_direction = fog_bank_directions{1};
min_peak_size = 1000;
nb_obj = 0;
border_mask = [];
seed_mask = [];
mitotic_mask = [];
segmented_image = [];
os_panel = sub_panel(h_tabpanel(3), [0 0 1 1], '', 'lefttop', 'k', lt_gray, 14, 'serif');
set(os_panel, 'borderwidth', 0);
os_display_panel = sub_panel(os_panel, [.01 .02 .7 .93], ['Image: <' '>'], 'lefttop', green_blue, lt_gray, 14, 'serif');
os_options_panel = sub_panel(os_panel, [.72 .02 .27 .93], 'Options', 'lefttop', green_blue, lt_gray, 14, 'serif');
push_button(os_options_panel, [.88 .96 .1 component_height], '?', 'center', 'k', 'default', .6, 'sans serif', 'bold', 'on', {@os_help_callback});
function os_help_callback(varargin)
winopen('Object_Separation_Tab.pdf');
end
%-----------------------------------------------------------------------------------------
% Border Mask
os_use_border_checkbox = checkbox(os_options_panel, [.05 .9 .65 component_height], 'Use Border Mask', 'center', 'k', lt_gray, .6, 'sans serif', 'normal', {@os_use_border_checkbox_Callback});
set(os_use_border_checkbox, 'value', os_display_use_border);
function os_use_border_checkbox_Callback(varargin)
os_display_use_border = logical(get(os_use_border_checkbox, 'value'));
if os_display_use_border
set(border_mask_pb, 'enable', 'on');
else
set(border_mask_pb, 'enable', 'off');
end
end
border_mask_pb = push_button(os_options_panel, [.63 .9 .33 component_height], 'Generate', 'center', 'k', lt_gray, .5, 'sans serif', 'bold', 'off', {@os_Border_Mask_Callback});
%-----------------------------------------------------------------------------------------
% Mitotic Mask
os_use_mitotic_checkbox = checkbox(os_options_panel, [.05 .83 .65 component_height], 'Use Mitotic Mask', 'center', 'k', lt_gray, .55, 'sans serif', 'normal', {@os_use_mitotic_checkbox_Callback});
set(os_use_mitotic_checkbox, 'value', os_display_use_mitotic);
function os_use_mitotic_checkbox_Callback(varargin)
os_display_use_mitotic = logical(get(os_use_mitotic_checkbox, 'value'));
if os_display_use_mitotic
set(mitotic_mask_pb, 'enable', 'on');
else
set(mitotic_mask_pb, 'enable', 'off');
end
end
mitotic_mask_pb = push_button(os_options_panel, [.63 .83 .33 component_height], 'Generate', 'center', 'k', lt_gray, .5, 'sans serif', 'bold', 'off', {@os_Mitotic_Mask_Callback});
%-----------------------------------------------------------------------------------------
% Seed Mask
os_use_seed_checkbox = checkbox(os_options_panel, [.05 .76 .65 component_height], 'Use Seed Mask', 'center', 'k', lt_gray, .55, 'sans serif', 'normal', {@os_use_seed_checkbox_Callback});
set(os_use_seed_checkbox, 'value', os_display_use_seed);
function os_use_seed_checkbox_Callback(varargin)
os_display_use_seed = logical(get(os_use_seed_checkbox, 'value'));
if os_display_use_seed
set(os_min_peak_size_edit, 'visible', 'off');
set(os_min_peak_size_label, 'visible', 'off');
set(seed_mask_pb, 'visible', 'on');
set(seed_mask_pb, 'enable', 'on');
set(seed_mask_load_pb, 'visible', 'on');
set(seed_mask_load_pb, 'enable', 'on');
else
set(os_min_peak_size_edit, 'visible', 'on');
set(os_min_peak_size_label, 'visible', 'on');
set(seed_mask_pb, 'visible', 'off');
set(seed_mask_pb, 'enable', 'off');
set(seed_mask_load_pb, 'visible', 'off');
set(seed_mask_load_pb, 'enable', 'off');
end
end
os_min_peak_size_label = label(os_options_panel, [.05 .71 .65 component_height], 'Min Seed Size:', 'center', 'k', lt_gray, .6, 'sans serif', 'normal');
os_min_peak_size_edit = editbox_check(os_options_panel, [.63 .715 .33 component_height], num2str(min_peak_size), 'center', 'k', 'w', .6, 'normal', @os_min_peak_size_Callback);
function bool = os_min_peak_size_Callback(varargin)
bool = false;
temp = str2double(get(os_min_peak_size_edit, 'string'));
if isnan(temp) || temp < 0
errordlg('Invalid min seed size');
return;
end
min_peak_size = temp;
bool = true;
end
% seed mask push button, hidden until seed mask checkbox is selected
seed_mask_pb = push_button(os_options_panel, [.63 .76 .33 component_height], 'Generate', 'center', 'k', lt_gray, .5, 'sans serif', 'bold', 'off', {@os_Seed_Mask_Callback});
set(seed_mask_pb, 'visible', 'off');
seed_mask_load_pb = push_button(os_options_panel, [.63 .70 .33 component_height], 'Load', 'center', 'k', lt_gray, .5, 'sans serif', 'bold', 'off', {@os_Seed_Load_Mask_Callback});
set(seed_mask_load_pb, 'visible', 'off');
%-----------------------------------------------------------------------------------------
% Object Separation Panel Options
label(os_options_panel, [.05 .64 .95 component_height], 'Apply FogBank On:', 'left', 'k', lt_gray, .6, 'sans serif', 'normal');
os_fogbank_input_dropdown = popupmenu(os_options_panel, [.05 .6 .91 component_height], fogbank_input_options, 'k', 'w', .6, 'normal', @os_fogbank_input_Callback);
function os_fogbank_input_Callback(varargin)
temp = get(os_fogbank_input_dropdown, 'value');
if temp == 1
% grayscale img selected
use_distance_transform_in_fogbank_flag = false;