-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnvis.m
1935 lines (1594 loc) · 81.2 KB
/
nvis.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
classdef nvis < nvisBase
%nvis visualizes 2D slices from higherdimensional data
% NVIS(I) opens a UI that displays one 2D slice from the input
% matrix I with N dimensions (N>2). Sliders allow to navigate thorugh
% the remaining, non-singleton dimensions. The windowing of the
% colormaps can be dynamically changed by pressing the middle mouse
% button on the image and moving the mouse up/down (center) or
% left/right(width). ROIs can be drawn to measure Signal to Noise
% ratio in image data.
%
% NVIS(I1, I2): Data from the matrices I1 and I2 are overlaid
% by adding (default) the RGB values attributed by the individual
% colormaps. The windowing for the second image can be adjusted by
% using the left mouse button. Image sizes must not be identical, but
% for dimensions, where the size is different, one matrix must be of
% size one.
%
% Usage
%
% Values in the lower left show the array indices of the datapoint
% under the cursor as well as the matrix-values at that location. In
% case of complex data, the value is shown in the current complex
% mode.
% Colorbar button in the matlab figure-toolbar can be used to show
% adapting colorbars.
% <- and -> change the dimensions that are shown along the image
% dimensions. Initially, dimensions 1 and 2 are shown. By presing <-
% / -> both are decreased/increased by 1, wrapping where necessary.
% 'Run' starts a timer which loops through the image dimension
% selected by the radio button. 'SaveImage' save the currently
% visible image to file, 'SaveVideo' saves the running animation as a
% video file (.avi or .gif)
% The crosshair button creates a circle in the current image and the
% 'Plot' button opens an external window that shos the behavior of
% the data through that point along different dimensions of the input
% matrix. Continuous updating of the data shown in the external plot
% can be switched on or off using the 'Update' button.
%
% Name-Value-Pairs
%
% Name------------Value-------Descripton-----------------------------
%
% 'CW' 1x2 double Initial values for center and width.
% For two input matrices, Value must be
% 2x2 matrix, or values are applied to
% both.
% 'Colormap' Nx3 | char initial colormaps for the image. The
% user can either supply a custom
% colormap or chose from the available
% colormaps. Default is gray(256). For
% two input matrices, value must be 1x2
% cell array. Default is {'green',
% 'magenta'}. More colormaps are
% available if 'colorcet.m' is found on
% the MATLAB path (Peter Kovesi,
% https://peterkovesi.com/projects/colourmaps/)
% 'Contrast' char redundant NVP, will be removed in
% future versions.
% 'Overlay' int inital overlay mode for two input
% matrices (1: add (default), 2:
% multiply)
% 'ComplexMode' int For complex data, chooses the initially
% displayed complex part (1: magnitude
% (default), 2: phase, 3: real part, 4:
% imaginary part).
% 'AspectRatio' 'image' the displayed axes have the same aspect
% ratio as the input matrix for that
% slice, i.e. pixels will be squares.
% 'square' The displayed axes always have a square
% shape.
% 'Resize' double uses 'imresize' to resize the currently
% displayed slice by the given value.
% 'Title' char title of the figure window
% 'Position', 1x4 int Position of the figure in pixel
% 'Unit' char physical unit of the provided image
% data. For two input matrices, value
% must be 1x2 cell array, or both are
% assigned the same unit
% 'InitSlice', 1xN-2 set the slice that is shown when the
% figure is opened.
% 'InitRot', int initial rotation angle of the displayed
% image
% 'InitPoint', 1x2 coordinates along the first 2
% dimensions of img, where the marker is
% placed
% 'DimLabel', cell{char} char arrays to label the individual
% dimensions in the input data. Cell
% entries can be empty to use default
% label.
% 'DimVal', cell{cell{char}} char arrays containing the axis-values
% or cell{int} for each dimension. Cell entries can be
% empty to use default enumeration. Vals
% must not be char, but is encouraged.
% 'Permute' 1xN permutation vector, that works similar
% to matlabs permute function. It is used
% to access image information in
% different order. Use this when working
% with large image matrices, to avoid
% additional memory usage from calling
% permute.
% 'fps', double defines how many times per second the
% slider value provided by 'LoopDim' is
% increased.
% 'LoopDim', int Dimension, along which the slider is
% incremented 'fps' times per second
% 'ROI_Signal', Nx2 vertices polygon that defines a ROI in
% the initial slice.
% 'ROI_Noise', Nx2 vertices polygon that defines a ROI in
% the initial slice.
% 'SaveImage', filename When provided, the image data is
% prepared according to the other inputs,
% but no figure is shown. The prepared
% image data is directly saved to file
% under filename.
% 'SaveVideo', filename When provided, the image data is
% prepared according to the other inputs,
% but no figure is shown. 'fps' gives the
% framerate for the video that is saved
% under filename. Only '.avi' and '.gif'
% supported so far. 'LoopDim' can be used
% to specify the dimension along which
% the video loops.
%______________________________________________________________________
% Authors: Johannes Fischer
% Yanis Taege
% TODO:
% - RadioGroup Buttons for animated sliders
% - make 'SaveVideo' button only active, when timer is running
% - make clear that externalPlot does not work when fft button is
% pressed (would require fft of the whole stack)
properties (Access = private)
% DISPLAYING
locValString
% UI Elements
pImage
pSlider
pControls
pColorbar
hBtnShiftL
hBtnShiftR
hBtnPoint
hBtnPlot
hBtnUpdateExternal
locAndVals
hBtnG
hRadioBtnSlider
InitSlice
%% external plot parameters
% point for external plots
hMarker
point
% called objects
hExtPlot
% dimension that is shown in the external plot
externalDim
externalSel
% switch, whether external plot should be updated when selector is
% changed
bUpdateExternal
%% UI properties
pSliderHeight
colorbarWidth
sliderStartPos
division
margin
height
yPadding
panelPos
figurePos
pointEnabled
color_ma
end
properties (Constant, Access = private)
%% UI PROPERTIES
% absolute width of Control panel in pixel
controlWidth = 300; % px
controlWidthMinimized = 30 ; % px
sliderHeight = 20; % px
sliderPadding = 4; % px
end
methods
function obj = nvis(in, varargin)
%% CONSTRUCTOR
obj@nvisBase(in, varargin{:})
% set the type
obj.Type = 'nvis';
% only one Axis in nvis
obj.nAxes = 1;
obj.activeAx = 1;
obj.cbDirection = 'vertical';
% per default, update external plots
obj.bUpdateExternal = 1;
if obj.nImages == 2
obj.inputNames{1} = inputname(1);
obj.inputNames{2} = inputname(2);
obj.standardTitle = [inputname(1) ' ' inputname(2)];
else
obj.inputNames{1} = inputname(1);
obj.standardTitle = inputname(1);
end
obj.prepareParser()
% additional parameters
addParameter(obj.p, 'InitSlice', round(obj.S([false false obj.S(3:end) > 2])/2), @isnumeric);
addParameter(obj.p, 'InitPoint', [1 1], @isnumeric);
addParameter(obj.p, 'InitShift', 0, @(x) isnumeric(x) && isscalar(x));
addParameter(obj.p, 'MarkerColor', [1 0 0], @(x) isnumeric(x) && numel(x) == 3);
addParameter(obj.p, 'ROI_Signal', [0 0; 0 0; 0 0], @isnumeric);
addParameter(obj.p, 'ROI_Noise', [0 0; 0 0; 0 0], @isnumeric);
addParameter(obj.p, 'Permute', 1:obj.nDims, @(x) isnumeric(x) && numel(x) >= obj.nDims && isequal(sort(x, 'ascend'), 1:numel(x)) );
parse(obj.p, obj.varargin{:});
obj.cmap{1} = obj.p.Results.Colormap;
obj.fps = obj.p.Results.fps;
obj.complexMode = obj.p.Results.ComplexMode;
obj.resize = obj.p.Results.Resize;
obj.contrast = obj.p.Results.Contrast;
obj.overlay = obj.p.Results.Overlay;
obj.unit = obj.p.Results.Unit;
obj.color_ma = obj.p.Results.MarkerColor;
obj.fixedDim = obj.p.Results.fixedDim;
% remove all entries from permute, where obj.S is 1. Create a
% temporary size variable with trailing 1s to mimick behaviour
% of matlabs inbuilt permute function
s = [obj.S ones(1, max(obj.p.Results.Permute)-numel(obj.S))];
permute = obj.p.Results.Permute(s(obj.p.Results.Permute) > 1);
% which dimensions are shown initially
obj.showDims = permute([1 2]);
% are there more than 2 dimensions with size > 1?
if numel(permute) > 2
tmp = permute(3:end);
% create a temporary size variable with trailing 1s to
% mimick behaviour of matlabs inbuilt permute function
obj.mapSliderToDim = tmp(s(tmp) > 1);
obj.nSlider = numel(obj.mapSliderToDim);
obj.activeDim = obj.mapSliderToDim(1);
obj.externalDim = obj.mapSliderToDim(1);
if obj.fixedDim ~= 0
% make sure fixedDim is mapped to the last slider
obj.mapSliderToDim(obj.mapSliderToDim == obj.fixedDim) = [];
obj.mapSliderToDim = [obj.mapSliderToDim obj.fixedDim];
end
else
% there is no dimension to slide through anyway
obj.nSlider = 0;
obj.activeDim = 3;
obj.externalDim = [];
end
% after parsing the Permute vector, initially shown slices and
% dimensions might have changed. p.Results is write protected,
% so we have to provide our own parameter
if contains('InitSlice', obj.p.UsingDefaults)
obj.InitSlice = round(obj.S(obj.mapSliderToDim)/2);
else
obj.InitSlice = obj.p.Results.InitSlice;
end
if contains('InitPoint', obj.p.UsingDefaults)
obj.point = round(obj.S(obj.showDims)/2);
else
obj.point = obj.p.Results.InitPoint;
end
% only one image in nvis
obj.mapSliderToImage = num2cell(ones(1, obj.nSlider));
% if not specified, start with plotpoint disabled
if contains('InitPoint', obj.p.UsingDefaults)
obj.pointEnabled = 0;
else
obj.pointEnabled = 1;
end
if obj.fixedDim ~= 0
if (obj.S(obj.p.Results.fixedDim) > 1)
obj.interruptedSlider = find(obj.mapSliderToDim == obj.p.Results.fixedDim, 1);
else
warning('fixedDim was set to singleton dimension and will be ignored.')
obj.fixedDim = 0;
end
else
obj.interruptedSlider = obj.p.Results.LoopDimension - 2;
end
% set default values for dimLabel
obj.dimLabel = strcat(repmat({'Dim'}, 1, numel(obj.S)), cellfun(@num2str, num2cell(1:obj.nDims), 'UniformOutput', false));
obj.parseDimLabelsVals()
obj.prepareGUIElements()
obj.prepareColors()
% requires InitSlice to be set
obj.createSelector()
% necessary for view orientation, already needed when saving image or video
obj.azimuthAng = obj.p.Results.InitRot;
% when an image or a video is saved, dont create the GUI and
% terminate the class after finishing
if ~contains('SaveImage', obj.p.UsingDefaults)
obj.saveImage(obj.p.Results.SaveImage);
if contains('SaveVideo', obj.p.UsingDefaults)
% the user does not want a video to be saved at the
% same time so close the figure and delete the object.
clear obj
return
end
end
if ~contains('SaveVideo', obj.p.UsingDefaults)
if obj.fps == 0
error('Can''t write video file with 0 fps!')
else
obj.saveVideo(obj.p.Results.SaveVideo);
clear obj
return
end
end
% overwrite the default value fot maxLetters in locVal section
obj.maxLetters = 8;
obj.setValNames()
obj.setLocValFunction()
obj.prepareGUI()
obj.optimizeInitialFigureSize()
obj.guiResize()
obj.recolor()
if obj.p.Results.InitShift ~= 0
obj.shiftDims(obj.p.Results.InitShift);
end
set(obj.f, 'Visible', 'on');
if ~contains('ROI_Signal', obj.p.UsingDefaults)
obj.createROI(1, obj.p.Results.ROI_Signal)
end
if ~contains('ROI_Noise', obj.p.UsingDefaults)
obj.createROI(2, obj.p.Results.ROI_Noise)
end
% do not assign to 'ans' when called without assigned variable
if nargout == 0
clear obj
end
end
function delete(obj)
%% destructor
end
function prepareGUI(obj)
%% adjust figure properties
set(obj.f, ...
'name', obj.p.Results.Title, ...
'Units', 'pixel', ...
'Position', obj.p.Results.Position, ...
'Visible', 'off', ...
'ResizeFcn', @obj.guiResize, ...
'CloseRequestFcn', @obj.closeRqst, ...
'WindowButtonMotionFcn',@obj.mouseMovement, ...
'WindowButtonUpFcn', @obj.stopDragFcn, ...
'WindowScrollWheelFcn', @obj.scrollSlider)
if obj.nImages > 1
set(obj.f, 'KeyPressFcn', @obj.keyPressedFcn)
end
% absolute height of slider panel
obj.pSliderHeight = obj.nSlider * (obj.sliderHeight + 2*obj.sliderPadding); % px
% colorbar panel is invisible at first
obj.colorbarWidth = 0; % px
obj.calcPanelPos()
% create and place panels
obj.pImage = uipanel( ...
'Units', 'pixels', ...
'Position', obj.panelPos(1, :), ...
'BackgroundColor', obj.COLOR_BG, ...
'HighLightColor', obj.COLOR_BG, ...
'ShadowColor', obj.COLOR_B);
obj.pSlider = uipanel( ...
'Units', 'pixels', ...
'Position', obj.panelPos(2, :), ...
'BackgroundColor', obj.COLOR_BG, ...
'HighLightColor', obj.COLOR_BG, ...
'ShadowColor', obj.COLOR_B);
obj.pControls = uipanel( ...
'Units', 'pixels', ...
'Position', obj.panelPos(3, :), ...
'BackgroundColor', obj.COLOR_BG, ...
'HighLightColor', obj.COLOR_BG, ...
'ShadowColor', obj.COLOR_B);
obj.pColorbar = uipanel( ...
'Units', 'pixels', ...
'Position', obj.panelPos(4, :), ...
'BackgroundColor', obj.COLOR_BG, ...
'HighLightColor', obj.COLOR_BG, ...
'ShadowColor', obj.COLOR_B);
% place UIcontrol elements
obj.margin = 0.02 * obj.controlWidth;
obj.height = 0.05 * 660;
obj.yPadding = 0.0075 * 660;
if obj.nImages == 1
obj.division = 0.40 * obj.controlWidth;
centerString = 'Center:';
widthString = 'Width:';
signalString = 'Signal ROI';
noiseString = 'Noise ROI';
textFont = 0.6;
else
obj.division = 0.22 * obj.controlWidth;
centerString = 'C: ';
widthString = 'W: ';
signalString = 'S';
noiseString = 'N';
textFont = 0.4;
end
num = {'first', 'second'};
for ii = 1:obj.nImages
set(obj.hBtnCwHome(ii), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'FontUnits', 'normalized', ...
'FontSize', 0.6, ...
'HorizontalAlignment', 'left');
set(obj.hBtnCwSlice(ii), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'FontUnits', 'normalized', ...
'FontSize', 0.6, ...
'HorizontalAlignment', 'left');
if obj.nImages == 2
set(obj.hBtnCwHome(ii), 'Tooltip', ['use initial windowing on ' num{ii} ' image']);
set(obj.hBtnCwSlice(ii), 'Tooltip', ['window current slice of ' num{ii} ' image']);
end
end
% place cw windowing elements
if obj.nImages == 2
set(obj.hBtnCwCopy(1), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'FontUnits', 'normalized', ...
'FontSize', 0.6, ...
'HorizontalAlignment', 'left');
set(obj.hBtnCwCopy(2), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'FontUnits', 'normalized', ...
'FontSize', 0.6, ...
'HorizontalAlignment', 'left');
set(obj.hBtnCwLink, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'HorizontalAlignment', 'center');
end
set(obj.hTextC, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', centerString, ...
'FontUnits', 'normalized', ...
'FontSize', 0.6, ...
'HorizontalAlignment', 'left');
set(obj.hTextW, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', widthString, ...
'FontUnits', 'normalized', ...
'FontSize', 0.6, ...
'HorizontalAlignment', 'left');
for idh = 1:obj.nImages
set(obj.hEditC(idh), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'HorizontalAlignment', 'right', ...
'FontUnits', 'normalized', ...
'FontSize', textFont, ...
'FontName', 'FixedWidth', ...
'ForegroundColor', obj.COLOR_m(idh, :));
set(obj.hEditW(idh), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'HorizontalAlignment', 'right', ...
'FontUnits', 'normalized', ...
'FontSize', textFont, ...
'FontName', 'FixedWidth', ...
'ForegroundColor', obj.COLOR_m(idh, :));
if obj.nImages == 2
set(obj.hBtnHide(idh), ...
'Parent', obj.pControls, ...
'Value', 1, ...
'Units', 'pixel', ...
'String', ['Hide (' obj.BtnHideKey{idh} ')'], ...
'HorizontalAlignment', 'left', ...
'FontUnits', 'normalized', ...
'FontSize', 0.4, ...
'ForegroundColor', obj.COLOR_m(idh, :));
end
end
if obj.nImages == 2
% toggle button
set(obj.hBtnToggle, ...
'Parent', obj.pControls, ...
'Value', 1, ...
'Units', 'pixel', ...
'HorizontalAlignment', 'left', ...
'FontUnits', 'normalized', ...
'FontSize', 0.4);
end
set(obj.hPopCm(1), ...
'Parent', obj.pControls, ...
'FontUnits', 'normalized', ...
'FontSize', 0.6);
if obj.nImages == 2
set(obj.hPopCm(2), ...
'Parent', obj.pControls, ...
'FontUnits', 'normalized', ...
'FontSize', 0.6);
set(obj.hPopOverlay, ...
'Parent', obj.pControls, ...
'FontUnits', 'normalized', ...
'FontSize', 0.6);
end
obj.hBtnShiftL = uicontrol( ...
'Parent', obj.pControls, ...
'Style', 'pushbutton', ...
'Units', 'pixel', ...
'Callback', { @obj.shiftCallback}, ...
'String', char(8592), ...
'FontUnits', 'normalized', ...
'FontSize', 0.75, ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
obj.hBtnRotL = uicontrol( ...
'Parent', obj.pControls, ...
'Style', 'pushbutton', ...
'Units', 'pixel', ...
'String', char(11119), ...
'Tooltip', 'rotate image counter-clockwise by 90°', ...
'Callback', { @obj.rotateView, -90}, ...
'FontUnits', 'normalized', ...
'FontSize', 0.75, ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
obj.hBtnRotR = uicontrol( ...
'Parent', obj.pControls, ...
'Style', 'pushbutton', ...
'Units', 'pixel', ...
'String', char(11118), ...
'Tooltip', 'rotate image clockwise by 90°', ...
'Callback', { @obj.rotateView, 90}, ...
'FontUnits', 'normalized', ...
'FontSize', 0.75, ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
obj.hBtnShiftR = uicontrol( ...
'Parent', obj.pControls, ...
'Style', 'pushbutton', ...
'Units', 'pixel', ...
'Callback', { @obj.shiftCallback}, ...
'String', char(8594), ...
'FontUnits', 'normalized', ...
'FontSize', 0.75, ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
set(obj.hBtnRoi(1), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', signalString, ...
'FontUnits', 'normalized', ...
'FontSize', 0.4, ...
'Tooltip', 'draw signal ROI');
set(obj.hBtnRoi(2), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', noiseString, ...
'FontUnits', 'normalized', ...
'FontSize', 0.4, ...
'Tooltip', 'draw noise ROI');
set(obj.hTextRoi(1), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', '', ...
'Tooltip', 'mean value inside signal ROI', ...
'HorizontalAlignment', 'right', ...
'FontUnits', 'normalized', ...
'FontSize', textFont, ...
'FontName', 'FixedWidth');
set(obj.hTextRoi(2), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', '', ...
'Tooltip', 'standard deviation inside noise ROI', ...
'HorizontalAlignment', 'right', ...
'FontUnits', 'normalized', ...
'FontSize', textFont, ...
'FontName', 'FixedWidth');
set(obj.hTextSNR, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', 'SNR:', ...
'HorizontalAlignment', 'left', ...
'FontUnits', 'normalized', ...
'FontSize', 0.6);
set(obj.hTextSNRvals, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', '', ...
'HorizontalAlignment', 'right', ...
'FontUnits', 'normalized', ...
'FontSize', textFont, ...
'FontName', 'FixedWidth', ...
'Tooltip', 'signal / noise');
set(obj.hTextRoiType, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', 'ROI Shape', ...
'HorizontalAlignment', 'left', ...
'FontUnits', 'normalized', ...
'FontSize', 0.6);
set(obj.hPopRoiType, ...
'Parent', obj.pControls, ...
'FontUnits', 'normalized', ...
'FontSize', 0.6);
set(obj.hBtnDelRois, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', 'Delete ROIs', ...
'FontUnits', 'normalized', ...
'FontSize', 0.45);
set(obj.hBtnSaveRois, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', 'Save ROIs', ...
'FontUnits', 'normalized', ...
'FontSize', 0.45);
set(obj.hBtnFFT, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'FontUnits', 'normalized', ...
'FontSize', 0.45);
set(obj.hBtnCmplx(1), ...
'Parent', obj.pControls, ...
'Units', 'pixel',...
'Value', 1, ...
'FontUnits', 'normalized', ...
'FontSize', 0.45);
set(obj.hBtnCmplx(2), ...
'Parent', obj.pControls, ...
'Units', 'pixel',...
'Value', 0, ...
'FontUnits', 'normalized', ...
'FontSize', 0.45);
set(obj.hBtnCmplx(3), ...
'Parent', obj.pControls, ...
'Units', 'pixel',...
'Value', 0, ...
'FontUnits', 'normalized', ...
'FontSize', 0.45);
set(obj.hBtnCmplx(4), ...
'Parent', obj.pControls, ...
'Units', 'pixel',...
'Value', 0, ...
'FontUnits', 'normalized', ...
'FontSize', 0.45);
if any(obj.isComplex)% && isempty(obj.img{2})
set(obj.hBtnCmplx, 'Visible', 'on');
else
% when hBtnCmplx are hidden, complexMode must be 3
obj.complexMode = 3;
set(obj.hBtnCmplx, 'Visible', 'off');
end
if obj.nDims > 2
set(obj.hBtnRun, ...
'Parent', obj.pControls, ...
'FontUnits', 'normalized', ...
'FontSize', 0.45);
set(obj.hEditF, ...
'Parent', obj.pControls, ...
'HorizontalAlignment', 'left', ...
'FontUnits', 'normalized', ...
'FontSize', 0.6, ...
'FontName', 'FixedWidth');
set(obj.hTextFPS, ...
'Parent', obj.pControls, ...
'HorizontalAlignment', 'left', ...
'FontUnits', 'normalized', ...
'FontSize', 0.6);
obj.hBtnPoint = uicontrol( ...
'Parent', obj.pControls, ...
'Style', 'togglebutton', ...
'Units', 'pixel', ...
'String', char(8982), ...
'Value', obj.pointEnabled, ...
'Callback', {@obj.togglePoint}, ...
'FontUnits', 'normalized', ...
'FontSize', 0.85, ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
obj.hBtnPlot = uicontrol( ...
'Parent', obj.pControls, ...
'Style', 'pushbutton', ...
'Units', 'pixel', ...
'String', 'Plot', ...
'Callback', {@obj.openExternalPlot}, ...
'FontUnits', 'normalized', ...
'FontSize', 0.45, ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
obj.hBtnUpdateExternal = uicontrol( ...
'Parent', obj.pControls, ...
'Style', 'pushbutton', ...
'Units', 'pixel', ...
'String', 'Update: on', ...
'Callback', {@obj.toggleUpdateExternal}, ...
'FontUnits', 'normalized', ...
'FontSize', 0.45, ...
'Tooltip', 'Update data in external plot', ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
end
if obj.pointEnabled
set(obj.hBtnPlot, 'Enable', 'on')
set(obj.hBtnUpdateExternal, 'Enable', 'on')
else
set(obj.hBtnPlot, 'Enable', 'off')
set(obj.hBtnUpdateExternal, 'Enable', 'off')
end
obj.locAndVals = annotation(obj.pControls, 'textbox', ...
'LineStyle', 'none', ...
'Units', 'pixel', ...
'Position', [obj.margin ...
obj.margin+obj.height+2*obj.yPadding ...
obj.controlWidth-2*obj.margin ...
2.5*obj.height], ...
'String', '', ...
'HorizontalAlignment', 'left', ...
'FontUnits', 'pixel', ...
'FontSize', 16, ...
'FontName', 'FixedWidth', ...
'BackgroundColor', obj.COLOR_BG, ...
'Interpreter', 'Tex');
width_BtnMinimMaxim = obj.controlWidthMinimized - 2*obj.margin;
set(obj.hBtnSaveImg, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'Position', [obj.margin ...
obj.margin ...
(obj.controlWidth-width_BtnMinimMaxim-4*obj.margin)/2 ...
obj.height], ...
'String', 'Save Image', ...
'FontUnits', 'normalized', ...
'FontSize', 0.45);
set(obj.hBtnSaveVid, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'Position', [(obj.controlWidth-width_BtnMinimMaxim)/2 ...
obj.margin ...
(obj.controlWidth-width_BtnMinimMaxim-4*obj.margin)/2 ...
obj.height], ...
'FontUnits', 'normalized', ...
'FontSize', 0.45);
set(obj.hBtnMinimMaxim, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'Position', [obj.controlWidth-width_BtnMinimMaxim-obj.margin ...
obj.margin ...
width_BtnMinimMaxim ...
obj.height], ...
'FontUnits', 'normalized', ...
'FontSize', 0.45);
if obj.nDims <= 2
set(obj.hBtnSaveVid, 'Visible', 'off')
end
obj.t = timer(...
'BusyMode', 'queue', ...
'ExecutionMode', 'fixedRate', ...
'Period', 1, ...
'StartDelay', 0, ...
'TimerFcn', @(t, event) obj.interrupt, ...
'TasksToExecute', Inf);
% create uibuttongroup
obj.hBtnG = uibuttongroup( ...
'Parent', obj.pSlider, ...
'Visible', 'Off', ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F, ...
'ShadowColor', obj.COLOR_B, ...
'HighLightColor', obj.COLOR_BG, ...
'SelectionChangedFcn', @(bg, event) obj.btnGselection(bg, event), ...
'Visible', 'on');
% create and position the sliders
for iSlider = 1:obj.nSlider
sliderHeight0 = obj.pSliderHeight - iSlider*(2*obj.sliderPadding+obj.sliderHeight) + obj.sliderPadding;
TextWidth0 = 10;
TextWidth = 50;
EditWidth0 = TextWidth0 + TextWidth + 10;
EditWidth = 75;
obj.sliderStartPos = EditWidth0 + EditWidth + 10;
obj.hTextSlider(iSlider) = uicontrol( ...
'Parent', obj.pSlider, ...
'Style', 'text', ...
'Units', 'pixel', ...
'FontUnits', 'normalized', ...
'Position', [TextWidth0 sliderHeight0 TextWidth obj.sliderHeight], ...
'FontSize', 0.8, ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
obj.hEditSlider(iSlider) = uicontrol( ...
'Parent', obj.pSlider, ...
'Style', 'edit', ...
'Units', 'pixel', ...
'FontUnits', 'normalized', ...
'Position', [EditWidth0 sliderHeight0 EditWidth obj.sliderHeight], ...
'FontSize', 0.8, ...
'Enable', 'on', ...
'Value', iSlider, ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
set(obj.hEditSlider(iSlider), 'Callback', @obj.setSlider);
obj.hSlider(iSlider) = uicontrol( ...
'Parent', obj.pSlider, ...
'Style', 'slider', ...
'Units', 'pixel', ...
'Callback', @(src, eventdata) obj.newSlice(src, eventdata), ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_BG);
addlistener(obj.hSlider(iSlider), ...
'ContinuousValueChange', ...
@(src, eventdata) obj.newSlice(src, eventdata));
obj.hRadioBtnSlider(iSlider) = uicontrol(obj.hBtnG, ...
'Style', 'radiobutton', ...
'Units', 'pixel', ...
'Tag', num2str(iSlider), ...
'HandleVisibility', 'off', ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
end
obj.initializeColorbars()
obj.initializeSliders
obj.initializeAxis(true)
if ~sum(ismember(obj.p.UsingDefaults, 'fps')) && length(obj.S) > 2
set(obj.hBtnRun, 'String', 'Stop')
obj.setAndStartTimer
end
end
function initializeAxis(obj, firstCall)
%% (re)create the axes in the GUI
% initializeAxis is called, to create the GUI, or when the
% dimensions of the image are shifted and a reset of UI elements is
% necessary. Both cases differ in the value of the bool 'firstCall'
% This includes:
% axes ax1
% ROIs
% imageData h1
if ~firstCall
delete(obj.hImage.Parent)
obj.delRois()
end
obj.prepareSliceData;
ax = axes(...
'Parent', obj.pImage, ...
'Units', 'normal', ...
'Position', [0 0 1 1]);
obj.hImage = imagesc(obj.sliceMixer(1), ...
'Parent', ax); % plot image
hold on
obj.hMarker = plot(obj.point(1), obj.point(2), ...
'Parent', ax, ...
'MarkerSize', 10, ...
'LineWidth', 2, ...
'Color', obj.color_ma, ...
'Marker', 'o', ...
'Visible', obj.pointEnabled);
axis(obj.p.Results.AspectRatio)
set(ax, ...
'XTickLabel', '', ...
'YTickLabel', '', ...
'XTick', [], ...
'YTick', []);
set(obj.hImage, 'ButtonDownFcn', @obj.startDragFcn)