-
Notifications
You must be signed in to change notification settings - Fork 1
/
nvis3.m
1140 lines (953 loc) · 48 KB
/
nvis3.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 nvis3 < nvisBase
%nvis3 visualizes 2D slices from higherdimensional data
% NVIS3(I) opens a UI that displays three orthogonal 2D slices from the
% input matrix I with N dimensions (N>3). Sliders allow to navigate
% thorugh the first 3 dimensions. From left to right, the axes show a
% slice perpendicular to the first, second and third dimension. The
% windowing of the colormaps can be dynamically changed by pressing the
% middle mouse button on any 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.
%
% NVIS3(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 right 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. 'SaveImage' saves the currently
% visible images to file. 'Guides' switches on and off guidlines that
% show the position of the slices in the other axes.
%
% 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', 1x3 set the slices that are shown when the
% figure is opened.
% 'InitRot', 1x3 initial rotation angle of the displayed
% image
% '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.
% '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 three initial slices
% are prepared according to the other
% inputs, but no figure is shown. The
% three slices are concatenated and saved
% to file under filename.
%______________________________________________________________________
% Authors: Johannes Fischer
% Yanis Taege
% TODO:
% - implement ROI_Signal nvp
% - implement ROI_Noise nvp
% - implement SaveImage nvp
properties (Access = private)
% DISPLAYING
locValString
dimensionLabel
% stores information about the grid in the control bar
gridSize
% UI Elements
pColorbar
pImage
pSlider
pControls
pAdditionalSliders
locAndVals
hGuides % RGB plot guides in the axes
hBtnGuides
% UI properties
pSliderHeight
panelPos
controlPanelPos
sliderPos
figurePos
cr
end
properties (Constant, Access = private)
% UI PROPERTIES
% default figure position and size
defaultPosition = [ 300, 200, 1000, 800];
axColors = 'rgb';
end
methods
function obj = nvis3(in, varargin)
% CONSTRUCTOR
obj@nvisBase(in, varargin{:})
% Three axes are shown in nvis3
obj.nAxes = 3;
% one of the following two should be thrown away
obj.activeAx = 1;
obj.activeDim = 1;
obj.cbDirection = 'horizontal';
if obj.nDims < 4
% TODO: if obj.nDims == 2: open nvis instead
obj.nSlider = 3;
obj.mapSliderToImage = num2cell(1:3);
else
obj.nSlider = obj.nDims;
obj.mapSliderToImage = cat(2, num2cell(1:3), repmat({':'}, [1, obj.nSlider-3]));
end
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()
% definer additional Prameters
addParameter(obj.p, 'InitSlice', round(obj.S(1:3)/2), @isnumeric);
addParameter(obj.p, 'Crosshair', 1, @isnumeric);
parse(obj.p, obj.varargin{:});
obj.cmap{1} = obj.p.Results.Colormap;
obj.complexMode = obj.p.Results.ComplexMode;
obj.resize = obj.p.Results.Resize;
obj.cr = obj.p.Results.Crosshair;
obj.contrast = obj.p.Results.Contrast;
obj.overlay = obj.p.Results.Overlay;
obj.unit = obj.p.Results.Unit;
% 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()
obj.createSelector()
% necessary for view orientation
obj.azimuthAng = obj.p.Results.InitRot;
% overwrite the default value fot maxLetters in locVal section
obj.maxLetters = 8;
obj.setValNames()
obj.setLocValFunction()
obj.prepareSliceData()
obj.prepareGUI()
obj.refreshUI()
obj.guiResize()
obj.recolor()
set(obj.f, 'Visible', 'on');
% do not assign to 'ans' when called without assigned variable
if nargout == 0
clear obj
end
end
function prepareGUI(obj)
set(obj.f, ...
'name', obj.p.Results.Title, ...
'Units', 'pixel', ...
'Position', obj.p.Results.Position, ...
'Visible', 'on', ...
'ResizeFcn', @obj.guiResize, ...
'CloseRequestFcn', @obj.closeRqst, ...
'WindowButtonMotionFcn',@obj.mouseMovement, ...
'WindowButtonUpFcn', @obj.stopDragFcn, ...
'WindowScrollWheelFcn', @obj.scrollSlider);
obj.setPanelPos()
% create and place panels
for iim = 1:3
obj.pImage(iim) = uipanel( ...
'Units', 'pixels', ...
'Position', obj.panelPos(iim, :), ...
'BackgroundColor', obj.COLOR_BG, ...
'HighLightColor', obj.COLOR_BG, ...
'ShadowColor', obj.COLOR_B);
obj.pSlider(iim) = uipanel( ...
'Units', 'pixels', ...
'Position', obj.panelPos(iim+3, :), ...
'BackgroundColor', obj.COLOR_BG, ...
'HighLightColor', obj.COLOR_BG, ...
'ShadowColor', obj.COLOR_B);
end
obj.pColorbar = uipanel( ...
'Units', 'pixels', ...
'Position', obj.panelPos(7, :), ...
'BackgroundColor', obj.COLOR_BG, ...
'HighLightColor', obj.COLOR_BG, ...
'ShadowColor', obj.COLOR_B);
obj.pControls = uipanel( ...
'Units', 'pixels', ...
'Position', obj.panelPos(8, :), ...
'BackgroundColor', obj.COLOR_BG, ...
'HighLightColor', obj.COLOR_BG, ...
'ShadowColor', obj.COLOR_B);
obj.pAdditionalSliders = uipanel( ...
'Units', 'pixels', ...
'Position', obj.panelPos(9, :), ...
'BackgroundColor', obj.COLOR_BG, ...
'HighLightColor', obj.COLOR_BG, ...
'ShadowColor', obj.COLOR_B);
%% set UI elements
% populate image panels
ax = gobjects(1, obj.nAxes);
obj.hGuides = gobjects(obj.nAxes, 4);
obj.hImage = gobjects(1, obj.nAxes);
for iim = 1:obj.nAxes
% axes are not members of nvisBase or nvis3, to get the
% handle to an axis use: get(hImage(i), 'Parent')
ax(iim) = axes(...
'Parent', obj.pImage(iim), ...
'Units', 'normalized', ...
'Position', [0 0 1 1]);
obj.hImage(iim) = imagesc(obj.sliceMixer(iim), 'Parent', ax(iim)); % plot image
hold on
eval(['axis ', obj.p.Results.AspectRatio]);
set(obj.hImage(iim), 'ButtonDownFcn', @obj.startDragFcn)
colormap(ax(iim), obj.cmap{1});
view([obj.azimuthAng(iim) 90])
for igu = 1:4
obj.hGuides(iim, igu) = plot([1 1], [1 1], ...
'Color', obj.axColors(obj.showDims(iim, abs(ceil((igu-6)/2)))));
end
end
set(ax, ...
'XTickLabel', '', ...
'YTickLabel', '', ...
'XTick', [], ...
'YTick', []);
% populate slider panels
for iSlider = 1:obj.nDims
% if dimension is singleton, set slider steps to 0
if obj.S(iSlider) == 1
steps = [0 0];
else
steps = [1/(obj.S(iSlider)-1) 10/(obj.S(iSlider)-1)];
end
if iSlider <= 3
panel = obj.pSlider(iSlider);
else
panel = obj.pAdditionalSliders;
end
obj.hTextSlider(iSlider) = uicontrol( ...
'Parent', panel, ...
'Style', 'text', ...
'Units', 'normalized', ...
'Position', [0.01 1/8 0.1 6/8], ...
'String', [obj.dimLabel{iSlider} ':'], ...
'FontUnits', 'normalized', ...
'FontSize', 0.8, ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
obj.hEditSlider(iSlider) = uicontrol( ...
'Parent', panel, ...
'Style', 'edit', ...
'Units', 'normalized', ...
'Position', [0.11 1/8 0.1 6/8], ...
'String', obj.dimVal{iSlider}{obj.sel{min(3, iSlider), iSlider}}, ...
'FontUnits', 'normalized', ...
'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', panel, ...
'Style', 'slider', ...
'Units', 'normalized', ...
'Position', [0.21 1/8 0.6 6/8], ...
'Min', 1, ...
'Max', obj.S(iSlider), ...
'Value', obj.sel{min(3, obj.mapSliderToDim(iSlider)), obj.mapSliderToDim(iSlider)}, ...
'SliderStep', steps, ...
'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));
if iSlider <= 3
obj.hBtnRotL(iSlider) = uicontrol( ...
'Parent', obj.pSlider(iSlider), ...
'Style', 'pushbutton', ...
'Units', 'normalized', ...
'Position', [0.81 1/8 0.07 6/8], ...
'String', char(11119), ...
'Tooltip', 'rotate image clockwise by 90°', ...
'Callback', { @obj.rotateView, -90}, ...
'FontUnits', 'normalized', ...
'FontSize', 0.75, ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
obj.hBtnRotR(iSlider) = uicontrol( ...
'Parent', obj.pSlider(iSlider), ...
'Style', 'pushbutton', ...
'Units', 'normalized', ...
'Position', [0.88 1/8 0.07 6/8], ...
'String', char(11118), ...
'Tooltip', 'rotate image counter-clockwise by 90°', ...
'Callback', { @obj.rotateView, 90}, ...
'FontUnits', 'normalized', ...
'FontSize', 0.75, ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F);
end
if obj.S(obj.mapSliderToDim(iSlider)) == 1
% dont show the slider, if both inputs are singleton,
% or if the single input is singleton (i.e. obj.S ~= 1)
set(obj.hSlider(iSlider), 'Visible', 'off');
end
end
% populate control panel
obj.genControlPanelGrid()
set(obj.hTextC, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', 'Center:', ...
'FontUnits', 'normalized', ...
'FontSize', 0.7, ...
'HorizontalAlignment', 'left');
set(obj.hTextW, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', 'Width:', ...
'FontUnits', 'normalized', ...
'FontSize', 0.7, ...
'HorizontalAlignment', 'left');
for idh = 1:obj.nImages
set(obj.hEditC(idh), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'HorizontalAlignment', 'right', ...
'FontUnits', 'normalized', ...
'FontSize', 0.4, ...
'FontName', 'FixedWidth', ...
'ForegroundColor', obj.COLOR_m(idh, :));
set(obj.hEditW(idh), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'HorizontalAlignment', 'right', ...
'FontUnits', 'normalized', ...
'FontSize', 0.4, ...
'FontName', 'FixedWidth', ...
'ForegroundColor', obj.COLOR_m(idh, :));
set(obj.hPopCm(idh), ...
'Parent', obj.pControls, ...
'FontUnits', 'normalized', ...
'FontSize', 0.6);
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, :));
set(obj.hPopCm(idh), ...
'Parent', obj.pControls, ...
'FontUnits', 'normalized', ...
'FontSize', 0.6);
set(obj.hPopOverlay, ...
'Parent', obj.pControls, ...
'FontUnits', 'normalized', ...
'FontSize', 0.6);
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
%ROI elements
set(obj.hBtnRoi(1), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', 'Signal', ...
'FontUnits', 'normalized', ...
'FontSize', 0.4, ...
'TooltipString', 'draw signal ROI');
set(obj.hBtnRoi(2), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', 'Noise', ...
'FontUnits', 'normalized', ...
'FontSize', 0.4, ...
'TooltipString', 'draw noise ROI');
set(obj.hTextSNR, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', 'SNR:', ...
'HorizontalAlignment', 'left', ...
'FontUnits', 'normalized', ...
'FontSize', 0.6);
set(obj.hTextRoi(1), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', '', ...
'Tooltip', 'mean value inside signal ROI', ...
'HorizontalAlignment', 'right', ...
'FontUnits', 'normalized', ...
'FontSize', 0.45, ...
'FontName', 'FixedWidth');
set(obj.hTextRoi(2), ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', '', ...
'Tooltip', 'standard deviation inside noise ROI', ...
'HorizontalAlignment', 'right', ...
'FontUnits', 'normalized', ...
'FontSize', 0.45, ...
'FontName', 'FixedWidth');
set(obj.hTextSNRvals, ...
'Parent', obj.pControls, ...
'Units', 'pixel', ...
'String', '', ...
'HorizontalAlignment', 'right', ...
'FontUnits', 'normalized', ...
'FontSize', 0.45, ...
'FontName', 'FixedWidth', ...
'TooltipString', 'signal / noise');
obj.hBtnGuides = uicontrol(...
'Parent', obj.pControls, ...
'Style', 'togglebutton', ...
'String', 'Guides', ...
'FontUnits', 'normalized', ...
'FontSize', 0.4, ...
'TooltipString', 'Toggle between showing and hiding the guides', ...
'BackgroundColor', obj.COLOR_BG, ...
'ForegroundColor', obj.COLOR_F, ...
'Callback', {@obj.toggleGuides});
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
obj.locAndVals = annotation(obj.pControls, 'textbox', ...
'LineStyle', 'none', ...
'Units', 'pixel', ...
'String', '', ...
'HorizontalAlignment', 'left', ...
'FontUnits', 'pixel', ...
'FontSize', 16, ...
'FontName', 'FixedWidth', ...
'BackgroundColor', obj.COLOR_BG, ...
'Interpreter', 'Tex');
%% OVERWRITE TOOLBAR BUTTONS
for idh = 1:obj.nImages
% create the colorbar axis for the colorbarpanel
obj.hAxCb(idh) = axes('Units', 'normal', ...
'Position', [1/9+(idh-1)*4/9 1/3 1/3 1/3], ...
'Parent', obj.pColorbar, ...
'Color', obj.COLOR_m(idh, :));
imagesc(linspace(0, 1, size(obj.cmap{idh}, 1)));
colormap(obj.hAxCb(idh), obj.cmap{idh});
caxis(obj.hAxCb(idh), [0 1])
% remove unnecessary Y ticks and labels
set(obj.hAxCb(idh), ...
'YTickLabel', [], ...
'YTick', []);
end
% hide colorbar
obj.cbShown = true;
obj.toggleCb()
% change callback of 'colorbar' icon in MATLAB toolbar
hToolColorbar = findall(gcf, 'tag', 'Annotation.InsertColorbar');
set(hToolColorbar, 'ClickedCallback', {@obj.toggleCb});
end
function setPanelPos(obj)
pos = get(obj.f, 'Position');
% set size of controlHeight
colorbarHeight = 80; % px
slidersHeight = 30; % px
controlHeight = 120; % px
% pImage(..), pColorbar, pSliders, pControl
for iim = 1:3
obj.panelPos(iim, :) = [(iim-1)*1/3*pos(3) ...
controlHeight+slidersHeight ...
1/3*pos(3) ...
pos(4)-controlHeight-slidersHeight-colorbarHeight];
obj.panelPos(iim+3, :) = [(iim-1)*1/3*pos(3) ...
controlHeight ...
1/3*pos(3) ...
slidersHeight];
end
% pColorbar
obj.panelPos(7, :) = [0 ...
pos(4)-colorbarHeight ...
pos(3) ...
colorbarHeight];
% pControls
obj.panelPos(8, :) = [0 ...
0 ...
2/3*pos(3) ...
controlHeight];
% pAdditionalSliders
obj.panelPos(9, :) = [2/3*pos(3) ...
0 ...
1/3*pos(3) ...
controlHeight];
end
function genControlPanelGrid(obj)
% if obj.nImages == 1
% obj.gridSize = [3 8];
% else
obj.gridSize = [4 8];
% end
pos = get(obj.pControls, 'Position');
xPadding = 3;
yPadding = 3;
width = 90;%(pos(3) - (obj.gridSize(2)+1)*xPadding) / obj.gridSize(2);
height = (pos(4) - (obj.gridSize(1)+1)*yPadding) / obj.gridSize(1);
% repeat arrays to create gridSize x 4 matrix
width = repmat(width, [1, obj.gridSize(2)]);
% set some columns to fixed width
if obj.nImages == 1
width(3) = 0;
end
w0 = [xPadding cumsum(width, 2) + (1:obj.gridSize(2)) * xPadding];
h0 = pos(4) - yPadding - (1:obj.gridSize(1)) * (height+yPadding);
width = repmat(width, [obj.gridSize(1) 1]);
height = repmat(height, obj.gridSize);
w0 = repmat(w0(1:end-1), [obj.gridSize(1) 1]);
h0 = repmat(h0', [1 obj.gridSize(2)]);
obj.controlPanelPos = cat(3, w0, h0, width, height);
end
function setSliderPos(obj)
maxHeight = 22;
vPadding = 2;
% get panel size
pos = get(obj.pAdditionalSliders, 'Position');
sliderHeight = min(maxHeight, (pos(4) - (obj.nSlider+1)*vPadding) / (obj.nSlider-3));
obj.sliderPos = zeros(obj.nSlider, 4);
for iSlider = 1:obj.nSlider
if iSlider > 3
set(obj.hSlider(iSlider), 'units', 'pixels')
obj.sliderPos(iSlider, :) = [0.17*pos(3) pos(4)-(iSlider-3)*(vPadding+sliderHeight) 0.6*pos(3) sliderHeight];
end
end
end
function guidePos = calcGuidePos(obj)
guidePos = zeros(obj.nAxes, 4, 4);
for iim = 1:obj.nAxes
guidePos(iim, 1, :) = [...
obj.sel{obj.showDims(iim, 2), obj.showDims(iim, 2)}*obj.resize, ...
obj.sel{obj.showDims(iim, 2), obj.showDims(iim, 2)}*obj.resize, ...
0.5, ...
obj.sel{obj.showDims(iim, 1), obj.showDims(iim, 1)}*obj.resize-obj.cr];
guidePos(iim, 2, :) = [...
obj.sel{obj.showDims(iim, 2), obj.showDims(iim, 2)}*obj.resize, ...
obj.sel{obj.showDims(iim, 2), obj.showDims(iim, 2)}*obj.resize, ...
obj.sel{obj.showDims(iim, 1), obj.showDims(iim, 1)}*obj.resize+obj.cr, ...
obj.S(obj.showDims(iim, 1))*obj.resize+0.5];
guidePos(iim, 3, :) = [...
0.5, ...
obj.sel{obj.showDims(iim, 2), obj.showDims(iim, 2)}*obj.resize-obj.cr, ...
obj.sel{obj.showDims(iim, 1), obj.showDims(iim, 1)}*obj.resize, ...
obj.sel{obj.showDims(iim, 1), obj.showDims(iim, 1)}*obj.resize];
guidePos(iim, 4, :) = [...
obj.sel{obj.showDims(iim, 2), obj.showDims(iim, 2)}*obj.resize+obj.cr, ...
obj.S(obj.showDims(iim, 2))*obj.resize+0.5, ...
obj.sel{obj.showDims(iim, 1), obj.showDims(iim, 1)}*obj.resize, ...
obj.sel{obj.showDims(iim, 1), obj.showDims(iim, 1)}*obj.resize];
end
end
function createSelector(obj)
% which dimensions are shown initially
obj.showDims = [2 3; 1 3; 1 2];
obj.mapSliderToDim = 1:obj.nDims;
% create slice selector for dimensions 3 and higher
obj.sel = repmat({':'}, obj.nAxes, max(ndims(obj.img{1}), ndims(obj.img{1})));
for iim = 1:obj.nAxes
obj.sel(iim, obj.mapSliderToDim == iim) = num2cell(obj.p.Results.InitSlice(iim));
end
for iSlider = 4:obj.nDims
obj.sel(:, iSlider) = num2cell(round(obj.S(iSlider)/2));
end
% consider singleton dimensions
obj.sel(:, obj.S == 1) = {1};
% obj.sel{obj.S == 1} = 1; does not work here, because the
% condition might return an empty array which fails with curly
% brackets
end
function refreshUI(obj)
% fill obj.slice
obj.prepareSliceData;
for iim = 1:obj.nAxes
% update the images
set(obj.hImage(iim), 'CData', obj.sliceMixer(iim));
% set position of guides
if true % guides visible
guidePos = obj.calcGuidePos();
set(obj.hGuides(iim, 1), ...
'XData', guidePos(iim, 1, 1:2), ...
'YData', guidePos(iim, 1, 3:4));
set(obj.hGuides(iim, 2), ...
'XData', guidePos(iim, 2, 1:2), ...
'YData', guidePos(iim, 2, 3:4));
set(obj.hGuides(iim, 3), ...
'XData', guidePos(iim, 3, 1:2), ...
'YData', guidePos(iim, 3, 3:4));
set(obj.hGuides(iim, 4), ...
'XData', guidePos(iim, 4, 1:2), ...
'YData', guidePos(iim, 4, 3:4));
end
end
for iSlider = 1:obj.nSlider
% update the values is the edit fields
if obj.mapSliderToImage{iSlider} == ':'
val = obj.sel{1, iSlider};
else
val = obj.sel{obj.mapSliderToDim(iSlider), obj.mapSliderToDim(iSlider)};
end
if iSlider < 4
set(obj.hEditSlider(iSlider), 'String', obj.dimVal{iSlider}{obj.sel{iSlider, iSlider}});
else
set(obj.hEditSlider(iSlider), 'String', obj.dimVal{iSlider}{obj.sel{1, iSlider}});
end
set(obj.hSlider(iSlider), 'Value', val);
end
% update 'val' when changing slice
obj.mouseMovement();
% if ~isempty(Sroi) | ~isempty(Nroi)
% % only calculate SNR, when there are ROIs to calculate
% calcROI();
% end
end
function activateAx(obj, axNo)
if obj.activeAx ~= axNo
obj.activeAx = axNo;
obj.activeDim = axNo;
for iax = 1:obj.nAxes
set(get(obj.hImage(iax), 'Parent'), 'XColor', [0 0 0]);
set(get(obj.hImage(iax), 'Parent'), 'YColor', [0 0 0]);
end
% TODO: implement 4th slider first
% set(pSlider(4),'ShadowColor',color_B)
if axNo < 4
axes(get(obj.hImage(axNo), 'Parent'))
set(get(obj.hImage(axNo), 'Parent'), ...
'XColor', obj.axColors(obj.activeAx), ...
'YColor', obj.axColors(obj.activeAx));
else
% set(pSlider(4),'ShadowColor', color_F)
end
end
end
function activateSlider(obj, dim)
% change current axes and indicate to user by drawing coloured line
% around current axes, but only if dim wasnt the active axis before
if obj.activeDim ~= dim
obj.activeDim = dim;
end
if obj.nSlider < 4
obj.activateAx(dim);
end
end
function incDecActiveDim(obj, incDec)
% change the active dimension by incDec
if obj.activeDim <= obj.nAxes
obj.sel{obj.activeAx, obj.activeDim} = obj.sel{obj.activeAx, obj.activeDim} + incDec;
% check whether the value is too large and take the modulus
obj.sel{obj.activeAx, obj.activeDim} = mod(obj.sel{obj.activeAx, obj.activeDim}-1, obj.S(obj.activeDim))+1;
else
% change selector in all visible axes
for iAx = 1:obj.nAxes
obj.sel{iAx, obj.activeDim} = obj.sel{iAx, obj.activeDim} + incDec;
obj.sel{iAx, obj.activeDim} = mod(obj.sel{iAx, obj.activeDim}-1, obj.S(obj.activeDim))+1;
end
end
obj.refreshUI();
end
function mouseBtnAlt(obj, src, evtData)
Pt = round(get(gca, 'CurrentPoint')/obj.resize);
iim = find(src == obj.hImage);
obj.sel{obj.showDims(iim, 1), obj.showDims(iim, 1)} = Pt(1, 2);
obj.sel{obj.showDims(iim, 2), obj.showDims(iim, 2)} = Pt(1, 1);
obj.refreshUI()
end
function mouseBtnDouble(obj, src, ~)
axNo = find(obj.hImage == src);
callingAx = src.Parent;
Pt = get(callingAx, 'CurrentPoint');
coords = [Pt(1, 2) Pt(1, 1)];
dims = obj.showDims(axNo, :);
for iAx = 1:3
if iAx ~= axNo
dim = iAx == dims;
obj.sel{iAx, dims(dim)} = round(coords(dim));
end
end
obj.refreshUI()
end
function mouseBtnNormal(obj, src, evtData)
% code executed when the user presses the left mouse button.
% currently not implemented.
end
function recolor(obj)
% this function is callen, when the user changes a colormap in
% the GUI. To keep the colors consistent an easier
% attribuateble ti each in put, the colors in the GUI need to
% be adapted. Specifically in the locValString and the slider
% indices in the case of uniquely singleton dimensions.
obj.setLocValFunction()
% reset color to standard foreground color
set(obj.hEditSlider, 'ForegroundColor', obj.COLOR_F)
% if necessary, change color for unique singleton
% dimensions
for iImg = 1:obj.nImages
stonSliderDims = ismember(obj.mapSliderToDim, obj.ston{iImg});
set(obj.hEditSlider(stonSliderDims), ...
'ForegroundColor', obj.COLOR_m(mod(iImg, 2)+1, :))
end
end
function setLocValFunction(obj)
% sets the function for the locAndVal string depending on the
% amount of input images
% check 'Units' input
if ~contains('Unit', obj.p.UsingDefaults)
if ischar(obj.unit)
% make it a cell array
obj.unit = {obj.unit, obj.unit};
end
end
if obj.nImages == 1
obj.locValString = @(dim1L, dim1, dim2L, dim2, dim3L, dim3, val) sprintf('\\color[rgb]{%.2f,%.2f,%.2f}%s:%s\n%s:%s\n%s:%s\n%s:%s', ...
obj.COLOR_F, ...
dim1L, ...
dim1, ...
dim2L, ...
dim2, ...
dim3L, ...
dim3, ...
obj.valNames{1}, ...
[num2sci(val) ' ' obj.unit{1}]);
else
% check the currently shown dimensions for necessity of color
% indication, if one input is singleton along dimension
adjColorStr = {'', '', ''};
for iImg = 1:obj.nImages
% in nvis3, always the first three dimensions are
% shown
match = ismember([1 2 3], obj.ston{iImg});
for iDim = find(match)
% set color to different dimensions color
adjColorStr{iDim} = sprintf('\\color[rgb]{%.2f,%.2f,%.2f}', obj.COLOR_m(mod(iImg, 2)+1, :));
end
end
obj.locValString = @(dim1L, dim1, dim2L, dim2, dim3L, dim3, val1, val2) ...
sprintf('\\color[rgb]{%.2f,%.2f,%.2f}%s:%s%s\n\\color[rgb]{%.2f,%.2f,%.2f}%s:%s%s\n\\color[rgb]{%.2f,%.2f,%.2f}%s:%s%s\n\\color[rgb]{%.2f,%.2f,%.2f}%s:%s\n\\color[rgb]{%.2f,%.2f,%.2f}%s:%s', ...
obj.COLOR_F, ...
dim1L, ...
adjColorStr{1}, ...
dim1, ...
obj.COLOR_F, ...
dim2L, ...
adjColorStr{2}, ...
dim2, ...
obj.COLOR_F, ...
dim3L, ...
adjColorStr{3}, ...
dim3, ...
obj.COLOR_m(1, :), ...
obj.valNames{1}, ...
[num2sci(val1) obj.unit{1}], ...
obj.COLOR_m(2, :), ...
obj.valNames{2}, ...
[num2sci(val2) obj.unit{2}]);
end
end
function locVal(obj, point, axNo)
if ~isempty(point)
switch (axNo)
case 1
point = [obj.sel{axNo, axNo}, point(:)'];
case 2
point = [point(1), obj.sel(axNo, axNo), point(2)];
case 3
point = [point(:)', obj.sel{axNo, axNo}];
end
if obj.nImages == 1
val = obj.slice{axNo}(point{obj.showDims(axNo, :)});
set(obj.locAndVals, 'String', obj.locValString(...