forked from owenrandlett/Z-Brain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZBrainViewer.m
2394 lines (1909 loc) · 81.4 KB
/
ZBrainViewer.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 ZBrainViewer(ViewerMode, InitialGreyStackNo, SectDim)
%Optional Input Arguments = ZebrafishBrainVeiwer7(ViewerMode, InitialGreyStackNo, SectDim)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This function will allow the user to explore the larval zebrafish anatomy
% database. Instructions for interacting with the data are displayed when
% the program is started. Requires at least the 2013a version of Matlab.
% Confocal data (mean across fish) is contained within the file
% 'AnatomyLabelDatabase.hdf5'. The masks outlining the anatomical regions
% are contained within the file 'MaskDatabase.mat'. If the function
% 'ZBrainViewer.m' and the files are in Matlab's path, the images should
% open when the function is started. If not, you will need to point to the
% folder containing the files.
%
%
% Tested and written using Matlab R2014a running on OSx 10.9.3 by Owen
% Randlett ([email protected]). October 17, 2014.
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Input Arguments = ZBrainViewer(ViewerMode, InitialGreyStackNo, SectDim)
%
%%%%% ViewerMode = 0 --- (default). Anatomy database browsing mode only
%
% no additional image stacks are asked for
%
%
%
%%%%% ViewerMode = 1 --- Comparison to other Tiff stack
%
% This mode will overlay the anatomy database with another tiff stack. This
% can be used, for example, to compare the anatomy database to a new
% transgene or label, or to a MAP-Map. The label must be prepared as either
% a signle channel or three channel (RGB/composite) tiff stack (can be done
% by saving as a Tiff in FIJI/ImageJ). The stack must have been already
% registered into the reference brain, so as to be the correct resolution.
% Intensityies will be scaled to the max values in the satck.
%
%%%%%% InitialGreyStackNo - The number of the stack to load into the grey
%%%%%% channel at the beginning of the program
%
% InitialGreyStackNo = 0 -- load in the Elavl3-H2BRFP stack (default)
%
% InitialGreyStackNo >= 1 -- this stack number is loaded into the grey channel,
% ordered by the stack order in the hdf5 file. If InitialGreyStackNo >
% number of stacks, one is selected randomly
%
%%%%%% SectDim - the dimension/plane of sectioning. Note that ROI creation
%%%%%% and 'click to define regions' currently only work in the default
%%%%%% (coronal) view
%
% SectDim = 0 -- coronal (default)
% SectDim = 1 -- transverse
% SectDom = 2 -- saggital
%%%%%%
% Exporting data
%
% The 'AnatomyLabelDatabase.hdf5' file is in hdf5 format, and therefore
% should be directly readable by some imaging software packages (for
% example using the HDF5 plugin for FIJI). Or these can be read into Matlab
% using 'h5read' function, and then exported in whichever format you like.
% The mean-stacks in the HDF5 file are 3D image stacks, with an image size of
% 1406 x 621 x 138 (y, x, z), and voxel physical size of 0.798 um (x/y) and
% 2um (z).
%
% The 'MaskDatabse' variable in the MaskDatabase.mat file contains the
% regional mask definitions. These are stored as 2D sparse logical arrays,
% where each column is a regional mask. These can be reconstructed using
% reshape(full(MaskDatabase(:,x)), [height, width, Zs]), where height, width, Zs
% is the native the image size (1406, 621, 138). 'MaskDatabaseNames' lists
% the names of the regions. Once reconstructed these could similarly be
% exported as image stacks.
%
% 'MaskDatabaseDownsampled.mat' and 'AnatomyLabelDatabase.mat' are
% downsampled versions of the same files, at a resolution that matches the
% MAP-Maps: 679x300x80 (x, y, z). These are used by the
% 'ZBrainAnalysisOfMAPMaps.m' function.
%% Parse Inputs
if nargin == 0
ViewerMode = 0; % if no value is passed, just load the anatomy database, do not ask for a MAP-Map
SectDim = 0;
InitialGreyStackNo = 0;
disp('running "Default Viewermode", loading Elavl3:H2BRFP Stack')
elseif nargin == 1
InitialGreyStackNo = 0; % load tERK stack if variable is not passed
if ViewerMode == 0; % if no value is passed, just load the anatomy database, do not ask for a MAP-Map
disp('running "Default Viewermode", loading Elavl3:H2BRFP Stack')
elseif ViewerMode == 1
disp('running "Comparison To new stack Viewermode"')
else
warning('Invalid input!!! overriding and running "Default Viewermode", loading Elavl3:H2BRFP Stack')
end
SectDim = 0;
elseif nargin == 2
if ViewerMode == 0;
disp('running "Default Viewermode", loading specified stack')
elseif ViewerMode == 1
disp('running "MAP-Map Comparison Viewermode", loading specified Stack')
elseif ViewerMode == 2
disp('running "Comparison To Other Tiff Stack Viewermode"')
else
warning('Invalid input!!! overriding and running "Default Viewermode"')
end
SectDim = 0;
elseif nargin == 3
if ViewerMode == 0;
disp('running "Default Viewermode", loading specified stack')
elseif ViewerMode == 1
disp('running "Comparison To Other Tiff Stack Viewermode"')
else
warning('Invalid input!!! overriding and running "Default Viewermode"')
end
if SectDim == 0
disp('Coronal View')
elseif SectDim == 1
disp('Transverse View')
elseif SectDim == 2
disp('Saggital View')
else
warning('Invalid sectioning input, running Coronal View')
SectDim = 0;
end
elseif nargin > 3
ViewerMode = 0;
warning('Invalid input!!! overriding and running "Default Viewermode", loading tERK Stack')
end
% check version
Ver = version('-release');
if str2double(Ver(1:4)) < 2014
beep on;
beep
warning('You are running an old version of Matlab - upgrade to avoid errors related to how MATLAB handles HDF5 files');
end
%% Intialize variables
global imFig
global sliderFig
global rect
global DisplaySlice
global PrintSlice
global GetMaskName
global ShiftingTime
global currentPos
global lastPos
global xSubtractor
global ySubtractor
global ClearMasks
global firstPos
global MakeNewRegionMask
global FinishNewMask
global SaveMask
global ClearMaskSlice
global WriteMask
global ChangeDim
global PrintStack;
global FirstSlice;
global upSlice;
global downSlice;
global ZoomIn;
global ZoomOut;
ChangeDim = 0;
rect = [0,0,0,0];
PrintSlice = 0;
GetMaskName = 0;
ShiftingTime = 0;
currentPos = 0;
lastPos = [0,0];
MakeNewRegionMask = 0;
FinishNewMask = 0;
SaveMask = 0;
ClearMaskSlice = 0;
MakingNewMask = 0;
ZRez = 2; % the voxel size of the reference brain
XYRez = 0.789;
PrintStack = 0;
upSlice = 0;
downSlice = 0;
ZoomIn = 0;
ZoomOut = 0;
%
try
StacksDir = which('AnatomyLabelDatabase.hdf5');
StacksDir = strrep(StacksDir, 'AnatomyLabelDatabase.hdf5', '');
cd(StacksDir)
catch
StacksDir = uigetdir('*.hdf5', 'Select Directory With the Z-Brain Files (AnatomyLabelDatabase.hdf5 and MaskDatabase.mat)');
cd(StacksDir);
addpath(StacksDir);
end
% get the HDF5 file info
hdf5fileInfo = h5info('AnatomyLabelDatabase.hdf5');
filesLabels = hdf5fileInfo.Datasets;
for i =1:length(filesLabels)
filesLabels(i).hdf5Name = 'AnatomyLabelDatabase.hdf5';
end
% find any other HDF5 files, not including AnatomyLabelDatabaseDownsampled
OtherHDF5Files = dir('*.hdf5');
for i = length(OtherHDF5Files):-1:1
if strcmp(OtherHDF5Files(i).name, 'AnatomyLabelDatabase.hdf5') ==0 && strcmp(OtherHDF5Files(i).name, 'AnatomyLabelDatabaseDownsampled.hdf5') == 0
hdf5fileInfo = h5info(OtherHDF5Files(i).name);
newfilesLabels = hdf5fileInfo.Datasets;
for j = 1:length(newfilesLabels)
newfilesLabels(j).hdf5Name = OtherHDF5Files(i).name;
end
filesLabels = [filesLabels; newfilesLabels];
end
end
ImageSize = filesLabels(1).Dataspace.Size;
height = ImageSize(1);
width = ImageSize(2);
Zs = ImageSize(3);
% load in the mask database '.mat' file, containing the anatomy ROIs
load('MaskDatabase.mat');
% set up the string for the dropdown menu to load in the stacks
for i = 1:length(filesLabels)+1
if i == 1
popupnamesLabels = '-';
else
FullName = filesLabels(i-1).Name;
EndPos = strfind(filesLabels(i-1).Name, 'dpf') - 2;
if numel(EndPos) > 0
TruncName = FullName(1:EndPos-1);
else
TruncName = FullName(1:end);
end
popupnamesLabels = strcat(popupnamesLabels, '|', TruncName);
if strfind(filesLabels(i-1).Name, 'Elavl3-H2BRFP_6dpf_MeanImageOf10Fish') == 1
H2BStack = i;
end
end
end
popupnamesMasks = cell(1, length(MaskDatabaseNames) + 1);
popupnamesMasks(1, 2:end) = MaskDatabaseNames;
if ViewerMode == 1; % load in the new stack, either to RGB or grey channel. upsize appropriately
[TiffName, TiffPath] = uigetfile('*.tif', 'Select the new stack');
cd(TiffPath)
info = imfinfo(TiffName);
ZsTiff = length(info);
heightTiff = info(1).Height;
widthTiff = info(1).Width;
nChan = length(info(1).BitsPerSample);
if nChan ~= 3; % check if not RGB image
greyStack = zeros(heightTiff, widthTiff, ZsTiff);
wait = waitbar(0, 'Loading new Stack', 'Color', [1 1 1]);
set(findobj(wait,'type','patch'), ...
'edgecolor','k','facecolor','k')
for Sect = 1:ZsTiff
TempSlice = double(imread(TiffName, Sect, 'info', info));
if numel(info(1).BitsPerSample) == 1 % if it is a 1 channel image
greyStack(:,:,Sect) = TempSlice;
elseif numel(info(1).BitsPerSample) > 1 % someone tries to load in a 3 channel image or something, sum the channels to make a greyscale image
greyStack(:,:,Sect) = squeeze(sum(TempSlice, 3));
if Sect == 1
h = warndlg('loading in a mutlichannel image, it will be converted to one channel');
warning('loading in a mutlichannel image, it will be converted to one channel')
elseif Sect==ZsTiff
close(h)
end
end
waitbar(Sect/ZsTiff)
end
close(wait)
if ZsTiff ~=Zs || heightTiff ~= height || widthTiff ~= width
wait = waitbar(0, 'RE-Sizing stack to fit Anatomy Database', 'Color', [1 1 1]);
set(findobj(wait,'type','patch'), ...
'edgecolor','k','facecolor','k')
nLoops = ZsTiff + width;
StackTemp = zeros(height, width, ZsTiff);
for Sect = 1:ZsTiff
StackTemp(:,:,Sect) = imresize(greyStack(:,:,Sect), [height, width], 'method', 'nearest');
waitbar(Sect/nLoops)
end
greyStack = zeros(height, width, Zs);
for w = 1:width
greyStack(:,w,:) = imresize(squeeze(StackTemp(:, w, :)), [height, Zs], 'method', 'nearest');
waitbar((ZsTiff + w)/nLoops)
end
greyStack = uint16(65535.*greyStack./max(greyStack(:)));
close(wait);
end
end
if nChan == 3
rStackOriginal= zeros(heightTiff, widthTiff, ZsTiff);
gStackOriginal= zeros(heightTiff, widthTiff, ZsTiff);
bStackOriginal= zeros(heightTiff, widthTiff, ZsTiff);
wait = waitbar(0, 'Loading 3-color stack', 'Color', [0 1 0]);
set(findobj(wait,'type','patch'), ...
'edgecolor','m','facecolor','m')
for Sect = 1:ZsTiff
TempSlice = imread(TiffName, Sect, 'info', info);
rStackOriginal(:,:,Sect) = squeeze(TempSlice(:,:,1));
gStackOriginal(:,:,Sect) = squeeze(TempSlice(:,:,2));
bStackOriginal(:,:,Sect) = squeeze(TempSlice(:,:,3));
waitbar(Sect/ZsTiff)
end
close(wait);
StackMax = max(max([rStackOriginal(:), gStackOriginal(:), bStackOriginal(:)]));
if ZsTiff ~=Zs || heightTiff ~= height || widthTiff ~= width
rStackOriginal = 65535.*rStackOriginal./StackMax;
gStackOriginal = 65535.*gStackOriginal./StackMax;
bStackOriginal = 65535.*bStackOriginal./StackMax;
wait = waitbar(0, 'UP-Sizing new stack to fit Anatomy Database', 'Color', [0 1 0]);
set(findobj(wait,'type','patch'), ...
'edgecolor','m','facecolor','m')
nLoops = ZsTiff + width;
rStackTemp = zeros(height, width, ZsTiff);
gStackTemp = zeros(height, width, ZsTiff);
bStackTemp = zeros(height, width, ZsTiff);
for Sect = 1:ZsTiff
rStackTemp(:,:,Sect) = imresize(rStackOriginal(:,:,Sect), [height, width], 'method', 'nearest');
gStackTemp(:,:,Sect) = imresize(gStackOriginal(:,:,Sect), [height, width], 'method', 'nearest');
bStackTemp(:,:,Sect) = imresize(bStackOriginal(:,:,Sect), [height, width], 'method', 'nearest');
waitbar(Sect/nLoops)
end
rStack = zeros(height, width, Zs);
gStack = zeros(height, width, Zs);
bStack = zeros(height, width, Zs);
for w = 1:width
rStack(:,w,:) = imresize(squeeze(rStackTemp(:, w, :)), [height, Zs], 'method', 'nearest');
gStack(:,w,:) = imresize(squeeze(gStackTemp(:, w, :)), [height, Zs], 'method', 'nearest');
bStack(:,w, :) = imresize(squeeze(bStackTemp(:, w, :)), [height, Zs], 'method', 'nearest');
waitbar((ZsTiff + w)/nLoops)
end
rStack = uint16(rStack);
gStack = uint16(gStack);
bStack = uint16(bStack);
close(wait)
else
rStack = 65535.*rStackOriginal./StackMax;
gStack = 65535.*gStackOriginal./StackMax;
bStack = 65535.*bStackOriginal./StackMax;
end
clear pERKSlice rStackOriginal gStackOriginal bStackOriginal rStackTemp gStackTemp bStackTemp
end
end
if ~exist('InitialGreyStackNo', 'var') || InitialGreyStackNo == 0
greyVal = H2BStack;
elseif InitialGreyStackNo > length(filesLabels) || InitialGreyStackNo < 0
greyVal = randi(length(filesLabels) + 1);
else
greyVal = InitialGreyStackNo + 1;
end
rVal = 1;
gVal = 1;
bVal = 1;
cVal = 1;
mVal = 1;
yVal = 1;
greyValMask = 1;
rValMask = 1;
gValMask = 1;
bValMask = 1;
cValMask = 1;
mValMask = 1;
yValMask = 1;
greyMaskStack = false(height, width, Zs);
rMaskStack = greyMaskStack;
gMaskStack = greyMaskStack;
bMaskStack = greyMaskStack;
cMaskStack = greyMaskStack;
mMaskStack = greyMaskStack;
yMaskStack = greyMaskStack;
%
%% Define the initial image paramaters
% initial image min/max scalings
greyMin = 1000;
greyMax = 25000;
rMin = 1000;
rMax = 25000;
gMin = 1000;
gMax = 25000;
bMin = 1000;
bMax = 25000;
cMin = 1000;
cMax = 25000;
mMin = 1000;
mMax = 25000;
yMin = 1000;
yMax = 25000;
% initial image opacities (the intenstiy values will be multiplied by this
% number (0 to 1) to reduce intensity or make image more transparent.
greyvalTransp = 1;
rvalTransp = 1;
gvalTransp = 1;
bvalTransp = 1;
cvalTransp = 1;
mvalTransp = 1;
yvalTransp = 1;
% initial image gammas
greyvalGamma = 1;
rvalGamma = 1;
gvalGamma = 1;
bvalGamma = 1;
cvalGamma = 1;
mvalGamma = 1;
yvalGamma = 1;
% opacity value of the mask outlines
greyvalMaskTransp = 0.7;
rvalMaskTransp = 0.7;
gvalMaskTransp = 0.7;
bvalMaskTransp = 0.7;
cvalMaskTransp = 0.7;
mvalMaskTransp = 0.7;
yvalMaskTransp = 0.7;
if SectDim == 0;
ImHeight = height;
ImWidth = width;
elseif SectDim == 1;
ImHeight = width;
ImWidth = Zs;
elseif SectDim == 2
ImHeight = height;
ImWidth = Zs;
end
greySlice = zeros(ImHeight, ImWidth);
rSlice = zeros(ImHeight, ImWidth);
gSlice = zeros(ImHeight, ImWidth);
bSlice = zeros(ImHeight, ImWidth);
cSlice = zeros(ImHeight, ImWidth);
mSlice = zeros(ImHeight, ImWidth);
ySlice = zeros(ImHeight, ImWidth);
greySliceMask = zeros(ImHeight, ImWidth);
rSliceMask = zeros(ImHeight, ImWidth);
gSliceMask = zeros(ImHeight, ImWidth);
bSliceMask = zeros(ImHeight, ImWidth);
cSliceMask = zeros(ImHeight, ImWidth);
mSliceMask = zeros(ImHeight, ImWidth);
ySliceMask = zeros(ImHeight, ImWidth);
nIter = 1;
%% Set up control figure with sliders
% this could be done in a more pretty way with loops, but for now just
% define each panel separately
sliderFig = figure;
set(sliderFig, 'menubar',...
'none','Units', 'normalized',...
'OuterPosition', [0, 0.05, 1,0.2],...
'Color', [0 0 0], 'Numbertitle',...
'off', 'Name', 'Control Window');
GammaText = uicontrol('Style','text',...
'Units', 'normalized',...
'Position',[0.61 0.93 0.1 0.065],...
'String','Gamma Adjustment');
minText = uicontrol('Style','text',...
'Units', 'normalized',...
'Position',[0.2 0.93 0.2 0.065],...
'String','Min Displayed Intensity');
maxText = uicontrol('Style','text',...
'Units', 'normalized',...
'Position',[0.405 0.93 0.2 0.065],...
'String','Max Displayed Intensity');
TranspText = uicontrol('Style','text',...
'Units', 'normalized',...
'Position',[0.715 0.93 0.07 0.065],...
'String','Opacity');
MaskText = uicontrol('Style','text',...
'Units', 'normalized',...
'Position',[0.788 0.93 0.211 0.065],...
'String','Brain Region Masks');
MaskSeparator = uicontrol('Style','text',...
'Units', 'normalized',...
'Position',[0.787 0.2 0.002 1],...
'BackgroundColor', [1 1 1]);
%
if SectDim == 0;
TotalSlices = Zs;
elseif SectDim == 1;
TotalSlices = height;
elseif SectDim == 2;
TotalSlices = width;
end
Sect = round(TotalSlices./1.5);
sliderObj = uicontrol('Style', 'slider',...
'Min',1,'Max',TotalSlices,'Value',Sect,...
'Units', 'normalized',...
'String', 'Z Slider',...
'SliderStep', [1,5]/(Zs-1),...
'BackgroundColor', [0.5, 0.5, 0.5],...
'Position', [0, 0, 1, 0.22]);
if ViewerMode ~= 1 || nChan ~=1
greyObj = uicontrol('Style', 'popup',...
'String', popupnamesLabels,...
'Units', 'normalized',...
'Value',greyVal,...
'Position', [0 0.82 0.15 0.1]);
elseif ViewerMode == 1 && nChan == 1;
greyObj = uicontrol('Style', 'popup',...
'String', TiffName,...
'Units', 'normalized',...
'Position', [0 0.62 0.15 0.1]);
end
greyText = uicontrol('Style','text',...
'Units', 'normalized',...
'Position',[0.15 0.85 0.046 0.07],...
'String','Grey');
greyGammaSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',2,'Value',1,...
'Units', 'normalized',...
'SliderStep', [0.05, 0.2],...
'BackgroundColor', [0.5, 0.5, 0.5],...
'Position',[0.61 0.82 0.1 0.1]);
greyMinSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',greyMin,...
'Units', 'normalized',...
'SliderStep', [250 5000]./65535,...
'BackgroundColor', [0.5, 0.5, 0.5],...
'Position',[0.2 0.82 0.2 0.1]);
greyMaxSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',greyMax,...
'Units', 'normalized',...
'SliderStep', [250 5000]./65535,...
'BackgroundColor', [0.5, 0.5, 0.5],...
'Position',[0.405 0.82 0.2 0.1]);
greyTransparencyObj = uicontrol('Style', 'slider',...
'Min', 0, 'Max', 1, 'Value', 1,...
'SliderStep', [0.1, 1],...
'Units', 'normalized',...
'BackgroundColor', [0.5, 0.5, 0.5],...
'Position',[0.715 0.82 0.07 0.1]);
greyMaskObj = uicontrol('Style', 'popup',...
'String', popupnamesMasks,...
'Units', 'normalized',...
'Value',greyValMask,...
'Position', [0.788 0.82 0.21 0.1]);
if ViewerMode ~= 1 || nChan == 1
rObj = uicontrol('Style', 'popup',...
'String', popupnamesLabels,...
'Units', 'normalized',...
'Value',rVal,...
'Position', [0 0.72 0.15 0.1]);
elseif ViewerMode == 1 && nChan == 3;
rObj = uicontrol('Style', 'popup',...
'String', strcat(TiffName, '-RedCh'),...
'Units', 'normalized',...
'Value',rVal,...
'Position', [0 0.72 0.15 0.1]);
end
rText = uicontrol('Style','text',...
'Units', 'normalized',...
'Position',[0.15 0.75 0.046 0.07],...
'BackgroundColor', [1 0 0],...
'String','Red');
rGammaSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',2,'Value',1,...
'Units', 'normalized',...
'SliderStep', [0.05, 0.2],...
'BackgroundColor', [1 0 0],...
'Position',[0.61 0.72 0.1 0.1]);
rMinSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',rMin,...
'Units', 'normalized',...
'SliderStep', [250 5000]./65535,...
'BackgroundColor', [1 0 0],...
'Position',[0.2 0.72 0.2 0.1]);
rMaxSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',rMax,...
'Units', 'normalized',...
'SliderStep', [250 5000]./65535,...
'BackgroundColor', [1 0 0],...
'Position',[0.405 0.72 0.2 0.1]);
rTransparencyObj = uicontrol('Style', 'slider',...
'Min', 0, 'Max', 1, 'Value', 1,...
'SliderStep', [0.1, 1],...
'Units', 'normalized',...
'BackgroundColor', [1 0 0],...
'Position',[0.715 0.72 0.07 0.1]);
rMaskObj = uicontrol('Style', 'popup',...
'String', popupnamesMasks,...
'Units', 'normalized',...
'Value',rValMask,...
'Position', [0.788 0.72 0.21 0.1]);
if ViewerMode ~= 1 || nChan == 1
gObj = uicontrol('Style', 'popup',...
'String', popupnamesLabels,...
'Units', 'normalized',...
'Value',gVal,...
'Position', [0 0.62 0.15 0.1]);
elseif ViewerMode == 1 && nChan == 3;
gObj = uicontrol('Style', 'popup',...
'String', strcat(TiffName, '-GrCh'),...
'Units', 'normalized',...
'Position', [0 0.62 0.15 0.1]);
end
gText = uicontrol('Style','text',...
'Units', 'normalized',...
'BackgroundColor', [0 1 0],...
'Position',[0.15 0.65 0.046 0.07],...
'String','Green');
gGammaSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',2,'Value',1,...
'Units', 'normalized',...
'SliderStep', [0.05, 0.2],...
'BackgroundColor', [0 1 0],...
'Position',[0.61 0.62 0.1 0.1]);
gMinSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',gMin,...
'Units', 'normalized',...
'BackgroundColor', [0 1 0],...
'SliderStep', [250 5000]./65535,...
'Position',[0.2 0.62 0.2 0.1]);
gMaxSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',gMax,...
'Units', 'normalized',...
'BackgroundColor', [0 1 0],...
'SliderStep', [250 5000]./65535,...
'Position',[0.405 0.62 0.2 0.1]);
gTransparencyObj = uicontrol('Style', 'slider',...
'Min', 0, 'Max', 1, 'Value', 1,...
'SliderStep', [0.1, 1],...
'Units', 'normalized',...
'BackgroundColor', [0 1 0],...
'Position',[0.715 0.62 0.07 0.1]);
gMaskObj = uicontrol('Style', 'popup',...
'String', popupnamesMasks,...
'Units', 'normalized',...
'Value',gValMask,...
'Position', [0.788 0.62 0.21 0.1]);
if ViewerMode ~= 1 || nChan == 1
bObj = uicontrol('Style', 'popup',...
'String', popupnamesLabels,...
'Units', 'normalized',...
'Value',bVal,...
'Position', [0 0.52 0.15 0.1]);
elseif ViewerMode == 1 && nChan == 3;
bObj = uicontrol('Style', 'popup',...
'String', strcat(TiffName, '-BlCh'),...
'Units', 'normalized',...
'Value',bVal,...
'Position', [0 0.52 0.15 0.1]);
end
bText = uicontrol('Style','text',...
'Units', 'normalized',...
'BackgroundColor', [0 0 1],...
'Position',[0.15 0.55 0.046 0.07],...
'String','Blue');
bGammaSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',2,'Value',1,...
'Units', 'normalized',...
'SliderStep', [0.05, 0.2],...
'BackgroundColor', [0 0 1],...
'Position',[0.61 0.52 0.1 0.1]);
bMinSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',bMin,...
'Units', 'normalized',...
'BackgroundColor', [0 0 1],...
'SliderStep', [250 5000]./65535,...
'Position',[0.2 0.52 0.2 0.1]);
bMaxSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',bMax,...
'Units', 'normalized',...
'BackgroundColor', [0 0 1],...
'SliderStep', [250 5000]./65535,...
'Position',[0.405 0.52 0.2 0.1]);
bTransparencyObj = uicontrol('Style', 'slider',...
'Min', 0, 'Max', 1, 'Value', 1,...
'SliderStep', [0.1, 1],...
'Units', 'normalized',...
'BackgroundColor', [0 0 1],...
'Position',[0.715 0.52 0.07 0.1]);
bMaskObj = uicontrol('Style', 'popup',...
'String', popupnamesMasks,...
'Units', 'normalized',...
'Value',bValMask,...
'Position', [0.788 0.52 0.21 0.1]);
cObj = uicontrol('Style', 'popup',...
'String', popupnamesLabels,...
'Units', 'normalized',...
'Value',cVal,...
'Position', [0 0.42 0.15 0.1]);
cText = uicontrol('Style','text',...
'Units', 'normalized',...
'BackgroundColor', [0 1 1],...
'Position',[0.15 0.45 0.046 0.07],...
'String','Cyan');
cGammaSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',2,'Value',1,...
'Units', 'normalized',...
'SliderStep', [0.05, 0.2],...
'BackgroundColor', [0 1 1],...
'Position',[0.61 0.42 0.1 0.1]);
cMinSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',cMin,...
'Units', 'normalized',...
'BackgroundColor', [0 1 1],...
'SliderStep', [250 5000]./65535,...
'Position',[0.2 0.42 0.2 0.1]);
cMaxSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',cMax,...
'Units', 'normalized',...
'BackgroundColor', [0 1 1],...
'SliderStep', [250 5000]./65535,...
'Position',[0.405 0.42 0.2 0.1]);
cTransparencyObj = uicontrol('Style', 'slider',...
'Min', 0, 'Max', 1, 'Value', 1,...
'SliderStep', [0.1, 1],...
'Units', 'normalized',...
'BackgroundColor', [0 1 1],...
'Position',[0.715 0.42 0.07 0.1]);
cMaskObj = uicontrol('Style', 'popup',...
'String', popupnamesMasks,...
'Units', 'normalized',...
'Value',cValMask,...
'Position', [0.788 0.42 0.21 0.1]);
mObj = uicontrol('Style', 'popup',...
'String', popupnamesLabels,...
'Units', 'normalized',...
'Position', [0 0.32 0.15 0.1]);
mText = uicontrol('Style','text',...
'Units', 'normalized',...
'BackgroundColor', [1 0 1],...
'Position',[0.15 0.35 0.046 0.07],...
'String','Magenta');
mGammaSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',2,'Value',1,...
'Units', 'normalized',...
'SliderStep', [0.05, 0.2],...
'BackgroundColor', [1 0 1],...
'Position',[0.61 0.32 0.1 0.1]);
mMinSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',mMin,...
'Units', 'normalized',...
'BackgroundColor', [1 0 1],...
'SliderStep', [250 5000]./65535,...
'Position',[0.2 0.32 0.2 0.1]);
mMaxSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',mMax,...
'Units', 'normalized',...
'BackgroundColor', [1 0 1],...
'SliderStep', [250 5000]./65535,...
'Position',[0.405 0.32 0.2 0.1]);
mTransparencyObj = uicontrol('Style', 'slider',...
'Min', 0, 'Max', 1, 'Value', 1,...
'SliderStep', [0.1, 1],...
'Units', 'normalized',...
'BackgroundColor', [1 0 1],...
'Position',[0.715 0.32 0.07 0.1]);
mMaskObj = uicontrol('Style', 'popup',...
'String', popupnamesMasks,...
'Units', 'normalized',...
'Value',mValMask,...
'Position', [0.788 0.32 0.21 0.1]);
yObj = uicontrol('Style', 'popup',...
'String', popupnamesLabels,...
'Units', 'normalized',...
'Value',yVal,...
'Position', [0 0.22 0.15 0.1]);
yText = uicontrol('Style','text',...
'Units', 'normalized',...
'BackgroundColor', [1 1 0],...
'Position',[0.15 0.25 0.046 0.07],...
'String','Yellow');
yGammaSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',2,'Value',1,...
'Units', 'normalized',...
'SliderStep', [0.05, 0.2],...
'BackgroundColor', [1 1 0],...
'Position',[0.61 0.22 0.1 0.1]);
yMinSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',yMin,...
'Units', 'normalized',...
'SliderStep', [250 5000]./65535,...
'BackgroundColor', [1 1 0],...
'Position',[0.2 0.22 0.2 0.1]);
yMaxSliderObj = uicontrol('Style', 'slider',...
'Min',0,'Max',65535,'Value',yMax,...
'Units', 'normalized',...
'BackgroundColor', [1 1 0],...
'SliderStep', [250 5000]./65535,...
'Position',[0.405 0.22 0.2 0.1]);
yTransparencyObj = uicontrol('Style', 'slider',...
'Min', 0, 'Max', 1, 'Value', 1,...
'SliderStep', [0.1, 1],...
'Units', 'normalized',...
'BackgroundColor', [1 1 0],...
'Position',[0.715 0.22 0.07 0.1]);
yMaskObj = uicontrol('Style', 'popup',...
'String', popupnamesMasks,...
'Units', 'normalized',...
'Value',yValMask,...
'Position', [0.788 0.22 0.21 0.1]);
%% Make the image display window
imFig = figure;
set(imFig, 'menubar', 'none',...
'units', 'normalized',...
'outerposition', [0 0.3 1 0.70],...
'Color', [0 0 0],...
'Numbertitle', 'off',...
'Name', 'Image Window',...
'doublebuffer','off',...
'resize', 'off',...
'KeyPressFcn', @IMFigCallback,...
'WindowButtonDownFcn', @imFigButtonDown,...
'WindowButtonUpFcn', @imFigButtonUp);
set(imFig, 'units', 'pixels');
iptsetpref('ImshowBorder', 'tight');
figSizeVec = get(imFig, 'position');
figWidth = floor(figSizeVec(3));
figHeight = floor(figSizeVec(4));
CurrentImage = imshow(zeros(figHeight, figWidth)); % for some reason this call shifts the figure, put it back up
set(imFig, 'units', 'normalized');
set(imFig, 'outerposition', [0 0.3 1 0.70])
%set(CurrentImage, 'erasemode', 'none');
set(imFig, 'units', 'pixels');
axis manual
%% Continuous loop that looks for updates to sliders and dropdown menus, and updates the dispaly image accordingly
DisplaySlice = 1;
while true
tic
if ChangeDim == 1; % If 'v' is pressed, change sectioning dimension
DisplaySlice = 1;
if SectDim == 2;
SectDim = 0;
else
SectDim = SectDim + 1;
end
if SectDim == 0;