-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathreportflow.m
1520 lines (1343 loc) · 51.6 KB
/
reportflow.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] = reportflow(varargin)
%GUI for flow analysis.
%Adapted for use with mygui class by Nils Lundahl
macro_helper(varargin{:});
if nargin == 0 || isempty(varargin{1})
varargin{1} = 'init';
elseif strncmp(varargin{1},'get',3)
[varargout{1:nargout}] = feval('getdata',varargin{:});
return
end
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
%-------------------------
function resampedit_Callback
%-------------------------
global DATA
gui = DATA.GUI.Flow;
[temp,ok] = str2num(mygetedit(gui.handles.resampedit)); %#ok<ST2NM>
if not(ok)
disp('Illegal value');
else
gui.resampsize = temp;
end
%----------------------------
function resampreset_Callback %#ok<DEFNU>
%----------------------------
global NO
%Recalculate to get correct flow
init(NO);
%-------------------------
function resamp_Callback %#ok<DEFNU>
%-------------------------
global DATA SET NO
no = NO;
gui = DATA.GUI.Flow;
gui.resamped = 0;
init(no); %get real values from recalc everytime!
numrois = gui.numrois;
t = gui.t;
size(t)
if ~isempty(gui.resampsize)
TSize2 = gui.resampsize;
else
disp('TSize2 error');
TSize2 = 5;
end
%create new data structures
newnetflow = NaN(TSize2, numrois);
newvelmean = newnetflow;
newvelstd = newnetflow;
newvelmax = newnetflow;
newvelmin = newnetflow;
newkenergy = newnetflow;
newarea = newnetflow;
newposflow = newnetflow;
newnegflow = newnetflow;
for loop=1:numrois
[newt, newy] = calcfunctions('resamplemodel',t',gui.netflow(:,loop),TSize2);
newnetflow(:,loop) = newy;
[~, newy] = calcfunctions('resamplemodel',t',gui.velmean(:,loop),TSize2);
newvelmean(:,loop) = newy;
[~, newy] = calcfunctions('resamplemodel',t',gui.velstd(:,loop),TSize2);
newvelstd(:,loop) = newy;
[~, newy] = calcfunctions('resamplemodel',t',gui.velmax(:,loop),TSize2);
newvelmax(:,loop) = newy;
[~, newy] = calcfunctions('resamplemodel',t',gui.velmin(:,loop),TSize2);
newvelmin(:,loop) = newy;
[~, newy] = calcfunctions('resamplemodel',t',gui.kenergy(:,loop),TSize2);
newkenergy(:,loop) = newy;
[~, newy] = calcfunctions('resamplemodel',t',gui.area(:,loop),TSize2);
newarea(:,loop) = newy;
[~, newy] = calcfunctions('resamplemodel',t',gui.posflow(:,loop),TSize2);
newposflow(:,loop) = newy;
[~, newy] = calcfunctions('resamplemodel',t',gui.negflow(:,loop),TSize2);
newnegflow(:,loop) = newy;
end
%assignment time:
gui.t = newt';
gui.velmean = newvelmean;
gui.velstd = newvelstd;
gui.velmax = newvelmax;
gui.velmin = newvelmin;
gui.kenergy = newkenergy;
gui.area = newarea;
gui.netflow = newnetflow;
gui.posflow = newposflow;
gui.negflow = newnegflow;
%Calculate diameter equivalent
gui.diameter = 2*10*sqrt(gui.area/pi); %mm*10 => cm
nom = SET(no).Flow.MagnitudeNo;
%backup variables:
gui.TIncr = ((SET(nom).TSize-1)*SET(nom).TIncr)/(TSize2-1);
gui.tsize = TSize2;
gui.resamped = 1;
recalculate(no); %Also do an update
% gui.resamped = 0;
segment('updateflow'); %DATA.updateaxestables('flow',nom,nop); %maybe unnecessary?
%---------------------------------
function ok = init(no,eddycheck, invisible)
%---------------------------------
%Init flow report GUI
global DATA SET NO
ok = false; %inform if unable to launch GUI
if nargin<1
no=NO;
end
if nargin<2
eddycheck = true;
end
if nargin<3
invisible = false;
end
if isempty(SET(no).Flow)
myfailed('No flow data in current image stack.',DATA.GUI.Segment);
return;
end
if ~isempty(SET(no).Flow)
nom = SET(no).Flow.MagnitudeNo;
else
return;
end
if isempty(SET(nom).Flow.PhaseNo)
myfailed('No through plane velocity data found.',DATA.GUI.Segment);
return;
end
if SET(nom).RoiN==0
myfailed('No ROIs available.',DATA.GUI.Segment);
return;
end
tempnos=[SET(no).Flow.MagnitudeNo SET(no).Flow.PhaseNo];
imissingle=classcheckim(tempnos);%checks so that SET(tempnos).IM is single and can also convert from int16 to singel if user wants
if not(imissingle)
disp('non single image')
return;
end
if ~DATA.Silent
viewfunctions('switchimagestack',nom)
end
if isempty(SET(nom).EndAnalysis)
SET(nom).EndAnalysis = SET(nom).TSize;
end
if isempty(SET(nom).StartAnalysis)
SET(nom).StartAnalysis = 1;
end
if (SET(nom).EndAnalysis-SET(nom).StartAnalysis) ==0
if ~isopengui('flowonetimephase.fig')
if invisible
gui = mygui('flowonetimephase.fig','invisible');
else
gui = mygui('flowonetimephase.fig');
end
DATA.GUI.Flow = gui;
else
gui = DATA.GUI.Flow;
end
%Calculate number of ROI's
rois2take = [];
for loop=1:SET(nom).RoiN
% if sum(~isnan(SET(nom).Roi(loop).X(1,:)))>1
%More than one timeframe
rois2take = [rois2take loop]; %#ok<AGROW>
% end;
end
gui.rois2take = rois2take;
gui.numrois = length(rois2take);
gui.nom = nom;
%gui.nop = nop;
showflowroidata(no,0);
elseif (SET(nom).EndAnalysis-SET(nom).StartAnalysis)<0 %1
myfailed('No timespan, adjust Start/End analysis time (under stress menu or drag red bar).',DATA.GUI.Segment);
return;
else
nop = SET(nom).Flow.PhaseNo;
if not(isrectilinear(SET(nom).TimeVector))
switch mymenu(['Non uniform time steps detected. This is not '...
'supported for flow calculations. Will use mean time step.'],...
'Accept for now',...
'Accept and apply to stack',...
'Cancel')
case 2
SET(nom).TimeVector = SET(nom).TIncr*(0:SET(nom).TSize-1);
SET(nop).TimeVector = SET(nom).TimeVector;
case 3
return
end
end
%Automatically perform Eddy current. Added Einar Heiberg
if eddycheck
if isfield(SET(nom).Flow,'PhaseCorrAsk') && SET(nom).Flow.PhaseCorrAsk == false
%do not ask if perform eddy current
else
if ~isequal(SET(nom).Scanner,'Philips')
%Only perform for other scanners than Philips
try
if isempty(SET(nop).Flow.PhaseCorr)
plotonok = true;
floweddycurrent('initsmall',plotonok); %When specifying plotonok, then this function is called again when user press ok.
return;
end
catch %Do point of crasch if we can't perform
end
end
end
end
%Calculate number of ROI's
rois2take = [];
for loop=1:SET(nom).RoiN
if sum(~isnan(SET(nom).Roi(loop).X(1,:)))>1
%More than one timeframe
rois2take = [rois2take loop]; %#ok<AGROW>
end
end
if isempty(rois2take)
return
end
%Open GUI
if ~isopengui('flow.fig')
if invisible
gui = mygui('flow.fig','invisible');
else
gui = mygui('flow.fig');
end
DATA.GUI.Flow = gui;
else
gui = DATA.GUI.Flow;
end
set(gui.fig,'Name',dprintf('Flow report'));
gui.outsize = [SET(nom).XSize SET(nom).YSize];
if not(isfield(SET(nom).Flow,'HeartRate')) || isempty(SET(nom).Flow.HeartRate)
temphr = (60/(SET(nom).TSize*SET(nom).TIncr));
if temphr < 35
defineheartrate(nom);
else
SET(nom).Flow.HeartRate = temphr;
end
segment('updateflow'); %update result panel
end
gui.hr = SET(nom).Flow.HeartRate;
set(gui.handles.heartratetext,'String',dprintf('Heart rate: %0.3g [bpm]',gui.hr));
if not(isfield(SET(nop).Flow,'PhaseCorr'))
SET(nop).Flow.PhaseCorr = [];
end
gui.t = SET(nom).TIncr*(-1+(1:SET(nom).TSize));
gui.d = '.';
gui.dt = 9;
gui.nom = nom;
gui.nop = nop;
% % % %Calculate number of ROI's
% % % rois2take = [];
% % % for loop=1:SET(nom).RoiN
% % % if sum(~isnan(SET(nom).Roi(loop).X(1,:)))>1
% % % %More than one timeframe
% % % rois2take = [rois2take loop]; %#ok<AGROW>
% % % end
% % % end
% % % if isempty(rois2take)
% % % return
% % % end
gui.rois2take = rois2take;
gui.numrois = length(rois2take);
%new variables for internal sampling of data: only for use in resampling
gui.TIncr = [];
gui.tsize = [];
gui.resamped = 0;
resampedit_Callback;
recalculate(no);
ok = true;
set(gui.fig,'pointer','arrow');
end
%---------------------------
function defineheartrate(no)
%---------------------------
%Ask user to manually define the heart reate by giving the number of heart
%beats
global SET DATA NO
if nargin < 1
no = NO;
end
temphr = (60/(SET(no).TSize*SET(no).TIncr));
%assume real time flow, aks user to define number of hearts beat
[nbrheartbeats,ok] = mygetnumber('Enter number of heart beats (decimal with .)', 'Heart beats',1.0,0,[]);
if not(ok)
myfailed('Invalid number of heart beats or aborted.');
return;
end
if ~isempty(nbrheartbeats) && nbrheartbeats > 0 && isnumeric(nbrheartbeats)
SET(no).Flow.HeartRate = nbrheartbeats*temphr;
else
myfailed('Incorrect input value for number of heart beats, using 1',DATA.GUI.Segment);
SET(no).Flow.HeartRate = temphr;
end
mymsgbox(dprintf('The heart rate is now set to %0.3g',SET(no).Flow.HeartRate),'Heart rate',DATA.GUI.Segment);
if nargin < 1
segment('updateflow'); %update result panel
end
%-----------------------
function showflowroidata(no,flag)
%-----------------------
%To display flow (cm/s) from ROI's for non-time resolved Contrast Phase
%Images
global DATA SET
gui = DATA.GUI.Flow;
nom = gui.nom;
%nop = gui.nop;
rois2take = gui.rois2take;
numrois = gui.numrois;
%SET(no).Flow.Result(roinbr)
if isempty(SET(no).Flow.Result)
close_Callback
return
end
if flag == 0
%Calculate Flow
gui.netflow = zeros(1,numrois);
gui.posflow = zeros(1,numrois);
gui.negflow = zeros(1,numrois);
gui.velmean = zeros(1,numrois);
gui.velstd = zeros(1,numrois);
gui.velmax = zeros(1,numrois);
gui.velmin = zeros(1,numrois);
gui.roiname = cell(1,numrois);
gui.roinbr = zeros(1,numrois);
gui.kenergy=0;
gui.area=zeros(1,numrois);
gui.volstri = dprintf('Roi-Name\tTotal vol\tForward vol\tBackward vol\n');
line = 3;
for rloop=1:numrois
%--- Interpolate up
%Sum
gui.netflow(rloop) = SET(no).Flow.Result(rloop).netflow;
gui.posflow(rloop) = SET(no).Flow.Result(rloop).posflow;
gui.negflow(rloop) = SET(no).Flow.Result(rloop).negflow;
gui.velmean(rloop) = SET(no).Flow.Result(rloop).velmean;
gui.velstd(rloop) = SET(no).Flow.Result(rloop).velstd;
gui.velmax(rloop) = SET(no).Flow.Result(rloop).velmax;
gui.velmin(rloop) = SET(no).Flow.Result(rloop).velmean;
gui.area(rloop) =SET(no).Flow.Result(rloop).area;
%Add to stri
gui.volstri = [gui.volstri sprintf('%s\t%0.4g\t%0.4g\t%0.4g\n',...
SET(nom).Roi(rois2take(rloop)).Name,...
gui.netflow(rloop),...
gui.posflow(rloop),...
gui.negflow(rloop))];
% gui.voltext = [gui.voltext dprintf('ROI: %s:\nNet: %0.3g ml\nNet: %0.3g l/min\nForward: %0.3g ml\nBackward: %0.3g ml\nRegurgitant fraction: %0.3g%%\n\n',...
% SET(nom).Roi(rois2take(rloop)).Name,...
% gui.nettotvol(rloop),...
% gui.nettotvol(rloop)*gui.hr/1000,...
% gui.netforwardvol(rloop),...
% gui.netbackwardvol(rloop),...
% abs(100*gui.netbackwardvol(rloop)/gui.netforwardvol(rloop)))];
gui.voltext{line} = dprintf('ROI: %s:',SET(nom).Roi(rois2take(rloop)).Name);
gui.voltext{line+1} = dprintf('Net Flow: %0.3g ml/s',gui.netflow(rloop));
gui.voltext{line+2} = dprintf('Pos Flow: %0.3g ml/s',gui.posflow(rloop));
gui.voltext{line+3} = dprintf('Neg Flow: %0.3g ml/s',gui.negflow(rloop));
gui.voltext{line+4} = dprintf('Mean Vel: %0.3g cm/s',gui.velmean(rloop));
gui.voltext{line+5} = dprintf('Std Vel: %0.3g cm/s',gui.velstd(rloop));
gui.voltext{line+6} = dprintf('Max Vel: %0.3g cm/s',gui.velmax(rloop));
gui.voltext{line+7} = dprintf('Min Vel: %0.3g cm/s',gui.velmin(rloop));
gui.voltext{line+8} = dprintf('ROI Area: %0.3g cm^2',gui.area(rloop));
line = line+10;
end
else
line = 3;
for rloop=1:numrois
%--- Interpolate up
%Add to stri
gui.volstri = [gui.volstri sprintf('%s\t%0.4g\t%0.4g\t%0.4g\n',...
SET(nom).Roi(rois2take(rloop)).Name,...
gui.netflow(rloop),...
gui.posflow(rloop),...
gui.negflow(rloop))];
% gui.voltext = [gui.voltext dprintf('ROI: %s:\nNet: %0.3g ml\nNet: %0.3g l/min\nForward: %0.3g ml\nBackward: %0.3g ml\nRegurgitant fraction: %0.3g%%\n\n',...
% SET(nom).Roi(rois2take(rloop)).Name,...
% gui.nettotvol(rloop),...
% gui.nettotvol(rloop)*gui.hr/1000,...
% gui.netforwardvol(rloop),...
% gui.netbackwardvol(rloop),...
% abs(100*gui.netbackwardvol(rloop)/gui.netforwardvol(rloop)))];
gui.voltext{line} = dprintf('ROI: %s:',SET(nom).Roi(rois2take(rloop)).Name);
gui.voltext{line+1} = dprintf('Net Flow: %0.3g cm/s',gui.netflow(rloop));
gui.voltext{line+2} = dprintf('Pos Flow: %0.3g cm/s',gui.posflow(rloop));
gui.voltext{line+3} = dprintf('Neg Flow: %0.3g cm/s',gui.negflow(rloop));
gui.voltext{line+4} = dprintf('Mean Vel: %0.3g cm/s',gui.velmean(rloop));
gui.voltext{line+5} = dprintf('Std Vel: %0.3g cm/s',gui.velstd(rloop));
gui.voltext{line+6} = dprintf('Max Vel: %0.3g cm/s',gui.velmax(rloop));
gui.voltext{line+7} = dprintf('Min Vel: %0.3g cm/s',gui.velmin(rloop));
gui.voltext{line+8} = dprintf('ROI Area: %0.3g cm2',gui.area(rloop));
line = line+10;
end
end
set(gui.handles.volumelistbox,'String',gui.voltext);
%-----------------------
function recalculate(no)
%-----------------------
%Calculate flow data
global DATA SET
gui = DATA.GUI.Flow;
nom = gui.nom;
nop = gui.nop;
if gui.rois2take ~= SET(nom).RoiN
% Check if the number of time resolvedof ROIs has been updated outside the figure
rois2take = [];
for loop = 1:SET(nom).RoiN
if sum(~isnan(SET(nom).Roi(loop).X(1,:)))>1
%More than one timeframe
rois2take = [rois2take loop]; %#ok<AGROW>
end
end
if ~isempty(rois2take)
gui.rois2take = rois2take;
gui.numrois = length(rois2take);
else
return
end
end
rois2take = gui.rois2take;
numrois = gui.numrois;
calcfunctions('calcflow',no);
if (~gui.resamped)
gui.velmean = NaN(SET(nom).TSize,numrois);
gui.velstd = gui.velmean;
gui.velmax = gui.velmean;
gui.velmin = gui.velmean;
gui.kenergy = gui.velmean;
gui.area = gui.velmean;
gui.netflow = gui.velmean;
gui.posflow = gui.velmean;
gui.negflow = gui.velmean;
gui.phasecorrstring = '';
if ~isempty(SET(nop).Flow.PhaseCorr)
if ~isfield(SET(nop).Flow,'PhaseCorrTimeResolved')
mywarning('Incompatible eddy current correction. Correction reset.',DATA.GUI.Segment);
SET(nop).Flow.PhaseCorr = [];
gui.phasecorrstring = '';
else
if SET(nop).Flow.PhaseCorrTimeResolved
gui.phasecorrstring = dprintf('[Time-resolved eddy current compensation applied]');
else
gui.phasecorrstring = dprintf('[Stationary eddy current compensation applied]');
end
end
end
warnedempty = false;
h = mywaitbarstart(numrois,'Please wait, calculating flow.');
for rloop = 1:numrois
for tloop = SET(nom).Roi(rois2take(rloop)).T
%Create mask
mask = logical(segment('createmask',...
gui.outsize,...
SET(nom).Roi(rois2take(rloop)).Y(:,tloop),...
SET(nom).Roi(rois2take(rloop)).X(:,tloop)));
%Extract phase image
temp = SET(nop).IM(:,:,tloop,SET(nom).Roi(rois2take(rloop)).Z);
%If empty phasecorr, the do not add phase correction.
if isempty(SET(nop).Flow.PhaseCorr)
veldata = SET(nom).Roi(rois2take(rloop)).Sign*...
(temp-0.5)*2*SET(nop).VENC;
else
%Phase correction
if SET(nop).Flow.PhaseCorrTimeResolved
%Time resolved phase correction
veldata = SET(nom).Roi(rois2take(rloop)).Sign*...
(temp-0.5-SET(nop).Flow.PhaseCorr(:,:,tloop,SET(nom).Roi(rois2take(rloop)).Z))*2*SET(nop).VENC;
else
%Stationary phase correction
veldata = SET(nom).Roi(rois2take(rloop)).Sign*...
(temp-0.5-SET(nop).Flow.PhaseCorr(:,:,1,SET(nom).Roi(rois2take(rloop)).Z))*2*SET(nop).VENC;
end
end
veldata = veldata(mask);
if isempty(veldata)
if not(warnedempty)
mywarning('Empty ROI detected. Should not occur.',DATA.GUI.Segment);
end
warnedempty = true;
else
%Okej to go
posveldata = veldata(veldata>0);
negveldata = veldata(veldata<0);
gui.velmean(tloop,rloop) = mean(veldata);
gui.velstd(tloop,rloop) = std(veldata);
gui.velmax(tloop,rloop) = max(veldata);
gui.velmin(tloop,rloop) = min(veldata);
gui.kenergy(tloop,rloop) = sum((veldata/100).^3/2*(SET(nom).ResolutionX*SET(nom).ResolutionY/1e6)*1060); %kg/m^3
gui.area(tloop,rloop) = SET(nom).ResolutionX*SET(nom).ResolutionY*sum(mask(:))/100; %cm^2
gui.netflow(tloop,rloop) = (10/1000)*SET(nom).ResolutionX*SET(nom).ResolutionY*sum(veldata); %cm^3
gui.posflow(tloop,rloop) = (10/1000)*SET(nom).ResolutionX*SET(nom).ResolutionY*sum(posveldata); %cm^3
gui.negflow(tloop,rloop) = (10/1000)*SET(nom).ResolutionX*SET(nom).ResolutionY*sum(negveldata); %cm^3
end
end
h = mywaitbarupdate(h);
end
mywaitbarclose(h);
timeframes = SET(nom).StartAnalysis:SET(nom).EndAnalysis;
%Calculate diameter equivalent
gui.diameter = 2*10*sqrt(gui.area/pi); %mm*10 => cm
TIncr = SET(nom).TIncr;
TSize = SET(nom).TSize;
else
gui.phasecorrstring = '';
% StartAnalysis = 1;
% EndAnalysis = length(gui.t);
timeframes = 1:gui.tsize;
TIncr = gui.TIncr;
TSize = gui.tsize;
end
if (isempty(TIncr) || isempty(TSize))
disp('TIncr or TSize structures are empty due to resampling error or bad SET!');
end
gui.volstri = dprintf('Roi-Name\tTotal vol\tForward vol\tBackward vol\n');
gui.voltext{1} = dprintf('Time between green bars:%d ms\n\n',...
round(1000*TIncr*(length(timeframes)-1)));
%--------------------------------------------------------------------------
%Calculate stroke volume
gui.nettotvol = zeros(1,numrois);
gui.nettotposvol = zeros(1,numrois);
gui.nettotnegvol = zeros(1,numrois);
gui.netforwardvol = zeros(1,numrois);
gui.netbackwardvol = zeros(1,numrois);
gui.meanflow = zeros(1,numrois);
gui.maxflow = zeros(1,numrois);
gui.maxmaxvel = zeros(1,numrois);
gui.roiname = cell(1,numrois);
gui.roinbr = zeros(1,numrois);
gui.hr = (60/(TSize*TIncr));
line = 3;
for rloop=1:numrois
%--- Interpolate up
%Sum
gui.nettotvol(rloop) = nansum(gui.netflow(timeframes,rloop))*TIncr;
gui.nettotposvol(rloop) = nansum(gui.posflow(timeframes,rloop))*TIncr;
gui.nettotnegvol(rloop) = nansum(gui.negflow(timeframes,rloop))*TIncr;
gui.netforwardvol(rloop) = nansum(...
gui.netflow(timeframes,rloop).*(gui.netflow(timeframes,rloop)>0))*TIncr;
gui.netbackwardvol(rloop) = nansum(...
gui.netflow(timeframes,rloop).*(gui.netflow(timeframes,rloop)<0))*TIncr;
gui.roiname{rloop}=SET(nom).Roi(rois2take(rloop)).Name;
gui.roinbr(rloop)=rois2take(rloop);
gui.sv(rloop)=gui.nettotvol(rloop)/gui.hr*60;
gui.meanflow(rloop)=nansum(gui.netflow(timeframes,rloop))/length(timeframes)*60/1000;
gui.maxflow(rloop)=max(gui.netflow(:,rloop))*60/1000;
gui.maxmaxvel(rloop)=max(gui.velmax(:,rloop));
gui.meanmeanvel(rloop)=mynanmean(gui.velmean(:,rloop));
%Add to stri
gui.volstri = [gui.volstri sprintf('%s\t%0.4g\t%0.4g\t%0.4g\n',...
SET(nom).Roi(rois2take(rloop)).Name,...
gui.nettotvol(rloop),...
gui.netforwardvol(rloop),...
gui.netbackwardvol(rloop))];
% gui.voltext = [gui.voltext dprintf('ROI: %s:\nNet: %0.3g ml\nNet: %0.3g l/min\nForward: %0.3g ml\nBackward: %0.3g ml\nRegurgitant fraction: %0.3g%%\n\n',...
% SET(nom).Roi(rois2take(rloop)).Name,...
% gui.nettotvol(rloop),...
% gui.nettotvol(rloop)*gui.hr/1000,...
% gui.netforwardvol(rloop),...
% gui.netbackwardvol(rloop),...
% abs(100*gui.netbackwardvol(rloop)/gui.netforwardvol(rloop)))];
gui.voltext{line} = dprintf('ROI: %s:',SET(nom).Roi(rois2take(rloop)).Name);
gui.voltext{line+1} = dprintf('Net vol: %0.3g ml',gui.nettotvol(rloop));
gui.voltext{line+2} = dprintf('Forward: %0.3g ml',gui.netforwardvol(rloop));
gui.voltext{line+3} = dprintf('Backward: %0.3g ml',gui.netbackwardvol(rloop));
gui.voltext{line+4} = dprintf('Regurgitant fraction: %0.3g%%',abs(100*gui.netbackwardvol(rloop)/gui.netforwardvol(rloop)));
gui.voltext{line+5} = dprintf('FlowCO: %0.3g l/min',gui.nettotvol(rloop)*gui.hr/1000);
line = line+7;
end
set(gui.handles.volumelistbox,'String',gui.voltext);
set(gui.fig,'pointer','arrow');
update(nom); %Also do an update
exporttosetstruct;
for loop = 1:SET(nom).RoiN
SET(nom).RoiCurrent = loop;
calcfunctions('calcflow',nom);
end
segment('updateflow'); %DATA.updateaxestables('flow',nom,nop);
grid(gui.handles.plotaxes,'on');
gui.handles.plotaxes.GridColor = 'k';
set(gui.handles.plotaxes,'Color',[0.94 0.94 0.94]);
%---------------------
function zoom_Callback %#ok<DEFNU>
%---------------------
%Callback for checkbox toggling zoom on/off
global DATA
gui = DATA.GUI.Flow;
if isequal(get(gui.handles.zoomcheckbox,'value'),1)
h=zoom(gui.fig);
set(h,'enable','on');
else
h=zoom(gui.fig);
set(h,'enable','off');
end
%--------------------------------
function varargout = getdata(arg)
%--------------------------------
%Output requested data from flow calculations
global DATA
gui = DATA.GUI.Flow;
varargout = cell(1,nargout); %initialise as empty
value = [];
switch arg
case 'getalldata'
value = gui;
case 'gettotal'
value = gui.nettotvol;
case 'getfwdflow'
value = gui.netforwardvol;
case 'getbwdflow'
value = gui.netbackwardvol;
case 'getmeanflow'
value = mean(gui.netflow);
case 'getpeakflow'
value = max(gui.netflow);
case 'getvelocity'
value = gui.velmean;
case 'getmeanvelocity'
value = mean(gui.velmean,1);
case 'getpeakvelocity'
value = max(gui.velmax);
varargout{2} = min(gui.velmin);
case 'getstrokevolume'
value = gui.nettotvol.*gui.hr/1000;
case 'getdistensibility'
value = gui.diameter/10;%cm/10=mm
case 'getcurve'
value = gui.netflow;
case 'getroiname'
value = gui.roiname;
case 'getpeakvelocitycurve'
value = gui.velmax;
end
varargout{1} = value;
%-------------------------
function exporttosetstruct
%-------------------------
global DATA SET
gui = DATA.GUI.Flow;
no = gui.nom;
for roinbr = 1:gui.numrois%gui.rois2take
flowdata = [];
flowdata.velmean = gui.velmean(:,roinbr);
flowdata.velstd = gui.velstd(:,roinbr);
flowdata.velmax = gui.velmax(:,roinbr);
flowdata.velmin = gui.velmin(:,roinbr);
flowdata.kenergy = gui.kenergy(:,roinbr);
flowdata.netflow = gui.netflow(:,roinbr);
flowdata.posflow = gui.posflow(:,roinbr);
flowdata.negflow = gui.negflow(:,roinbr);
flowdata.diameter = gui.diameter(:,roinbr);
flowdata.nettotvol = gui.nettotvol(roinbr);
flowdata.nettotposvol = gui.nettotposvol(roinbr);
flowdata.nettotnegvol = gui.nettotnegvol(roinbr);
flowdata.netforwardvol = gui.netforwardvol(roinbr);
flowdata.netbackwardvol = gui.netbackwardvol(roinbr);
flowdata.meanflow = gui.meanflow(roinbr);
flowdata.maxflow = gui.maxflow(roinbr);
flowdata.maxmaxvel = gui.maxmaxvel(roinbr);
flowdata.sv = gui.sv(roinbr);
flowdata.meanmeanvel = gui.meanmeanvel(roinbr);
SET(no).Roi(gui.rois2take(roinbr)).Flow = flowdata;
end
return
%Save plot for later use in report. Not working yet.
fnames = fieldnames(gui.handles);
for i = 1:numel(fnames)
h = gui.handles.(fnames{i});
if ~ismember(get(h,'Type'),{'figure','axes'})
set(h,'Visible','off')
end
end
set(gui.handles.figure1,'Color',[1 1 1]);
f = mygetframe(gui.handles.figure1);
im = imresize(frame2im(f), [NaN 512]);
if ~isfield(SET(1).Report,'Name') || isempty(SET(1).Report.Name)
name = removeforbiddenchars(SET(1).PatientInfo.Name);
if isempty(name)
name = 'Hidden';
end
else
name = SET(1).Report.Name;
end
imwrite(im,fullfile(DATA.Pref.Pacs.ReportsheetPath,name,sprintf('flowaxes_%d.png',no)));
%----------------------
function close_Callback
%-----------------------
%Close flow report GUI
global DATA
datacursormode off;
try
DATA.GUI.Flow=close(DATA.GUI.Flow); %close the flow gui
catch %#ok<CTCH>
delete(gcbf)
end
DATA.GUI.Flow = [];
segment('updateflow'); %DATA.updateaxestables('flow');
%--------------
function update(no)
%--------------
%Make graphical update of plot
global DATA SET NO
gui = DATA.GUI.Flow;
t = gui.t;
d = gui.d;
dt = gui.dt;
nom = gui.nom;
rois2take = gui.rois2take;
numrois = gui.numrois;
if nargin < 1
no = NO;
end
%check if there has been roi updates in the main gui
if ~(gui.nop==no) && ~(gui.nom==no)
reportflow('init');
elseif ~(numrois==length(SET(no).Roi))
%reportflow('init');
end
v = mygetlistbox(gui.handles.parameterlistbox);
switch v
case 1 %'Flow'
%--- Plot flow
h = plot(gui.handles.plotaxes,t*1000,gui.netflow(:,1),[d SET(nom).Roi(rois2take(1)).LineSpec]);
set(h,'linewidth',2);
hold(gui.handles.plotaxes,'on')
for loop=2:size(gui.netflow,2)
h = plot(gui.handles.plotaxes,t*1000,gui.netflow(:,loop),[d SET(nom).Roi(rois2take(loop)).LineSpec]);
set(h,'linewidth',2);
end
set(gui.handles.plotaxes,'XColor',DATA.GUISettings.ForegroundColor,'YColor',DATA.GUISettings.ForegroundColor);
hold(gui.handles.plotaxes,'off');
set(gui.handles.plotaxes,'xlim',[0 (SET(nom).TSize-1)*1000*SET(nom).TIncr]);
title(gui.handles.plotaxes,dprintf('Net flow. %s',gui.phasecorrstring),'FontSize',12,'Color',DATA.GUISettings.ForegroundColor);
xlabel(gui.handles.plotaxes,dprintf('Time [ms]'),'Color',DATA.GUISettings.ForegroundColor);
ylabel(gui.handles.plotaxes,dprintf('Flow [ml/s]'),'Color',DATA.GUISettings.ForegroundColor);
grid(gui.handles.plotaxes,'on');
case 2 %'Positive/Negative Flow'
%--- plot forward/backward flow
h = plot(gui.handles.plotaxes,t*1000,gui.posflow(:,1),[d SET(nom).Roi(rois2take(1)).LineSpec]);
set(h,'linewidth',2);
hold(gui.handles.plotaxes,'on');
for loop=2:size(gui.netflow,2)
h = plot(gui.handles.plotaxes,t*1000,gui.posflow(:,loop),[d SET(nom).Roi(rois2take(loop)).LineSpec]);
set(h,'linewidth',2);
end
for loop=1:size(gui.negflow,2)
h = plot(gui.handles.plotaxes,t*1000,gui.negflow(:,loop),[d SET(nom).Roi(rois2take(loop)).LineSpec]);
set(h,'linewidth',2,'linestyle',':');
end
set(gui.handles.plotaxes,'XColor',DATA.GUISettings.ForegroundColor,'YColor',DATA.GUISettings.ForegroundColor);
hold(gui.handles.plotaxes,'off');
set(gui.handles.plotaxes,'xlim',[0 (SET(nom).TSize-1)*1000*SET(nom).TIncr]);
title(gui.handles.plotaxes,dprintf('Positive (-) / Negative (:) flow. %s',gui.phasecorrstring),'FontSize',12,'Color',DATA.GUISettings.ForegroundColor);
xlabel(gui.handles.plotaxes,dprintf('Time [ms]'),'Color',DATA.GUISettings.ForegroundColor);
ylabel(gui.handles.plotaxes,dprintf('Flow [ml/s]'),'Color',DATA.GUISettings.ForegroundColor);
grid(gui.handles.plotaxes,'on');
case 3 %'Velocity'
%--- Plot velocity
h = plot(gui.handles.plotaxes,t*1000,gui.velmean(:,1),[d SET(nom).Roi(rois2take(1)).LineSpec]);
set(h,'linewidth',2);
hold(gui.handles.plotaxes,'on')
for loop=2:size(gui.velmean,2)
h = plot(gui.handles.plotaxes,t*1000,gui.velmean(:,loop),[d SET(nom).Roi(rois2take(loop)).LineSpec]);
set(h,'linewidth',2);
end
%--- Plot std bars
plot(...
gui.handles.plotaxes,...
[t'*1000 t'*1000]',...
[gui.velmean(:,1)-gui.velstd(:,1) gui.velmean(:,1)+gui.velstd(:,1)]',...
SET(nom).Roi(1).LineSpec);
plot(...
gui.handles.plotaxes,...
[t'*1000-dt t'*1000+dt]',...
[gui.velmean(:,1)-gui.velstd(:,1) gui.velmean(:,1)-gui.velstd(:,1)]',...
SET(nom).Roi(1).LineSpec);
plot(...
gui.handles.plotaxes,...
[t'*1000-dt t'*1000+dt]',...
[gui.velmean(:,1)-gui.velstd(:,1) gui.velmean(:,1)-gui.velstd(:,1)]',...
SET(nom).Roi(1).LineSpec);
plot(...
gui.handles.plotaxes,...
[t'*1000-dt t'*1000+dt]',...
[gui.velmean(:,1)+gui.velstd(:,1) gui.velmean(:,1)+gui.velstd(:,1)]',...
SET(nom).Roi(1).LineSpec);
for loop=2:size(gui.velmean,2)
plot(...
gui.handles.plotaxes,...
[t'*1000 t'*1000]',...
[gui.velmean(:,loop)-gui.velstd(:,loop) gui.velmean(:,loop)+gui.velstd(:,loop)]',...
SET(nom).Roi(loop).LineSpec);
plot(...
gui.handles.plotaxes,...
[t'*1000-dt t'*1000+dt]',...
[gui.velmean(:,loop)-gui.velstd(:,loop) gui.velmean(:,loop)-gui.velstd(:,loop)]',...
SET(nom).Roi(loop).LineSpec);
plot(...
gui.handles.plotaxes,...
[t'*1000-dt t'*1000+dt]',...
[gui.velmean(:,loop)-gui.velstd(:,loop) gui.velmean(:,loop)-gui.velstd(:,loop)]',...
SET(nom).Roi(loop).LineSpec);
plot(...
gui.handles.plotaxes,...
[t'*1000-dt t'*1000+dt]',...
[gui.velmean(:,loop)+gui.velstd(:,loop) gui.velmean(:,loop)+gui.velstd(:,loop)]',...
SET(nom).Roi(1).LineSpec);
end
set(gui.handles.plotaxes,'XColor',DATA.GUISettings.ForegroundColor,'YColor',DATA.GUISettings.ForegroundColor);
hold(gui.handles.plotaxes,'off');
set(gui.handles.plotaxes,'xlim',[0 (SET(nom).TSize-1)*1000*SET(nom).TIncr]);
title(gui.handles.plotaxes,dprintf('Mean velocity. %s',gui.phasecorrstring),'FontSize',12,'Color',DATA.GUISettings.ForegroundColor);
xlabel(gui.handles.plotaxes,dprintf('Time [ms]'),'Color',DATA.GUISettings.ForegroundColor);
ylabel(gui.handles.plotaxes,dprintf('Mean velocity [cm/s]'),'Color',DATA.GUISettings.ForegroundColor);
grid(gui.handles.plotaxes,'on');
case 4 %'Max Velocity'
%--- Plot max
h = plot(gui.handles.plotaxes,t*1000,gui.velmax(:,1),[d SET(nom).Roi(rois2take(1)).LineSpec]);
set(h,'linewidth',2);
hold(gui.handles.plotaxes,'on');
for loop=2:size(gui.area,2)
h = plot(gui.handles.plotaxes,t*1000,gui.velmax(:,loop),[d SET(nom).Roi(rois2take(loop)).LineSpec]);
set(h,'linewidth',2);
end
set(gui.handles.plotaxes,'XColor',DATA.GUISettings.ForegroundColor,'YColor',DATA.GUISettings.ForegroundColor);
hold(gui.handles.plotaxes,'off');
set(gui.handles.plotaxes,'xlim',[0 (SET(nom).TSize-1)*1000*SET(nom).TIncr]);
title(gui.handles.plotaxes,dprintf('Max velocity. %s',gui.phasecorrstring),'FontSize',12,'Color',DATA.GUISettings.ForegroundColor);
xlabel(gui.handles.plotaxes,dprintf('Time [ms]'),'Color',DATA.GUISettings.ForegroundColor);
ylabel(gui.handles.plotaxes,dprintf('Max velocity [cm/s]'),'Color',DATA.GUISettings.ForegroundColor);
grid(gui.handles.plotaxes,'on');
case 5 %'Min Velocity'
%--- Plot min
h = plot(gui.handles.plotaxes,t*1000,gui.velmin(:,1),[d SET(nom).Roi(rois2take(1)).LineSpec]);
set(h,'linewidth',2);
hold(gui.handles.plotaxes,'on');
for loop=2:size(gui.area,2)
h = plot(gui.handles.plotaxes,t*1000,gui.velmin(:,loop),[d SET(nom).Roi(rois2take(loop)).LineSpec]);
set(h,'linewidth',2);
end
set(gui.handles.plotaxes,'XColor',DATA.GUISettings.ForegroundColor,'YColor',DATA.GUISettings.ForegroundColor);
hold(gui.handles.plotaxes,'off');
set(gui.handles.plotaxes,'xlim',[0 (SET(nom).TSize-1)*1000*SET(nom).TIncr]);
title(gui.handles.plotaxes,dprintf('Min velocity. %s',gui.phasecorrstring),'FontSize',12,'Color',DATA.GUISettings.ForegroundColor);
xlabel(gui.handles.plotaxes,dprintf('Time [ms]'),'Color',DATA.GUISettings.ForegroundColor);
ylabel(gui.handles.plotaxes,dprintf('Min velocity [cm/s]'),'Color',DATA.GUISettings.ForegroundColor);
grid(gui.handles.plotaxes,'on');
case 6 %'Signed Kinetic Energy'
%--- Plot KE
h = plot(gui.handles.plotaxes,t*1000,gui.kenergy(:,1),[d SET(nom).Roi(rois2take(1)).LineSpec]);
set(h,'linewidth',2);
hold(gui.handles.plotaxes,'on');
for loop=2:size(gui.area,2)
h = plot(gui.handles.plotaxes,t*1000,gui.kenergy(:,loop),[d SET(nom).Roi(rois2take(loop)).LineSpec]);
set(h,'linewidth',2);
end
set(gui.handles.plotaxes,'XColor',DATA.GUISettings.ForegroundColor,'YColor',DATA.GUISettings.ForegroundColor);
hold(gui.handles.plotaxes,'off');
set(gui.handles.plotaxes,'xlim',[0 (SET(nom).TSize-1)*1000*SET(nom).TIncr]);
title(gui.handles.plotaxes,dprintf('Signed Kinetic Energy. %s',gui.phasecorrstring),'FontSize',12,'Color',DATA.GUISettings.ForegroundColor);
xlabel(gui.handles.plotaxes,dprintf('Time [ms]'),'Color',DATA.GUISettings.ForegroundColor);
ylabel(gui.handles.plotaxes,dprintf('Signed Kinetic Energy [Nm/s]'),'Color',DATA.GUISettings.ForegroundColor);
grid(gui.handles.plotaxes,'on');
case 7 %'Area'
%--- Plot area
h = plot(gui.handles.plotaxes,t*1000,gui.area(:,1),[d SET(nom).Roi(rois2take(1)).LineSpec]);
set(h,'linewidth',2);
hold(gui.handles.plotaxes,'on');
for loop=2:size(gui.area,2)
h = plot(gui.handles.plotaxes,t*1000,gui.area(:,loop),[d SET(nom).Roi(rois2take(loop)).LineSpec]);
set(h,'linewidth',2);
end
set(gui.handles.plotaxes,'XColor',DATA.GUISettings.ForegroundColor,'YColor',DATA.GUISettings.ForegroundColor);
hold(gui.handles.plotaxes,'off');
set(gui.handles.plotaxes,'xlim',[0 (SET(nom).TSize-1)*1000*SET(nom).TIncr]);
set(gui.handles.plotaxes,'ylim',[0 1.2*max(max(gui.area))]);
title(gui.handles.plotaxes,dprintf('Area. %s',gui.phasecorrstring),'FontSize',12,'Color',DATA.GUISettings.ForegroundColor);
xlabel(gui.handles.plotaxes,dprintf('Time [ms]'),'Color',DATA.GUISettings.ForegroundColor);
ylabel(gui.handles.plotaxes,dprintf('Area [cm^2]'),'Color',DATA.GUISettings.ForegroundColor);
grid(gui.handles.plotaxes,'on');
case 8 %'Diameter'
%--- Plot diameter
h = plot(gui.handles.plotaxes,t*1000,gui.diameter(:,1),[d SET(nom).Roi(rois2take(1)).LineSpec]);
set(h,'linewidth',2);
hold(gui.handles.plotaxes,'on');
for loop=2:size(gui.diameter,2)
h = plot(gui.handles.plotaxes,t*1000,gui.diameter(:,loop),[d SET(nom).Roi(rois2take(loop)).LineSpec]);
set(h,'linewidth',2);
end
set(gui.handles.plotaxes,'XColor',DATA.GUISettings.ForegroundColor,'YColor',DATA.GUISettings.ForegroundColor);
hold(gui.handles.plotaxes,'off');
set(gui.handles.plotaxes,'xlim',[0 (SET(nom).TSize-1)*1000*SET(nom).TIncr]);
set(gui.handles.plotaxes,'ylim',[0 1.2*max(max(gui.diameter))]);
title(gui.handles.plotaxes,dprintf('Diameter. %s',gui.phasecorrstring),'FontSize',12,'Color',DATA.GUISettings.ForegroundColor);
xlabel(gui.handles.plotaxes,dprintf('Time [ms]'),'Color',DATA.GUISettings.ForegroundColor);
ylabel(gui.handles.plotaxes,dprintf('Diameter [mm]'),'Color',DATA.GUISettings.ForegroundColor);
grid(gui.handles.plotaxes,'on');
case {9,10,11} %{'3D plot','3D plot one frame','Pixel Export'}
%--- 3D plot
if v == 10 %strcmp(s{v},'3D plot one frame')
rois=SET(nom).RoiCurrent;