-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathLandmarkGUI.m
2669 lines (2384 loc) · 104 KB
/
LandmarkGUI.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = LandmarkGUI(varargin)
% GUI to set landmarks in reference and registered images to evaluate the
% registration results
%
% opens from EvalGUI with the current registration results or from the
% command window, then, registration mat-file has to be loaded
%
%
% Before the first start check the path in th LandmarkGUI_OpeningFcn
%
% -------------------------------------------------------------------------
% (c) 2015: Thomas Kuestner, Verena Neumann
% -------------------------------------------------------------------------
% Last Modified by GUIDE v2.5 22-Apr-2016 09:52:40
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @LandmarkGUI_OpeningFcn, ...
'gui_OutputFcn', @LandmarkGUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before LandmarkGUI is made visible.
function LandmarkGUI_OpeningFcn(hObject, ~, handles, varargin)
%% standard paths
currpath = fileparts(mfilename('fullpath'));
if(~exist('GUIPreferences.mat','file')) % first run
SPaths.sResults = uigetdir(pwd,'Select default result directory');
SPaths.sData = uigetdir(pwd,'Select default data directory');
SPaths.sCode = currpath;
standardVoxelsize = [1,1,1];
save('GUIPreferences.mat','SPaths','standardVoxelsize');
else
load GUIPreferences.mat;
try
% check if path are reachable
if(~exist(SPaths.sResults,'dir')), error('path not existing'); end;
if(~exist(SPaths.sData,'dir')), error('path not existing'); end;
if(~exist(SPaths.sCode,'dir')), error('path not existing'); end;
catch
% loading failed or paths not reachable
clear 'SPaths' 'standardVoxelsize';
end
end
if(~exist('SPaths','var'))
% if no valid GUIPreferences are set use the standard paths:
if ~exist([currpath,filesep,'Results'],'dir'); mkdir(currpath,'results'); end
SPaths.sResults = [currpath,filesep,'results'];
SPaths.sData = [currpath,filesep,'example'];
SPaths.sCode = currpath;
end
handles.SPaths = SPaths;
% set some folders on the path
addpath(genpath([currpath,filesep,'io']));
addpath(genpath([currpath,filesep,'metrics']));
addpath(genpath([currpath,filesep,'registration']));
addpath(genpath([currpath,filesep,'segmentation']));
addpath(genpath([currpath,filesep,'utils']));
%% read inputs
if(nargin > 3)
for index = 1:2:(nargin-3),
if nargin-3==index, break, end
switch lower(varargin{index})
case 'inarg'
handles.h = varargin{index+1};
end
end
end
% when opening without data, select a data struct from the hard drive
% originating from registration with RegiGUI
if ~isfield(handles, 'h') || isempty(handles.h)
handles.h = fSelectStruct(handles.SPaths.sResults);
if ~handles.h
handles.closeFigure = true;
% Update handles structure
guidata(hObject, handles);
return;
end
end
%% set icons
try % Try to apply a nice icon
warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');
jframe = get(hObject, 'javaframe');
jIcon = javax.swing.ImageIcon([currpath, filesep, 'icons', filesep, 'LandmarkGUI_icon.png']);
pause(0.001);
jframe.setFigureIcon(jIcon);
clear jframe jIcon
catch
warning('Could not apply a nice icon to the figure :(');
end
dImage = double(imread([currpath,filesep,'icons',filesep,'save.png']))./255;
if size(dImage, 3) == 1, dImage = repmat(dImage, [1 1 3]); end
set(handles.pb_save, 'CData', dImage/max(dImage(:)));
dImage = double(imread([currpath,filesep,'icons',filesep,'open.png']))./255;
if size(dImage, 3) == 1, dImage = repmat(dImage, [1 1 3]); end
set(handles.pb_load, 'CData', dImage/max(dImage(:)));
dImage = double(imread([currpath,filesep,'icons',filesep,'reset.png']))./255;
if size(dImage, 3) == 1, dImage = repmat(dImage, [1 1 3]); end
set(handles.pb_reset_contrast, 'CData', dImage/max(dImage(:)));
dImage = double(imread([currpath,filesep,'icons',filesep,'cogs.png']))./255;
if size(dImage, 3) == 1, dImage = repmat(dImage, [1 1 3]); end
set(handles.pbSettingsMetrics, 'CData', dImage/max(dImage(:)));
x = double(imread([currpath,filesep,'icons',filesep,'papierkorb.jpg']))./255;
I2 = imresize(x, [16 16]);
set(handles.pb_deleteNo, 'CData', I2/max(I2(:)));
%% get voxelsize from preferences, if no SGeo in handles.h!
if ~isfield(handles.h, 'SGeo')|| isempty(handles.h.SGeo.cVoxelsize)
handles.h.SGeo.cVoxelsize{1} = standardVoxelsize;
end
if ~isfield(handles.h,'nSCT')
handles.nSCT = 1; % slice orientation (1 = coronal, 2 = sagittal, 3 = transversal)
else
handles.nSCT = handles.h.nSCT;
set(handles.pm_CorSagTrans,'Value',handles.nSCT)
end
if(~isfield(handles.h, 'SDeform'))
errordlg('No deformation field found. Please provide appropriate file.');
return;
else
handles.SDeform = handles.h.SDeform;
end
% Choose default command line output for LandmarkGUI
handles.output = hObject;
handles.slice = floor(size(handles.h.dImg,3)/2); % slice number
handles.nMovGate = 2; % compare first Reference Gate with Moving Gate 2
handles.iNGates = size(handles.h.dImg,4);
tmp = repmat({'G'},handles.iNGates,1);
handles.names = strcat(tmp,cellfun(@(x) num2str(x,'%02d'), num2cell(1:handles.iNGates).', 'UniformOutput', false));
for iG=1:handles.iNGates
handles.fix.(handles.names{iG}) = []; % arrays for fixed points in different gates
handles.cPolyCoord.(handles.names{iG}){3,1} = {}; % cell array for Line Polygons
handles.cPolyROICoord.(handles.names{iG}){3,1} = {}; % cell array for ROI Polygons
end
handles.ROINumber=ones(handles.iNGates,1); % global number to count lines
handles.lineNumber=ones(handles.iNGates,1); % ROIs
handles.FPointsLines = 1; % default set-tool is setting points
handles.setActive = 1; % flag, set function is active for start up
handles.unfixedpoints = 0; % flag, turns 1 if new landmarks are set
handles.unfixedlines = 0; % flag, turns 1 if new lines or ROIs are set
handles.axeslink = 1; % flag for linked axes, important for scrolling
handles.FButtonDown = 0; % no mouse click at the beginning
handles.exchangePoints = 0;
handles.sImageData='origImage'; % start with original image data (can be changed to interpolated images)
handles.colScale = 4; % scale default color range
set(handles.markRefAx,'xtick',[],'ytick',[]);
set(handles.markMovAx,'xtick',[],'ytick',[]);
set(handles.axBlackRef, 'xtick', [], 'ytick', []);
set(handles.axBlackMov, 'xtick', [], 'ytick', []);
handles.noScrolling = 0;
handles.cTablePoints = num2cell(repmat('-',1,size(handles.h.dImg,4)));
handles.cTableLines = num2cell(repmat('-',1,size(handles.h.dImg,4)));
handles.cTableROIs = num2cell(repmat('-',1,size(handles.h.dImg,4)));
handles.FCellSelectionActive = 1;
% set(handles.tb_points,'ColumName', handles.names);
% try set(handles.tFilename, 'String', ['Dataset: ',handles.h.sFilename(1:min(end,90))]); catch; end;
methods = {'elastix', 'halar', 'grics', 'LAP', 'demons'};
method = methods{handles.h.nRegMethod};
handles.RegMParam = ['Registration Method: ', method];
if isfield(handles.h, 'sParFile')
handles.RegMParam = [handles.RegMParam, ', Parameter: ',handles.h.sParFile];
end
set(handles.tRegMParm, 'String', handles.RegMParam)
set(handles.rb_interpImage,'Value',0);
set(handles.rb_origImage,'Value',1);
handles.cMetrics = {'smi', 'snmi', 'efinfo', 'rmi', 'rnmi', 'tmi', 'tnmi', 'ejp', 'gre', 'finfo', 'mssim', 'cc', 'zcc', 'spr', 'ket', 'mse', 'nmse', ...
'rmse', 'nrmse', 'psnr', 'tam', 'zca', 'zcr', 'mr', 'ssd', 'msd', 'nssd', 'sad', 'zsad', 'lsad', 'mad', 'shd', 'besov'; ...
'Shannon mutual information', 'Shannon normalized mutual information', 'exclusive F-information', 'Renyi mutual information', 'Renyi normalized mutual information', 'Tsallis mutual information', 'Tsallis normalized mutual information', 'energy of joint probability', 'gradient entropy', ...
'F-information measures', 'Mean structural similarity', '(Pearson) cross correlation', 'zero-mean normalized (Pearson) cross correlation', 'Spearman rank correlation', ...
'Kendall''s tau', 'mean squared error', 'normalized mean squared error', 'root mean squared error', 'normalized root mean squared error', 'peak signal to noise ratio', ...
'Tanimoto measure', 'zero crossings (absolute)', 'zero crossings (relative)', 'minimum ratio', 'sum of squared differences', 'median of squared differences', 'normalized sum of squared differences', ...
'sum of absolute differences', 'zero-mean sum of absolute differences', 'locally scaled sum of absolute differences', 'median of absolute differences', 'sum of hamming distance', 'besov norm'};
if(~exist('lEvalMetrics','var'))
handles.lEvalMetrics = logical([0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0]); % default to be evaluated intensity-based metrics
else
handles.lEvalMetrics = lEvalMetrics;
end
% normalize images
handles.h.dImg = handles.h.dImg/max(handles.h.dImg(:));
handles.h.dImgReg = handles.h.dImgReg/max(handles.h.dImgReg(:));
handles = plotImages(handles);
axes(handles.axRefGate);
handles.iActive = 0;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = LandmarkGUI_OutputFcn(~, ~, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
try
if(isfield(handles,'closeFigure') && handles.closeFigure)
LandmarkGUI_CloseRequestFcn(hObject, eventdata, handles)
end
catch
end
function pm_PointsLinesROIs_Callback(hObject, ~, handles)
% select to set points, lines or ROIs
contents = cellstr(get(hObject,'String'));
lead=contents{get(hObject,'value')};
switch lead
case 'Points'
handles.FPointsLines = 1;
set(handles.tb_points,'Data',handles.cTablePoints);
set(handles.pb_clear_set,'String','clear set points');
set(handles.pb_clear_all,'String','clear all points');
case 'Lines'
handles.FPointsLines = 2;
set(handles.tb_points,'Data',handles.cTableLines);
set(handles.pb_clear_set,'String','clear set lines');
set(handles.pb_clear_all,'String','clear all lines');
case 'ROIs'
handles.FPointsLines = 3;
set(handles.tb_points,'Data',handles.cTableROIs);
set(handles.pb_clear_set,'String','clear set ROIs');
set(handles.pb_clear_all,'String','clear all ROIs');
otherwise
error('Unknown error.')
end
guidata(hObject, handles)
function [exchP, newSlice] = pb_set_lmp_Callback(hObject, eventdata, handles)
% set points, lines and ROIs
handles.noScrolling = 1; guidata(hObject, handles);
if handles.setActive
% set landmark points in the reference image (gate 01)
if strcmp(handles.sImageData,'interpImage')
errordlg('Landmark points can only be set in original pixel configuration.')
exchP = []; newSlice = [];
return
end
handles.setActive = 0;
% -------------------------------------------------------------------------
% Depending on selected type of labeling set points, lines or ROIs
% ---------------------------
if handles.FPointsLines == 1
if gca == handles.axRefGate
% delete old plot of landmarks
try delete(handles.reflm); delete(handles.reflmLabel); catch; end;
% set new landmarks with fGetPts
[a, b] = fGetPts(handles.axRefGate);
% get coordinates of pixel
x = floor(a+0.5); y = floor(b+0.5); % +0.5 necessary for centering of pixel
% delete points outside the image borders
A = zeros(length(x),2);
A(:,1) = floor(x);
A(:,2) = floor(y);
A(any(A'<0),:) = [];
A(A(:,1)> size(handles.h.dImg,2),:) = [];
A(A(:,2)> size(handles.h.dImg,1),:) = [];
% if size(A,1) ~= length(x)
% errordlg('There were points outside the image. Please check if the labels correspond correctly.')
% end
x = A(:,1);
y = A(:,2);
% return if no points were selected
if isempty(x)
handles.setActive = 1;
handles.noScrolling = 0;
try handles.xes = rmfield(handles.xes,'G01'); catch; end;
guidata(hObject, handles)
set(handles.tb_points,'Data',handles.cTablePoints);
exchP=[]; newSlice=[];
return;
end
% replace only one point if function is called by the table cell
% selection callback
if handles.exchangePoints == 1
exchP = [x,y];
newSlice = handles.slice;
if size(x,1) > 1
edlg = errordlg('Please set only one new point.');
uiwait(edlg);
handles.setActive = 1;
guidata(hObject, handles);
[exchP, newSlice] = pb_set_lmp_Callback(hObject, eventdata, handles);
end
handles.setActive = 1;
handles.noScrolling = 0;
handles.FCellSelectionActive = 1;
handles.exchangePoints = 0;
guidata(hObject, handles)
set(handles.tb_points,'Data',handles.cTablePoints);
return;
end
% check if number of gates is equal to number of previously set points
% in other gates
if isfield(handles,'xes')
try nPts = length(handles.xes.G02); catch; end;
try nPts = length(handles.xes.G03); catch; end;
try nPts = length(handles.xes.G04); catch; end;
try
if nPts ~= length(x)
errordlg('Please set the same number of points in every gate.')
return
end
catch
end
end
% pass to global handle
handles.xes.G01 = x;
handles.yes.G01 = y;
handles.zes.G01 = handles.slice.*ones(size(x));
% plot new landmarks
axes(handles.axRefGate)
hold on
handles.reflm = plot(x,y,'yx', 'Linewidth', 1.5,'MarkerSize', 5);
labels = cellstr( num2str([1:size(x)]')); % labels corresponding to x,y order
handles.reflmLabel = text(x(:,1), y(:,1), labels,'Color','y', 'VerticalAlignment','bottom', ...
'HorizontalAlignment','right');
hold off
handles.unfixedpoints = 1;
elseif gca == handles.axMovGate
% set landmark points in current moving image (gate 02-04)
% delete old plot of landmarks
try delete(handles.movlm.(handles.names{handles.nMovGate}));
delete(handles.movlmLabel.(handles.names{handles.nMovGate})); catch
end
axMovGate_ButtonDownFcn(hObject, eventdata, handles)
% set new landmarks
[a, b] = fGetPts(handles.axMovGate);
% get coordinates of pixel
x = floor(a+0.5); y = floor(b+0.5);
% delete points outside the image borders
A = zeros(length(x),2);
A(:,1) = x;
A(:,2) = y;
A(any(A'<0),:) = [];
A(A(:,1)> size(handles.h.dImg,2),:) = [];
A(A(:,2)> size(handles.h.dImg,1),:) = [];
% if size(A,1) ~= length(x)
% errordlg('There were points outside the image. Please check if the labels correspond correctly.')
% end
x = A(:,1);
y = A(:,2);
% return if no points were selected
if isempty(a)
handles.setActive = 1;
handles.noScrolling = 0;
try handles.xes = rmfield(handles.xes,handles.names{handles.nMovGate}); catch; end;
guidata(hObject, handles)
set(handles.tb_points,'Data',handles.cTablePoints);
exchP=[]; newSlice=[];
return;
end
% replace only one point if function is called by the table cell
% selection callback
if handles.exchangePoints == 1
exchP = [x,y];
newSlice = handles.slice;
if size(x,1) > 1
edlg = errordlg('Please set only one new point.');
uiwait(edlg);
handles.setActive = 1;
guidata(hObject, handles);
[exchP, newSlice] = pb_set_lmp_Callback(hObject, eventdata, handles);
end
handles.setActive = 1;
handles.noScrolling = 0;
handles.FCellSelectionActive = 1;
handles.exchangePoints = 0;
guidata(hObject, handles)
set(handles.tb_points,'Data',handles.cTablePoints);
return;
end
% check if number of gates is equal to number of previously set points
% in other gates
if isfield(handles,'xes') && ...
any(isfield(handles.xes,handles.names))
% (isfield(handles.xes,'G01') ||isfield(handles.xes,'G02') ||isfield(handles.xes,'G03') ||isfield(handles.xes,'G04'))
for iG=1:length(handles.names)
nPts = [];
try nPts = length(handles.xes.(handles.names{iG})); catch; end;
% try nPts = length(handles.xes.G02); catch; end;
% try nPts = length(handles.xes.G03); catch; end;
% try nPts = length(handles.xes.G04); catch; end;
if(~isempty(nPts) && nPts ~= length(x))
errordlg('Please set the same number of points in every gate.')
handles.setActive = 1;
return
end
end
end
% save in handles
handles.xes.(handles.names{handles.nMovGate}) = x;
handles.yes.(handles.names{handles.nMovGate}) = y;
handles.zes.(handles.names{handles.nMovGate}) = handles.slice.*ones(size(x));
% plot new landmarks
axes(handles.axMovGate)
hold on
handles.movlm.(handles.names{handles.nMovGate}) = plot(x,y,'yx', 'Linewidth', 1.5,'MarkerSize', 5);
labels = cellstr( num2str([1:size(x)]')); % labels corresponding to x,y order
handles.movlmLabel.(handles.names{handles.nMovGate}) =...
text(x(:,1), y(:,1), labels,'Color','y', 'VerticalAlignment','bottom', ...
'HorizontalAlignment','right');
hold off
handles.unfixedpoints = 1;
else
errordlg('Select axes where you want to set points.')
end
% ---------------------------
elseif handles.FPointsLines == 2; % set lines
if gca == handles.axRefGate
if isfield(handles,'hPoly') && isfield(handles.hPoly,'G01')
delete(handles.hPoly.G01) % only one line at a time can be set
end
% -------------------------------------
% set landmark lines in reference image
handles.hPoly.G01 = impoly('Closed',false);
if isempty(handles.hPoly.G01)
handles.hPoly = rmfield(handles.hPoly,'G01');
handles.setActive = 1;
handles.noScrolling = 0;
guidata(hObject, handles)
return
end
setColor(handles.hPoly.G01,'y')
handles.hPolySlice.G01 = handles.slice;
handles.xyPos.G01 = getPosition(handles.hPoly.G01);
handles.unfixedlines = 1;
elseif gca == handles.axMovGate
if isfield(handles,'hPoly') && isfield(handles.hPoly, handles.names{handles.nMovGate})
delete(handles.hPoly.(handles.names{handles.nMovGate})) % only one line at a time can be set
end
% -------------------------------------
% set landmark lines in moving image
handles.hPoly.(handles.names{handles.nMovGate}) = impoly('Closed',false);
if isempty(handles.hPoly.(handles.names{handles.nMovGate}))
handles.hPoly = rmfield(handles.hPoly,handles.names{handles.nMovGate});
handles.setActive = 1;
handles.noScrolling = 0;
guidata(hObject, handles)
return
end
setColor(handles.hPoly.(handles.names{handles.nMovGate}),'y')
handles.hPolySlice.(handles.names{handles.nMovGate}) = handles.slice;
handles.xyPos.(handles.names{handles.nMovGate}) = getPosition(handles.hPoly.(handles.names{handles.nMovGate}));
handles.unfixedlines = 1;
else
errordlg('Select axes where you want to set points.')
end
% ---------------------------
elseif handles.FPointsLines == 3; % set ROIs
if gca == handles.axRefGate
if isfield(handles,'hPolyROI.G01')
delete(handles.hPolyROI.G01) % only one line at a time can be set
end
% -------------------------------------
% set ROI in reference image, polygon is closed at the end
handles.hPolyROI.G01 = impoly('Closed',true);
if isempty(handles.hPolyROI.G01)
handles.hPolyROI = rmfield(handles.hPolyROI,'G01');
handles.setActive = 1;
handles.noScrolling = 0;
guidata(hObject, handles)
return
end
setColor(handles.hPolyROI.G01,'y')
handles.hPolyROISlice.G01 = handles.slice;
handles.xyPosROI.G01 = getPosition(handles.hPolyROI.G01);
handles.unfixedlines = 1;
elseif gca == handles.axMovGate
if isfield(handles,'hPolyROI') && isfield(handles.hPolyROI, handles.names{handles.nMovGate})
delete(handles.hPolyROI.(handles.names{handles.nMovGate})) % only one line at a time can be set
end
% -------------------------------------
% set landmark lines in moving image
handles.hPolyROI.(handles.names{handles.nMovGate}) = impoly('Closed',true);
if isempty(handles.hPolyROI.(handles.names{handles.nMovGate}))
handles.hPolyROI = rmfield(handles.hPolyROI,handles.names{handles.nMovGate});
handles.setActive = 1;
handles.noScrolling = 0;
guidata(hObject, handles)
return
end
setColor(handles.hPolyROI.(handles.names{handles.nMovGate}),'y')
handles.hPolyROISlice.(handles.names{handles.nMovGate}) = handles.slice;
handles.xyPosROI.(handles.names{handles.nMovGate}) = getPosition(handles.hPolyROI.(handles.names{handles.nMovGate}));
handles.unfixedlines = 1;
else
errordlg('Select axes where you want to set points.')
end
else
error('Unknown error.')
end
handles.setActive = 1;
end
handles.noScrolling = 0;
guidata(hObject,handles)
function pb_fix_lmp_Callback(hObject, ~, handles)
% fix the landmark points, lines or ROIs that are set in previous steps
% -------------------------------------------------------------------------
% Depending on selected type of labeling fix points, lines or ROIs
% ---------------------------
if handles.FPointsLines == 1
% check if lmp are set in all 4 gates
try
if ~isfield(handles,'xes')||~isfield(handles.xes,'G01')||~isfield(handles.xes,'G02')||~isfield(handles.xes,'G03')||~isfield(handles.xes,'G04')||~isfield(handles,'xes')
errordlg('Please set corresponding points in all 4 gates.');
return
end
catch
end
% get the positions of all lmps and save them in fix.G0x by concatenation
nmb = (1:size(handles.xes.G01))';
x = handles.xes.G01;
y = handles.yes.G01;
z = handles.zes.G01;
handles.fix.G01 = cat(1,handles.fix.G01,[nmb, x, y, z]);
for iG=2:handles.iNGates
x = handles.xes.(handles.names{iG});
y = handles.yes.(handles.names{iG});
z = handles.zes.(handles.names{iG});
handles.fix.(handles.names{iG}) = cat(1,handles.fix.(handles.names{iG}),[nmb, x, y, z]);
end
% x = handles.xes.G03;
% y = handles.yes.G03;
% z = handles.zes.G03;
% handles.fix.G03 = cat(1,handles.fix.G03,[nmb, x, y, z]);
% x = handles.xes.G04;
% y = handles.yes.G04;
% z = handles.zes.G04;
% handles.fix.G04 = cat(1,handles.fix.G04,[nmb, x, y, z]);
handles = rmfield(handles, {'xes','yes','zes'});
% display plotted points in table
cDataTemp = repmat('x',size(handles.fix.G01,1),4);
handles.cTablePoints = num2cell(cDataTemp);
set(handles.tb_points,'Data',handles.cTablePoints);
handles = fPlotFixedMarker(handles);
% remove the landmark points that are set earlier and delete the plot
try delete(handles.reflm); catch; end;
try delete(handles.reflmLabel); catch; end;
try handles=rmfield(handles,'reflm');catch; end
try handles=rmfield(handles,'reflmLabel');catch; end
for iI = 1:4
try delete(handles.movlm.(handles.names{iI})); catch; end;
try delete(handles.movlmLabel.(handles.names{iI})); catch; end;
try handles=rmfield(handles,movlm.(handles.names{iI}));catch; end
try handles=rmfield(handles,movlmLabel.(handles.names{iI}));catch; end
end
handles.unfixedpoints = 0; % there are no longer unfixed points
% ---------------------------
elseif handles.FPointsLines == 2
% todo:
% % if call from table cell selection put line to correct position in
% % cell array
% try
% if isfield(handles,'lineIndex')
% lineNo = handles.lineIndex;
% if gca == handles.axRefGate; i=1; else i=handles.nMovGate; end
% xyzPoly = [getPosition(handles.hPoly.(handles.names{i})),...
% handles.hPolySlice.(handles.names{i}).*ones(size(getPosition(handles.hPoly.(handles.names{i})),1),1)...
% lineNo.*ones(size(getPosition(handles.hPoly.(handles.names{i})),1),1)];
% xyzPoly = round(xyzPoly);
% if handles.nSCT == 2
% l = 1; m = 3;
% xyzPoly(:,[l,m])= xyzPoly(:,[m,l]);
% elseif handles.nSCT == 3
% l = 2; m = 3;
% xyzPoly(:,[l,m])= xyzPoly(:,[m,l]);
% else
% % do nothing
% end
% % find cell array position for the next coordinates
% b = handles.cPolyCoord.(handles.names{i})(handles.nSCT,:);
% k=1;
% % save coordinates
% handles.cPolyCoord.(handles.names{i}){handles.nSCT,k} = xyzPoly;
% delete(handles.hPoly.(handles.names{i}))
% handles = rmfield(handles, 'lineIndex');
% guidata(hObject, handles);
% return
% end
% catch; 'here';
% end
% save coordinates of the line vertices in a global coordinate system
% x left-right, y head-foot and z anterior-posterior
try
i = 1;
xyzPoly = [getPosition(handles.hPoly.(handles.names{i})),...
handles.hPolySlice.(handles.names{i}).*ones(size(getPosition(handles.hPoly.(handles.names{i})),1),1)...
handles.lineNumber(i).*ones(size(getPosition(handles.hPoly.(handles.names{i})),1),1)];
% xyzPoly = round(xyzPoly);
% increment line number
handles.lineNumber(i) = handles.lineNumber(i)+1;
if handles.nSCT == 2
l = 1; m = 3;
xyzPoly(:,[l,m])= xyzPoly(:,[m,l]);
elseif handles.nSCT == 3
l = 2; m = 3;
xyzPoly(:,[l,m])= xyzPoly(:,[m,l]);
else
% do nothing
end
% find cell array position for the next coordinates
A = cellfun('isempty',handles.cPolyCoord.(handles.names{i}));
b = find(A(handles.nSCT,:)==0,1,'last');
if isempty(b); k=1; else k = 1+b; end
% save coordinates
handles.cPolyCoord.(handles.names{i}){handles.nSCT,k} = xyzPoly;
delete(handles.hPoly.(handles.names{i}))
catch
end
try
i = handles.nMovGate;
xyzPoly = [getPosition(handles.hPoly.(handles.names{i})),...
handles.hPolySlice.(handles.names{i}).*ones(size(getPosition(handles.hPoly.(handles.names{i})),1),1),...
handles.lineNumber(i).*ones(size(getPosition(handles.hPoly.(handles.names{i})),1),1)];
% xyzPoly = round(xyzPoly);
% increment line number
handles.lineNumber(i) = handles.lineNumber(i)+1;
if handles.nSCT == 2
l = 1; m = 3;
xyzPoly(:,[l,m])= xyzPoly(:,[m,l]);
elseif handles.nSCT == 3
l = 2; m = 3;
xyzPoly(:,[l,m])= xyzPoly(:,[m,l]);
else
% do nothing
end
% find cell array position for the next coordinates
A = cellfun('isempty',handles.cPolyCoord.(handles.names{i}));
b = find(A(handles.nSCT,:)==0,1,'last');
if isempty(b); k=1; else k = 1+b; end
% save coordinates
handles.cPolyCoord.(handles.names{i}){handles.nSCT,k} = xyzPoly;
delete(handles.hPoly.(handles.names{i}))
catch
end
try handles = rmfield(handles,'hPoly'); catch; end
handles = fPlotFixedMarker(handles);
handles.unfixedlines = 0;
% display plotted lines in table
for i = 1:size(handles.names,1)
B = cellfun('isempty',handles.cPolyCoord.(handles.names{i}));
numLines(i) = sum(~B(:));
end
cData = repmat('-',max(numLines),handles.iNGates);
for i = 1:size(handles.names,1)
cDataTemp = repmat('L',numLines(i),1);
cData(1:length(cDataTemp),i) = cDataTemp;
end
handles.cTableLines = num2cell(cData);
set(handles.tb_points,'Data',handles.cTableLines);
% ---------------------------
elseif handles.FPointsLines == 3
% save coordinates of the line vertices in a global coordinate system
% x left-right, y head-foot and z anterior-posterior
try
i = 1;
xyzPoly = [getPosition(handles.hPolyROI.(handles.names{i})),...
handles.hPolyROISlice.(handles.names{i}).*ones(size(getPosition(handles.hPolyROI.(handles.names{i})),1),1)...
handles.ROINumber(i).*ones(size(getPosition(handles.hPolyROI.(handles.names{i})),1),1)];
xyzPoly(end+1,:) = xyzPoly(1,:);
xyzPoly = round(xyzPoly);
% increment ROI number
handles.ROINumber(i) = handles.ROINumber(i)+1;
if handles.nSCT == 2
l = 1; m = 3;
xyzPoly(:,[l,m])= xyzPoly(:,[m,l]);
elseif handles.nSCT == 3
l = 2; m = 3;
xyzPoly(:,[l,m])= xyzPoly(:,[m,l]);
else
% do nothing
end
% find cell array position for the next coordinates
A = cellfun('isempty',handles.cPolyROICoord.(handles.names{i}));
b = find(A(handles.nSCT,:)==0,1,'last');
if isempty(b); k=1; else k = 1+b; end
% save coordinates
handles.cPolyROICoord.(handles.names{i}){handles.nSCT,k} = xyzPoly;
delete(handles.hPolyROI.(handles.names{i}))
catch
end
try
i = handles.nMovGate;
xyzPoly = [getPosition(handles.hPolyROI.(handles.names{i})),...
handles.hPolyROISlice.(handles.names{i}).*ones(size(getPosition(handles.hPolyROI.(handles.names{i})),1),1),...
handles.ROINumber(i).*ones(size(getPosition(handles.hPolyROI.(handles.names{i})),1),1)];
xyzPoly(end+1,:) = xyzPoly(1,:);
xyzPoly = round(xyzPoly);
% increment ROI number
handles.ROINumber(i) = handles.ROINumber(i)+1;
if handles.nSCT == 2
l = 1; m = 3;
xyzPoly(:,[l,m])= xyzPoly(:,[m,l]);
elseif handles.nSCT == 3
l = 2; m = 3;
xyzPoly(:,[l,m])= xyzPoly(:,[m,l]);
else
% do nothing
end
% find cell array position for the next coordinates
A = cellfun('isempty',handles.cPolyROICoord.(handles.names{i}));
b = find(A(handles.nSCT,:)==0,1,'last');
if isempty(b); k=1; else k = 1+b; end
% save coordinates
handles.cPolyROICoord.(handles.names{i}){handles.nSCT,k} = xyzPoly;
delete(handles.hPolyROI.(handles.names{i}))
catch
end
try handles = rmfield(handles,'hPolyROI'); catch; end
handles = fPlotFixedMarker(handles);
handles.unfixedlines = 0;
% display plotted ROIs in table
for i = 1:size(handles.names,1)
B = cellfun('isempty',handles.cPolyROICoord.(handles.names{i}));
numLines(i) = sum(~B(:));
end
cData = repmat('-',max(numLines),handles.iNGates);
for i = 1:size(handles.names,1)
cDataTemp = repmat('R',numLines(i),1);
cData(1:length(cDataTemp),i) = cDataTemp;
end
handles.cTableROIs = num2cell(cData);
set(handles.tb_points,'Data',handles.cTableROIs);
else
error('Unknown error!')
end
guidata(hObject, handles)
function cmp_lmp_Callback(~, ~, handles)
% start comparing set points, lines and ROIs
if handles.nSCT ~= 1
warning('Computation will be performed in coronal view.');
set(handles.pm_CorSagTrans,'Value',1); % coronal view
handles.unfixedlines = 0;
pm_CorSagTrans_Callback(hObject, [], handles);
end
if size(handles.fix.G01)==[0,0]
errordlg('There are no fixed points to compare. Please set and fix landmarkpoints first.')
return;
else
dVoxSz = handles.h.SGeo.cVoxelsize;
% get the coordinates of the fixed points that shall be compared
for iG=1:handles.iNGates
eval(sprintf('G%02d = handles.fix.G%02d; x%02d = G%02d(:,2); y%02d = G%02d(:,3); z%02d = G%02d(:,4);', iG*ones(1,8)));
end
% G02 = handles.fix.G02; x02 = G02(:,2); y02 = G02(:,3); z02 = G02(:,4);
% G03 = handles.fix.G03; x03 = G03(:,2); y03 = G03(:,3); z03 = G03(:,4);
% G04 = handles.fix.G04; x04 = G04(:,2); y04 = G04(:,3); z04 = G04(:,4);
if strcmp(handles.sImageData, 'origImage')
% transform the coordinates of the moving images according to
% registration result
for iI = 2:4
dBx(:,:,:,iI) = handles.h.SDeform(iI).dBx;
dBy(:,:,:,iI) = handles.h.SDeform(iI).dBy;
dBz(:,:,:,iI) = handles.h.SDeform(iI).dBz;
end
for iG=2:handles.iNGates
for i = 1:length(x02)
eval(sprintf('x%02dn(i) = x%02d(i) + dBx(x%02d(i),y%02d(i),z%02d(i),iG);', iG*ones(1,5)));
eval(sprintf('y%02dn(i) = y%02d(i) + dBy(x%02d(i),y%02d(i),z%02d(i),iG);', iG*ones(1,5)));
eval(sprintf('z%02dn(i) = z%02d(i) + dBz(x%02d(i),y%02d(i),z%02d(i),iG);', iG*ones(1,5)));
end
end
else
for iG=2:handles.iNGates
eval(sprintf('x%02dn=x%02d'';y%02dn=y%02d'';z%02dn=z%02d'';', iG*ones(1,6)));
end
end
cPoints = cell(2,handles.iNGates-1); % mean+std x images
for iG=2:handles.iNGates
% compute the euclidean distance
eval(sprintf('dist01%02d = sqrt(((x01*dVoxSz{1}(1)-x%02dn''*dVoxSz{iG}(1))).^2+((y01*dVoxSz{1}(2)-y%02dn''*dVoxSz{iG}(2))).^2+((z01*dVoxSz{1}(3)-z%02dn''*dVoxSz{iG}(3))).^2);', iG*ones(1,4)));
eval(sprintf('cPoints{1,iG-1} = mean(dist01%02d);', iG));
eval(sprintf('cPoints{2,iG-1} = std(dist01%02d);', iG));
end
end
% open figure for outputting results
if(isfield(handles, 'cPolyCoord'))
[xline, yline] = find(~cellfun(@isempty,handles.cPolyCoord.G01));
iNLinePlots = size(xline,1);
clear 'xline' 'yline';
else
iNLinePlots = 0;
end
if(isfield(handles,'cPolyROICoord'))
[xline, yline] = find(~cellfun(@isempty,handles.cPolyROICoord.G01));
iNROIPlots = size(xline,1);
clear 'xline' 'yline';
else
iNROIPlots = 0;
end
iSimMetrics = get(handles.cbMetrics,'Value');
iNPlots = [handles.iNGates-1, iNLinePlots, iNROIPlots, iSimMetrics];
[hfInsertPoint, hfInsertLineROI, hfPlotLabel, hfPlotMetrics] = fLandmarkCompare(iNPlots, dVoxSz{1});
for iG=2:handles.iNGates
hfInsertPoint([cPoints{1,iG-1},cPoints{2,iG-1}],iG);
end
if isfield(handles,'cPolyCoord')
if strcmp(handles.sImageData, 'origImage')
results.cLines = handles.cPolyCoord;
[diceLine,diceLine0,diceLine1] = fCompareLines(handles.h,results,{hfInsertLineROI, hfPlotLabel}, handles.names, handles.iNGates);
else
results.cLines = handles.cPolyCoord;
[diceLine,diceLine0,diceLine1] = fCompareLinesNoTr(handles.h,results,{hfInsertLineROI, hfPlotLabel}, handles.names, handles.iNGates);
end
else
warning('There are no lines to compare.')
end
if isfield(handles,'cPolyROICoord')
if strcmp(handles.sImageData, 'origImage')
results.cROIs = handles.cPolyROICoord;
diceROI = fCompareROIs(handles.h,results,{hfInsertLineROI, hfPlotLabel}, handles.names, handles.iNGates);
if(iSimMetrics > 0)
cString = handles.cMetrics(1,handles.lEvalMetrics).';
metricsROI = fMetricROIs(handles.h,results,hfPlotMetrics, handles.names, handles.iNGates, cString, true);
end
else
results.cROIs = handles.cPolyROICoord;
diceROI = fCompareROIsNoTr(handles.h,results,{hfInsertLineROI, hfPlotLabel}, handles.names, handles.iNGates);
if(iSimMetrics > 0)
cString = handles.cMetrics(1,handles.lEvalMetrics).';
metricsROI = fMetricROIs(handles.h,results,hfPlotMetrics, handles.names, handles.iNGates, cString, false);
end
end
else
warningdlg('There are no ROIs to compare.')
end
try results.EuclidDist = cPoints; catch; end;
try results.diceLine0 = diceLine0; catch; end;
try results.diceLine1 = diceLine1; catch; end;
try results.diceLine = diceLine; catch; end;
try results.diceROI = diceROI; catch; end;
try results.metricsROI = metricsROI; catch; end;
isSave = questdlg('Do you want to save the feature-based results?', 'Save results', 'Yes', 'No','No');
switch isSave
case 'Yes'
case 'No'
return
case ''
return
end
methods = {'elastix', 'halar', 'grics', 'lap', 'demons'};
sMethod = methods{handles.h.nRegMethod};
if(~isfield(handles,'SPaths'))
[sFilename,sPathname] = uiputfile([pwd,filesep,'LandmarkResult.mat'],'Specify file name');
else
sSavename = [handles.SPaths.sResults,sMethod,filesep,'LandmarkResult.mat'];
[sFilename,sPathname] = uiputfile(sSavename,'Specify file name');
end
% [sFilename,sPathname] = uiputfile([handles.SPaths.sResults,sMethod,'*.mat'],'Specify file name');
if sFilename == 0; return; end;
save([sPathname, sFilename],'results')
msgbox('Saved results.', 'Save complete.','help')
function pb_nxt_img_Callback(hObject, ~, handles)
% get next image in moving image axes (right image)
% handles.nMovGate = mod(handles.nMovGate+2,3)+2; % is 2,3,4,2,3,4,..
handles.nMovGate = handles.nMovGate + 1;
if(handles.nMovGate > handles.iNGates), handles.nMovGate = 2; end;
% flush image handle in order to force a new drawing (otherwise currently to
% be set but not fixed points will occur in the next image)
delete(handles.hI2); handles.hI2 = [];
handles = showMovImage(handles);
guidata(hObject, handles)
function pb_pre_img_Callback(hObject, ~, handles)
% get previous image in moving image axes (right image)
% handles.nMovGate = mod(handles.nMovGate+3,3)+2; % is 4,3,2,4,3,2,..
handles.nMovGate = handles.nMovGate - 1;
if(handles.nMovGate < 2), handles.nMovGate = handles.iNGates; end;
% flush image handle in order to force a new drawing (otherwise currently to
% be set but not fixed points will occur in the next image)
delete(handles.hI2); handles.hI2 = [];
handles = showMovImage(handles);
guidata(hObject, handles)
function LandmarkGUI_KeyPressFcn(hObject, eventdata, handles)
% collect figure key press events
if eventdata.Key == 's'
pb_set_lmp_Callback(hObject,eventdata,handles);
elseif eventdata.Key == 'f'
pb_fix_lmp_Callback(hObject, eventdata, handles);