-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMFSE_Main.m
More file actions
4151 lines (3790 loc) · 173 KB
/
MFSE_Main.m
File metadata and controls
4151 lines (3790 loc) · 173 KB
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% MATLAB GUI GENERATION FUNCTIONS %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = MFSE_Main(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 0;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MFSE_Main_OpeningFcn, ...
'gui_OutputFcn', @MFSE_Main_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
function MFSE_Main_OpeningFcn(hObject, ~, handles, varargin)
global data
global patches %#ok<*NUSED>
global cali
global system
global jtableobj
global GlobalHandles
set(groot,'defaultUicontrolBackgroundColor',[0.91 0.91 0.91]);
set(groot,'defaultUicontrolFontName','Century gothic');
set(groot,'defaultUIControlFontSize',11);
set(groot,'defaultUitableFontName','Century gothic');
set(groot,'defaultUitableFontSize',11);
set(groot,'defaultAxesFontName','Century gothic');
set(groot,'defaultTextFontName','Century gothic');
set(groot,'defaultTextFontSize',11);
set(groot,'defaultUipanelFontName','Century gothic');
set(groot,'defaultUipanelFontSize',11);
pinfo=parcluster;
load('MFSE_preferences.dat','-mat','system');
system.version='1.0';
system.date='Dec 2025';
system.author='Michael Siccha';
system.contact='msiccha@marum.de';
system.description={'X-ray micro computer tomography (x-ray µCT) allows the quantification of morphological features of microfossils in an unprecedented level of detail and completeness. This software toolbox is designed to assist researchers in the extraction of morphological data out of the µCT scan data accurately and reproducibly and allows the comprehensive manipulation of microfossil (in particular foraminifera) segmentation data.'};
system.forbidden_symbols='[\\%/\:\;\°*,.\"|~^]*';
system.temp.hit_from_patch=false;
system.temp.shift_pressed=false;
system.temp.control_pressed=false;
system.temp.cancel=false;
system.temp.current_load_path=[pwd '\'];
system.temp.current_save_path=[pwd '\'];
system.temp.current_export_path=[pwd '\'];
system.temp.settingsGUI_active=false;
system.temp.has_external_AO=false;
system.temp.view=[-37.5,30];
system.temp.revert_filename=[];
system.temp.available_pworkers=pinfo.NumWorkers;
system.temp.current_center=[0 0 0];
system.temp.filename=[];
system.temp.LastSort={'Label','ascend'};
system.temp.hit_from_table_renew=false;
if strcmp(system.static.startup_parallel_cluster,'true')
evalc('ppool=parpool(pinfo,round(system.static.pworkers_to_use*pinfo.NumWorkers))');
ppool.IdleTimeout=120; %#ok<STRNU>
end
%system.corollary.patch_margin=0.5;
%system.corollary.light_ambient=0.5;
%system.corollary.light_specular=0;
%system.corollary.light_diffuse=0.75;
%system.corollary.colormap=lines(4096);
%system.corollary.normal_gaussian_parms=[3,3,3,0.65];
%system.corollary.smooth_gaussian_parms=[5,5,5,3];
%system.static.pworkers_ratio_to_use=0.5;
%system.static.startup_parallel_cluster='false';
%system.static.TableOptParmList=table({'PrincipalAxisLength';'PrincipalAxisLength';'PrincipalAxisLength';'PrincipalAxisLength';'PrincipalAxisLength';'PrincipalAxisLength';'ConvexVolume';'Extent';'SurfaceArea';'Solidity';'EquivDiameter'},[1;1;2;2;3;3;1;1;1;1;1],[false;true;false;true;false;true;false;false;false;false;false],[0;1;0;2;0;3;0;0;0;0;0],[0;1;0;1;0;1;0;0;0;0;0],{'1st principal axis length';'1st principal axis length';'2nd principal axis length';'2nd principal axis length';'3rd principal axis length';'3rd principal axis length';'Convex Volume';'Extent';'Surface area';'Solidity';'Circle equivalent diameter'},{'[vx]';'[µm]';'[vx]';'[µm]';'[vx]';'[µm]';'[vx³]';'[]';'[vx²]';'[]';'[vx]'},{'1st Axis [vx]';'1st Axis [µm]';'2nd Axis [vx]';'2nd Axis [µm]';'3rd Axis [vx]';'3rd Axis [µm]';'Conv. vol. [vx³]';'Extent []';'Surf. area [vx²]';'Solidity []';'CED [vx]'},[true;false;false;false;false;false;false;false;false;true;false]);
%system.static.TableOptParmList.Properties.VariableNames={'RegionPropsName','RegionPropsIndex','Transformed','SourceIdx','Scale','LongName','Unit','ShortName','Set'};
%system.defaults.patch_margin=0.5;
%system.defaults.light_ambient=0.5;
%system.defaults.light_specular=0;
%system.defaults.light_diffuse=0.75;
%system.defaults.OptParmList=[true;false;false;false;false;false;true;false];
handles.output = hObject;
handles.Axes.Color=handles.frame_color.BackgroundColor;
handles.Axes.XAxis.Color=handles.axes_color.BackgroundColor;
handles.Axes.YAxis.Color=handles.axes_color.BackgroundColor;
handles.Axes.ZAxis.Color=handles.axes_color.BackgroundColor;
handles.Axes.MinorGridColor=handles.axes_color.BackgroundColor;
handles.Axes.GridColor=handles.axes_color.BackgroundColor;
handles.Axes.XAxis.Visible='off';
handles.Axes.YAxis.Visible='off';
handles.Axes.ZAxis.Visible='off';
handles.Axes.XGrid='off';
handles.Axes.YGrid='off';
handles.Axes.ZGrid='off';
handles.Axes.XMinorGrid='off';
handles.Axes.YMinorGrid='off';
handles.Axes.ZMinorGrid='off';
handles.Axes.XAxis.TickLabels={''};
handles.Axes.YAxis.TickLabels={''};
handles.Axes.ZAxis.TickLabels={''};
axis(handles.Axes,'off');
guidata(hObject, handles);
cali=camlight(handles.Axes,'headlight');
GlobalHandles.MainTableHandle=handles.MainTable;
GlobalHandles.SelectedFieldHandle=handles.selected_labels;
function varargout = MFSE_Main_OutputFcn(~, ~, handles)
varargout{1} = handles.output;
%place_GUI_element(handles.MainGUIWindow,1)
function MainGUIWindow_CloseRequestFcn(~, ~, ~) %#ok<*DEFNU>
selection = questdlg('Exit application? Any unsaved data will be lost!','Exit ','Yes', 'No','No');
switch selection
case 'Yes'
evalc('delete(gcp(''nocreate''))');
close all force
case 'No'
return
end
function MainGUIWindow_DeleteFcn(~, ~, ~)
close all force
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Menu callback functions %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function load_msd_MenuCallback(~, ~, handles)
global data
global system
global patches
if ~isempty(data)
selection = questdlg('Any unsaved data will be lost!','Load project','Continue', 'Cancel','Cancel');
switch selection
case 'Continue'
load_continue=true;
case 'Cancel'
load_continue=false;
end
else
load_continue=true;
end
if load_continue
[filename, pathname] = uigetfile([system.temp.current_load_path '*.msd'],'Select a segmentation data file');
if isequal(filename,0) || isequal(pathname,0)
return
else
try
system.temp.current_load_path=pathname;
data=[];
patches=[];
%cla(handles.Axes);
h=custom_msgbox('Please wait a few seconds...loading data','','none',[],false);
load(fullfile(pathname, filename),'-mat','segmentation');
ingest_segmentation_struct(segmentation,handles);
catch
h=custom_msgbox('Error encountered during loading file!','','error',[],true);
return
end
system.temp.has_external_AO=false;
handles.export_GIPL.Enable='on';
handles.export_RAW.Enable='on';
handles.import_AO.Enable='on';
handles.import_AO.Checked='off';
handles.RecalcLabelProps.Enable='on';
handles.MainGUIWindow.Name=['MicroFossil Segmentation Editor ' filename];
system.temp.revert_filename=fullfile(pathname, filename);
system.temp.filename=filename;
handles.group_show.Value=1;
handles.class_show.Value=1;
handles.MU_show.Value=1;
handles.layer_show.Value=1;
delete (h)
end
end
function revert_msd_Callback(~, ~, handles)
global data
global system
global patches
if ~isempty(data)
selection = questdlg('Changes since the last save will be undone!','Revert project','Continue', 'Cancel','Cancel');
switch selection
case 'Continue'
load_continue=true;
case 'Cancel'
load_continue=false;
end
else
load_continue=true;
end
if load_continue
data=[];
patches=[];
%cla(handles.Axes);
h=custom_msgbox('Please wait a few seconds...reverting data','','none',[],false);
load(system.temp.revert_filename,'-mat','segmentation');
ingest_segmentation_struct(segmentation,handles);
system.temp.has_external_AO=false;
handles.export_GIPL.Enable='on';
handles.export_RAW.Enable='on';
handles.import_AO.Enable='on';
handles.import_AO.Checked='off';
[~, system.temp.filename]=fileparts(system.temp.revert_filename);
delete (h)
end
function import_legacy_MSD_MenuCallback(~, ~, handles)
global data
global system
global patches
if ~isempty(data)
selection = questdlg('Any unsaved data will be lost!','Load project','Continue', 'Cancel','Cancel');
switch selection
case 'Continue'
load_continue=true;
case 'Cancel'
load_continue=false;
end
else
load_continue=true;
end
if load_continue
[filename, pathname] = uigetfile([system.temp.current_load_path '*.msd'],'Select a legacy segmentation data file');
if isequal(filename,0) || isequal(pathname,0)
return
else
h=custom_msgbox('Please wait a few seconds...importing data','','none',[],false);
system.temp.current_load_path=pathname;
data=[];
patches=[];
cla(handles.Axes);
X=load(fullfile(pathname, filename),'-mat');
Xnames=fieldnames(X);
if any(contains(Xnames,'Seg'))
OldVarNames=X.Seg.Labeltable.Properties.VariableNames;
if any(contains(OldVarNames,'Type_1'))
data.header.Projectname='no name';
data.header.Voxelsize=X.Seg.header.Voxelsize;
data.header.Dimensions=size(X.Seg.Labelfield);
data.header.Comment=reshape(X.Seg.header.Comment',1,numel(X.Seg.header.Comment));
data.header.BasicShellSegmentationSource='Legacy MSD file';
data.header.PrimaryLumenSegmentationSource='Legacy MSD file';
data.Labeltable=table();
data.Labeltable.Label=X.Seg.Labeltable.Label;
data.Labeltable.Active=X.Seg.Labeltable.active;
data.Labeltable.MorphoUnit=X.Seg.Labeltable.MorphoUnit;
data.Labeltable.Layer=ones(size(X.Seg.Labeltable,1),1);
data.Labeltable.Class=repmat({'Lumen'},size(X.Seg.Labeltable,1),1);
data.Labeltable.Group=X.Seg.Labeltable.Type_2;
data.Labeltable.Type=X.Seg.Labeltable.Type_3;
data.Labeltable.Name=X.Seg.Labeltable.Name;
data.basicshell.Binary=X.Seg.primary_shell.Binary;
data.basicshell.patchdata=X.Seg.primary_shell.volumedata;
data.basicshell.Centroid=X.Seg.primary_shell.Centroid;
else
data.header=X.Seg.header;
data.Labeltable=X.Seg.Labeltable(:,1:8);
data.basicshell=X.Seg.basicshell;
for k=1:size(data.Labeltable,1)
if strcmp(data.Labeltable.Class(k),'')
data.Labeltable.Class(k)={'Unclassified'};
end
end
end
max_used_dim=0;
for i=1:size(X.Seg.Labelfield,4)
if any(any(any(X.Seg.Labelfield(:,:,:,i))))
max_used_dim=i;
end
end
data.Labelfield=X.Seg.Labelfield(:,:,:,1:max_used_dim);
elseif contains(Xnames,'D')
data.header.Projectname='no name';
data.header.Voxelsize=X.D.Voxelsize;
data.header.Dimensions=size(X.D.Labelfield);
data.header.Comment=reshape(X.D.Comment',1,numel(X.D.Comment));
data.header.BasicShellSegmentationSource='Legacy MSD file';
data.header.PrimaryLumenSegmentationSource='Legacy MSD file';
data.Labeltable=table();
data.Labeltable.Label=X.D.Datatable.Label;
data.Labeltable.Active=X.D.Datatable.active;
data.Labeltable.MorphoUnit=zeros(size(X.D.Datatable,1),1);
data.Labeltable.Layer=ones(size(X.D.Datatable,1),1);
data.Labeltable.Class=repmat({'Unclassified'},size(X.D.Datatable,1),1);
data.Labeltable.Group=repmat({''},size(X.D.Datatable,1),1);
data.Labeltable.Type=repmat({''},size(X.D.Datatable,1),1);
data.Labeltable.Name=X.D.Datatable.Name;
data.basicshell.Binary=X.D.Shell.Shell_binary;
data.basicshell.patchdata=X.D.Shell.VolumeData;
data.basicshell.Centroid=X.D.Shell.Centroid;
data.Labelfield(:,:,:,1)=X.D.Labelfield;
end
delete (h);
recalculate_patches()
data.display=system.corollary;
ingest_segmentation_struct(data,handles);
handles.export_GIPL.Enable='on';
handles.export_RAW.Enable='on';
handles.import_AO.Enable='on';
handles.import_AO.Checked='off';
handles.MainGUIWindow.Name=['MicroFossil Segmentation Editor ' filename];
system.temp.revert_filename=fullfile(pathname, filename);
delete (h)
end
end
function show_manual_MenuCallback(~, ~, ~)
path=getenv('ProgramFiles');
winopen([path '\MFSE\application\MFSE_Manual.pdf']);
function show_tutorial_MenuCallback(~, ~, ~)
d = dialog('Position', [500, 400, 450, 120]);
uicontrol('Parent',d,'Style','text','Position',[20 80 410 30],'String','A number of short tutorial videos can be found at','HorizontalAlignment', 'center','FontSize', 10);
linkText = 'https://www.youtube.com/@MFSE-tutorials-123';
uicontrol('Parent',d,'Style', 'text', 'String', linkText, 'Position', [20, 50, 410, 30], 'HorizontalAlignment', 'center', 'FontSize', 12, 'Enable', 'inactive', 'ButtonDownFcn', @(~,~) web('https://www.youtube.com/@MFSE-tutorials-123', '-browser'));
cbtn = uicontrol('Parent',d,'Position',[190 20 70 25],'String','Close','Callback','delete(gcf)');
function save_msd_MenuCallback(~, ~, handles)
global data
global system
segmentation=data; %#ok<*NASGU>
segmentation.display=system.corollary;
[filename, pathname] = uiputfile('*.msd','Save segmentation data as', fullfile(system.temp.current_save_path,system.temp.filename));
if isequal(filename,0) || isequal(pathname,0)
return
else
save(fullfile(pathname, filename),'segmentation','-mat','-v7.3');
h=custom_msgbox(['Segmentation project has been saved as ' regexprep(filename,'_','\\_')],'','none',[],true);
handles.MainGUIWindow.Name=['MicroFossil Segmentation Editor ' filename];
system.temp.current_save_path=pathname;
system.temp.revert_filename=fullfile(pathname, filename);
system.temp.filename=filename;
end
function Open_PCT_MenuCallback(~, ~, ~)
global data
if ~isempty(data)
selection = questdlg('Any unsaved data will be lost!','Project Creation Tool','Continue', 'Cancel','Cancel');
switch selection
case 'Continue'
pcontinue=true;
case 'Cancel'
pcontinue=false;
end
else
pcontinue=true;
end
if pcontinue
% clear and disable everything
MFSE_PCT()
end
function import_AO_MenuCallback(~, ~, handles)
global system
global data
global supplementary
[filename, pathname] = uigetfile([system.temp.current_load_path '*.raw'],'Select the RAW file containg the externally calculated ambient occlusion data');
if isequal(filename,0) || isequal(pathname,0)
return
else
system.temp.current_load_path=pathname;
h=custom_msgbox('Please wait a few seconds...loading ambient occlusion data file','','help',[],false);
try
fid=fopen(fullfile (pathname,filename),'r');
AC=fread(fid,'float32');
supplementary.AmbientOcclusion=reshape(AC,data.header.Dimensions);
system.temp.has_external_AO=true;
handles.import_AO.Checked='on';
catch
e=custom_msgbox('Error encountered during import of Ambient Occlusion data file!','','error',[],true);
end
delete (h);
end
function About_MenuCallback(~, ~, ~)
global system
d = dialog('Position', [500, 400, 450, 315]);
uicontrol('Parent',d,'Style','text','Position',[20 275 410 30],'String','MFSE','HorizontalAlignment', 'center','FontSize', 20);
uicontrol('Parent',d,'Style','text','Position',[20 240 410 30],'String','MicroFossil Segmentation Editor','HorizontalAlignment', 'center','FontSize', 14);
uicontrol('Parent',d,'Style','text','Position',[20 210 410 30],'String',['Version: ' system.version],'HorizontalAlignment', 'center','FontSize', 14);
uicontrol('Parent',d,'Style','text','Position',[20 180 410 30],'String',['Contact: ' system.contact],'HorizontalAlignment', 'center','FontSize', 12);
uicontrol('Parent',d,'Style','text','Position',[20 50 410 130],'String',system.description,'HorizontalAlignment', 'left','FontSize', 10);
cbtn = uicontrol('Parent',d,'Position',[190 20 70 25],'String','Close','Callback','delete(gcf)');
function Preferences_MenuCallback(hObject,~,handles)
global system
if ~system.temp.settingsGUI_active
handles.Preferences.Enable='off';
system.temp.settingsGUI_active=true;
SecondWindow=openfig('MFSE_SettingsGUI.fig');
handlesSecondary=guihandles(SecondWindow);
guidata(hObject, handles);
handlesSecondary.MFSE_Settings.Name='MicroFossil Segmentation Editor Settings';
SecondWindow.CloseRequestFcn=@(hObject,eventdata)Settings_Window_close(handles,handlesSecondary);
handlesSecondary.SettingsDefaults.Callback=@(hObject,eventdata)MFSE_Main('Settings_defaults',hObject,eventdata,handlesSecondary);
handlesSecondary.SettingsLoadPrefs.Callback=@(hObject,eventdata)MFSE_Main('Settings_load_prefs',hObject,eventdata,handlesSecondary);
handlesSecondary.SettingsSavePrefs.Callback=@(hObject,eventdata)MFSE_Main('Settings_save_prefs',hObject,eventdata);
handlesSecondary.SettingsApply.Callback=@(hObject,eventdata)MFSE_Main('Settings_apply',hObject,eventdata,handlesSecondary,handles);
handlesSecondary.SettingsCancel.Callback=@(hObject,eventdata)Settings_Window_close(handles,handlesSecondary);
Populate_settings(handlesSecondary,system);
end
function export_GIPL_MenuCallback(~, ~, handles)
global data
global system
answer=inputdlg({'Enter the label number for the basic shell segmentation [0 to exclude]:' 'Enter the layer number to export:'},'',1,{'65535','1'});
if ~isempty(answer)
Shelllabel=str2num(answer{1});
SelLayer=str2num(answer{2});
else
return
end
if ~isempty(Shelllabel)&&~any(ismember(data.Labeltable.Label,Shelllabel))&&~isempty(SelLayer)&&SelLayer<=size(data.Labelfield,4)
GIPL=uint16(zeros(data.header.Dimensions));
if Shelllabel>0
Shell=data.basicshell.Binary;
GIPL(Shell)=Shelllabel; %65535;
end
labellist=unique(data.Labelfield(:,:,:,SelLayer));
h=custom_waitbar('Please wait...preparing GIPL data',[],false);
for i=2:numel(labellist)
GIPL(ismember(data.Labelfield(:,:,:,SelLayer),labellist(i)))=labellist(i);
waitbar(i/numel(labellist),h);
end
delete (h);
[filename, pathname] = uiputfile('*.gipl','Save data as',fullfile(system.temp.current_export_path,handles.projectname.String));
if isequal(filename,0) || isequal(pathname,0)
return
else
gipl_write_volume(GIPL,fullfile(pathname, filename),[data.header.Voxelsize data.header.Voxelsize data.header.Voxelsize]);
labelname=[filename(1:end-4) 'txt'];
export_ITK_Labels(fullfile(pathname, labelname),Shelllabel);
end
h=custom_msgbox(['Segmentation data and label description have been exported as ' regexprep(filename,'_','\\_') ' and ' labelname ],'','none',[],true);
else
h=custom_msgbox('Please select a valid shell label and layer for this operation!','','error',[],true);
end
function export_RAW_MenuCallback(~, ~, handles)
global data
global system
app=[handles.projectname.String ' [' num2str(data.header.Dimensions(1)) 'x' num2str(data.header.Dimensions(2)) 'x' num2str(data.header.Dimensions(3)) 'x' num2str(size(data.Labelfield,4)) ' - ' num2str(data.header.Voxelsize) ' um - ushort LE]'];
[filename, pathname] = uiputfile('*.raw','Save data as',fullfile(system.temp.current_export_path,app));
if isequal(filename,0) || isequal(pathname,0)
return
else
system.temp.current_export_path=pathname;
fid=fopen(fullfile(pathname, filename),'w');
fwrite(fid,data.Labelfield,'uint16');
fclose (fid);
end
h=custom_msgbox(['Segmentation data has been exported as ' regexprep(filename,'_','\\_')],'','none',[],true);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% View and select GUI functions %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function toggle_mode_Callback(hObject, ~, handles)
cheat={'off' 'on'};
btext={'Select','View'};
rotate3d(handles.Axes,cheat{~hObject.Value+1});
hObject.String=btext{~hObject.Value+1};
hFigure = ancestor(handles.Axes, 'Figure');
hManager = uigetmodemanager(hFigure);
[hManager.WindowListenerHandles.Enabled] = deal(false); % HG2
set(hFigure, 'WindowKeyPressFcn', []);
set(hFigure, 'KeyPressFcn',@(hObject,eventdata)MFSE_Main('MainGUIWindow_WindowKeyPressFcn',hObject,eventdata,guidata(hObject)));
function filter=assemble_label_filter(handles)
if iscell(handles.layer_show.String)
sLayer=handles.layer_show.String{handles.layer_show.Value};
else
sLayer=handles.layer_show.String;
end
if iscell(handles.class_show.String)
sClass=handles.class_show.String{handles.class_show.Value};
else
sClass=handles.class_show.String;
end
if iscell(handles.MU_show.String)
sMU=handles.MU_show.String{handles.MU_show.Value};
else
sMU=handles.MU_show.String;
end
if iscell(handles.group_show.String)
sGroup=handles.group_show.String{handles.group_show.Value};
else
sGroup=handles.group_show.String;
end
sMUops=handles.MU_operation.Value;
sLayerops=handles.layer_operation.Value;
sClassops=handles.class_operation.Value;
sGroupops=handles.group_operation.Value;
if ~strcmp(sMU,'Any')
MU=str2num(sMU); %#ok<*ST2NM>
switch sMUops
case 1
selMU=str2double(string((handles.MainTable.Data(:,5))))<=MU;
case 2
selMU=str2double(string((handles.MainTable.Data(:,5))))>=MU;
case 3
selMU=str2double(string((handles.MainTable.Data(:,5))))==MU;
case 4
selMU=str2double(string((handles.MainTable.Data(:,5))))~=MU;
end
else
selMU=true(size(handles.MainTable.Data,1),1);
end
if ~strcmp(sLayer,'Any')
Layer=str2num(sLayer);
switch sLayerops
case 1
selLayer=str2num(cell2mat(handles.MainTable.Data(:,4)))<=Layer;
case 2
selLayer=str2num(cell2mat(handles.MainTable.Data(:,4)))>=Layer;
case 3
selLayer=str2num(cell2mat(handles.MainTable.Data(:,4)))==Layer;
case 4
selLayer=str2num(cell2mat(handles.MainTable.Data(:,4)))~=Layer;
end
else
selLayer=true(size(handles.MainTable.Data,1),1);
end
if ~strcmp(sClass,'Any')
switch sClassops
case 1
selClass=strcmp(handles.MainTable.Data(:,7),sClass);
case 2
selClass=~strcmp(handles.MainTable.Data(:,7),sClass);
end
else
selClass=true(size(handles.MainTable.Data,1),1);
end
if ~strcmp(sGroup,'Any')
switch sGroupops
case 1
selGroup=strcmp(handles.MainTable.Data(:,8),sGroup);
case 2
selGroup=~strcmp(handles.MainTable.Data(:,8),sGroup);
end
else
selGroup=true(size(handles.MainTable.Data,1),1);
end
filter=selMU&selLayer&selClass&selGroup;
function hide_all_Callback(~, ~, handles)
global patches
global data
global system
for i=1:numel(system.TempLabeltable.Label)
cname=['L' num2str(system.TempLabeltable.Label(i),'%04u')];
patches.(cname).Visible='off';
end
handles.MainTable.Data(:,3)={false};
system.TempLabeltable.show(:)=false;
check_operations(handles);
function show_all_Callback(~, ~, handles)
global patches
global data
global system
for i=1:numel(system.TempLabeltable.Label)
cname=['L' num2str(system.TempLabeltable.Label(i),'%04u')];
patches.(cname).Visible='on';
end
handles.MainTable.Data(:,3)={true};
system.TempLabeltable.show(:)=true;
check_operations(handles);
function hide_Callback(~, ~, handles)
global patches
global data
global system
filter=assemble_label_filter(handles);
if handles.show_active.Value
filter=filter&logical(cell2mat(handles.MainTable.Data(:,2)));
end
for i=1:numel(data.Labeltable.Label)
cname=['L' num2str(data.Labeltable.Label(i),'%04u')];
if filter(i)
patches.(cname).Visible='off';
handles.MainTable.Data(i,3)={false};
system.TempLabeltable.show(i)=false;
end
end
check_operations(handles);
function show_Callback(~, ~, handles)
global patches
global data
global system
filter=assemble_label_filter(handles);
if handles.show_active.Value
filter=filter&logical(cell2mat(handles.MainTable.Data(:,2)));
end
if handles.show_only.Value % show filter und unshow inversion
for i=1:numel(data.Labeltable.Label)
cname=['L' num2str(data.Labeltable.Label(i),'%04u')];
if filter(i)
patches.(cname).Visible='on';
handles.MainTable.Data(i,3)={true};
system.TempLabeltable.show(i)=true;
else
patches.(cname).Visible='off';
handles.MainTable.Data(i,3)={false};
system.TempLabeltable.show(i)=false;
end
end
else % just show filter
for i=1:numel(data.Labeltable.Label)
if filter(i)
cname=['L' num2str(data.Labeltable.Label(i),'%04u')];
patches.(cname).Visible='on';
handles.MainTable.Data(i,3)={true};
system.TempLabeltable.show(i)=true;
end
end
end
check_operations(handles);
function show_selection_Callback(~, ~, handles)
global patches
global data
global system
currently_selected=str2num(handles.selected_labels.String);
system.hit_from_table_renew=true;
for i=1:numel(data.Labeltable.Label)
cname=['L' num2str(data.Labeltable.Label(i),'%04u')];
if any(ismember(currently_selected,data.Labeltable.Label(i)))
patches.(cname).Visible='on';
handles.MainTable.Data(i,3)={true};
system.TempLabeltable.show(i)=true;
else
patches.(cname).Visible='off';
handles.MainTable.Data(i,3)={false};
system.TempLabeltable.show(i)=false;
end
end
check_operations(handles);
function invert_selection_Callback(~, ~, handles)
global patches
global data
global system
currently_selected=str2num(handles.selected_labels.String);
inversion=data.Labeltable.Label(~(ismember(data.Labeltable.Label,currently_selected)));
label='';
for i=1:numel(data.Labeltable.Label)
cname=['L' num2str(data.Labeltable.Label(i),'%04u')];
if any(ismember(inversion,data.Labeltable.Label(i)))
patches.(cname).EdgeColor=[0 0 0];
system.TempLabeltable.selected(system.TempLabeltable.Label==data.Labeltable.Label(i))=true;
label=[label ' ' num2str(data.Labeltable.Label(i))]; %#ok<AGROW>
else
patches.(cname).EdgeColor='none';
system.TempLabeltable.selected(system.TempLabeltable.Label==data.Labeltable.Label(i))=false;
end
end
handles.selected_labels.String=strtrim(label);
check_operations(handles);
function select_visible_Callback(~, ~, handles)
global system
global patches
fn=fieldnames(patches);
label='';
for i=1:size(system.TempLabeltable,1)
cname=['L' num2str(system.TempLabeltable.Label(i),'%04u')];
if system.TempLabeltable.show(i)
patches.(cname).EdgeColor=[0 0 0];
label=[label ' ' num2str(system.TempLabeltable.Label(i))]; %#ok<AGROW>
system.TempLabeltable.selected(i)=true;
else
patches.(cname).EdgeColor='none';
system.TempLabeltable.selected(i)=false;
end
end
handles.selected_labels.String=strtrim(label);
system.TempLabeltable.selected=system.TempLabeltable.show;
check_operations(handles);
function show_shell_Callback(hObject, ~, ~)
global patches
cheat={'off' 'on'};
patches.Shellpatch.Visible=cheat{hObject.Value+1};
function shell_color_Callback(hObject, ~, ~)
global patches
col=custom_colorpicker(hObject.BackgroundColor);
set(hObject,'BackGroundColor',col);
patches.Shellpatch.FaceColor=col;
function shell_opacity_Callback(hObject, ~, ~)
global patches
patches.Shellpatch.FaceAlpha=hObject.Value;
function show_frame_Callback(hObject, ~, handles)
if hObject.Value==1
handles.Axes.Color=handles.frame_color.BackgroundColor;
handles.show_axes.Enable='on';
axis(handles.Axes,'on');
else
handles.show_axes.Enable='off';
handles.show_axes.Value=0;
handles.show_axeslabels.Enable='off';
handles.show_axeslabels.Value=0;
handles.show_grid.Enable='off';
handles.show_grid.Value=0;
handles.Axes.XAxis.Visible='off';
handles.Axes.YAxis.Visible='off';
handles.Axes.ZAxis.Visible='off';
handles.Axes.XGrid='off';
handles.Axes.YGrid='off';
handles.Axes.ZGrid='off';
handles.Axes.XMinorGrid='off';
handles.Axes.YMinorGrid='off';
handles.Axes.ZMinorGrid='off';
axis(handles.Axes,'off');
end
function frame_color_Callback(hObject, ~, handles)
col=custom_colorpicker(hObject.BackgroundColor);
set(hObject,'BackGroundColor',col);
handles.Axes.Color=col;
function show_axes_Callback(hObject, ~, handles)
if hObject.Value==1
handles.Axes.Box='on';
handles.Axes.XAxis.Visible='on';
handles.Axes.YAxis.Visible='on';
handles.Axes.ZAxis.Visible='on';
handles.Axes.XAxis.MinorTick='on';
handles.Axes.YAxis.MinorTick='on';
handles.Axes.ZAxis.MinorTick='on';
handles.show_axeslabels.Enable='on';
handles.show_grid.Enable='on';
else
handles.Axes.Box='off';
handles.show_axeslabels.Enable='off';
handles.show_axeslabels.Value=0;
handles.show_grid.Enable='off';
handles.show_grid.Value=0;
handles.Axes.XAxis.Visible='off';
handles.Axes.YAxis.Visible='off';
handles.Axes.ZAxis.Visible='off';
handles.Axes.XGrid='off';
handles.Axes.YGrid='off';
handles.Axes.ZGrid='off';
handles.Axes.XMinorGrid='off';
handles.Axes.YMinorGrid='off';
handles.Axes.ZMinorGrid='off';
handles.Axes.XAxis.TickLabels={''};
handles.Axes.YAxis.TickLabels={''};
handles.Axes.ZAxis.TickLabels={''};
end
function axes_color_Callback(hObject, ~, handles)
col=custom_colorpicker(hObject.BackgroundColor);
set(hObject,'BackGroundColor',col);
handles.Axes.XAxis.Color=col;
handles.Axes.YAxis.Color=col;
handles.Axes.ZAxis.Color=col;
handles.Axes.MinorGridColor=col;
handles.Axes.GridColor=col;
function show_grid_Callback(hObject, ~, handles)
if hObject.Value==1
handles.Axes.XGrid='on';
handles.Axes.YGrid='on';
handles.Axes.ZGrid='on';
handles.Axes.XMinorGrid='on';
handles.Axes.YMinorGrid='on';
handles.Axes.ZMinorGrid='on';
else
handles.Axes.XGrid='off';
handles.Axes.YGrid='off';
handles.Axes.ZGrid='off';
handles.Axes.XMinorGrid='off';
handles.Axes.YMinorGrid='off';
handles.Axes.ZMinorGrid='off';
end
function show_axeslabels_Callback(hObject, ~, handles)
if hObject.Value==1
handles.Axes.XAxis.TickLabelsMode='auto';
handles.Axes.YAxis.TickLabelsMode='auto';
handles.Axes.ZAxis.TickLabelsMode='auto';
else
handles.Axes.XAxis.TickLabels={''};
handles.Axes.YAxis.TickLabels={''};
handles.Axes.ZAxis.TickLabels={''};
end
function show_vicinity_Callback(~, ~, handles)
global data
global patches
global system
answer=inputdlg({'Enter the distance in voxels:'},'',1,{'50'});
crit_dist=str2num(answer{1});
label=str2num(handles.selected_labels.String);
if ~isempty(label)&&isnumeric(crit_dist)&&~isempty(crit_dist)&&sum(any(data.Labeltable.Label==label))==1
index=find(data.Labeltable.Label==label, 1);
org_patch_name=['L' num2str(label,'%04u')];
distances=zeros(numel(data.Labeltable.Label),1);
f=fieldnames(data.volumedata);
for i=1:numel(f)
distances(i)=pdistance(data.volumedata.(f{i}).Centroid,data.volumedata.(org_patch_name).Centroid);
end
list=distances<=crit_dist;
binary_cheat={'off' 'on'};
for i=1:numel(f)
patches.(f{i}).Visible=binary_cheat{list(i)+1};
label=str2num(f{i}(2:end));
handles.MainTable.Data(data.Labeltable.Label==label,3)={list(i)};
system.TempLabeltable.show(system.TempLabeltable.Label==label)=list(i);
end
else
h=custom_msgbox('Please select a single valid label and enter a numerical distance value for this operation!','','error',[],true);
end
check_operations(handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% general label operations callback functions %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function delete_Callback(~, ~, handles)
global data
labels=str2num(handles.selected_labels.String);
if ~isempty(labels)&&sum(any(data.Labeltable.Label==labels))>0
choice = questdlg('Sure about this?','Delete label(s)','Yes','No','No');
if strcmp(choice,'Yes')
for i=1:numel(labels)
label=labels(i);
remove_entry(label);
end
populate_table(handles,false,false);
end
else
h=custom_msgbox('Please select one or more valid labels for this operation!','','error',[],true);
end
function copy_label_Callback(~, ~, handles)
global data
global patches
labels=str2num(handles.selected_labels.String);
suggested_layer=suggest_layer(labels);
answer=inputdlg({'Enter the name for the new label:','Enter the target layer'},'',1,{'Unnamed label',suggested_layer});
if isempty(answer)
return
else
if ~isempty(answer(2))&&isnumeric(answer(2))
Name=answer{1};
trg_layer=str2num(answer{2});
if trg_layer<=4
if size(data.Labelfield,4)<trg_layer
add_layer(trg_layer-size(data.Labelfield,4))
end
labels=str2num(handles.selected_labels.String);
h=custom_waitbar('Please wait...copying label(s)!',[],false);
for i=1:numel(labels)
index=find(data.Labeltable.Label==labels(i), 1);
src_layer=data.Labeltable.Layer(index);
src_field=data.Labelfield(:,:,:,src_layer);
trg_field=data.Labelfield(:,:,:,trg_layer);
F=ismember(src_field,labels(i));
trg_field(F)=src_field(F);
data.Labelfield(:,:,:,trg_layer)=trg_field;
add_entry(handles,F,trg_layer,data.Labeltable.MorphoUnit(index),data.Labeltable.Class(index),data.Labeltable.Group(index),data.Labeltable.Type(index),data.Labeltable.Name(index));
end
populate_table(handles,true,false);
delete (h);
else
h=custom_msgbox('An maximum of four layers are currently allowed!','','error',[],true);
end
else
end
end
function recolor_label_Callback(~, ~, handles)
global data
global patches
global system
global GlobalHandles
switch handles.LabelColorMap.String{handles.LabelColorMap.Value}
case 'Prism'
colordummy=prism(4096);
disp=8;
case 'Colorbrewer'
dummy=[0.650980392156863 0.807843137254902 0.890196078431373;0.121568627450980 0.470588235294118 0.705882352941177;0.698039215686275 0.874509803921569 0.541176470588235;0.200000000000000 0.627450980392157 0.172549019607843;0.984313725490196 0.603921568627451 0.600000000000000;0.890196078431373 0.101960784313725 0.109803921568627;0.992156862745098 0.749019607843137 0.435294117647059;1 0.498039215686275 0;0.792156862745098 0.698039215686275 0.839215686274510;0.415686274509804 0.239215686274510 0.603921568627451;1 1 0.600000000000000;0.694117647058824 0.349019607843137 0.156862745098039];
colordummy=repmat(dummy,340,1);
disp=12;
case 'Lines'
colordummy=lines(4096);
disp=8;
case 'HSV'
dummy=hsv(8);
colordummy=repmat(dummy,512,1);
disp=8;
end
displacement=round(rand(1,1)*(disp-1))+1;
new_color=[colordummy(displacement:end,:);colordummy(1:displacement-1,:)];
current_labels=str2num(handles.selected_labels.String);
for i=1:numel(current_labels)
cname=['L' num2str(current_labels(i),'%04u')];
if contains(GlobalHandles.MainTableHandle.Data(str2num(cell2mat(GlobalHandles.MainTableHandle.Data(:,1)))==current_labels(i),10),'voxels')
ec=color_mod(new_color(i,:),0.25,'darker');
patches.(cname).EdgeColor=ec;
end
patches.(cname).FaceColor=new_color(i,:);
end
function singularize_Callback(hObject, ~, handles)
global data
labels=str2num(handles.selected_labels.String);
if ~isempty(labels)&&sum(any(data.Labeltable.Label==labels))>0
h=custom_msgbox('Please wait a few seconds...singularizing label patch','','help',[],false);
for i=1:numel(labels)
tbe=data.Labeltable.Label==labels(i);
layer=data.Labeltable.Layer(tbe);
split_data=data.Labelfield(:,:,:,layer);
split_data(split_data~=labels(i))=0;
[XR,YR,ZR]=extract_label(split_data);
cropped_split_data=logical(split_data(XR(1):XR(2),YR(1):YR(2),ZR(1):ZR(2)));
s=regionprops3(cropped_split_data,'Volume','BoundingBox','Image');
main_vol=find(s.Volume==max(s.Volume),1,'first');
L=false(data.header.Dimensions);
Ls=false(size(cropped_split_data));