-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotStack.m
More file actions
253 lines (211 loc) · 7.07 KB
/
plotStack.m
File metadata and controls
253 lines (211 loc) · 7.07 KB
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
function plotStack(data,figID)
% this function create a basic gui that allows to scroll through the stack
% in the specified dimension
dim = 2;
[s1,s2,s3] = size(data);
dat_min = min(data(:)); dat_max = max(data(:));
if nargin == 1
f = figure('visible','off','position',[360 500 400 285],'WindowScrollWheelFcn',@figScroll);
else
try close(figID);end
f = figure(figID);
set(f,'visible','off','position',[360 500 400 285],'WindowScrollWheelFcn',@figScroll);
end
set(f,'name',inputname(1))
hslide = uicontrol('style','slider','String','z',...
'position',[330 30 30 200],...
'Callback',{@slider_Callback});
set(hslide,'Min',1);set(hslide,'Max',s3);
set(hslide,'value',round((s3)/2));set(hslide,'SliderStep',[1/(s3) 1/(s3)]);
addlistener(hslide,'Value','PreSet',@slider_Callback);
htxt = uicontrol('style','edit','string','0',...
'position',[330 235 30 15],'Callback',@edit_Callback);
hcmax = uicontrol('style','edit','string',num2str(dat_max),...
'position',[335 250 50 8],'Callback',@hcmax_Callback,'enable','off');
hcmin = uicontrol('style','edit','string',num2str(dat_min),...
'position',[335 260 50 8],'Callback',@hcmax_Callback,'enable','off');
hcmapbox = uicontrol('style','checkbox','value',1,'string','Colomap auto',...
'Callback',@cmap_Callback,'position',[335 268 50 15]);
hpopcmap = uicontrol('style','popupmenu','string',{'parula','jet','hot','winter',...
'gray','copper','morgenstemning','isolum'},'units','normalized','position',[.1 .85 0.1 0.1],...
'value',1,'Callback',@popcmap_Callback);
hcbox = uicontrol('style','checkbox','value',0,'string','Scale colormap to 3D data',...
'Callback',@cbocx_Callback,'position',[200 260 80 20]);
hpop = uicontrol('style','popupmenu','string',{'X','Y','Z'},'value',2,...
'Callback',@pop_Callback,'position',[280 245 30 30]);
ha = axes('Units','pixels','Position',[50,60,260,185]);
% by default, plot the midle of the data
switch dim
case 1
him = imagesc(reshape(data(round(end/2),:,:),[s2 s3]));
case 2
him = imagesc(reshape(data(:,round(end/2),:),[s1 s3])');
title('Sliding along the "Y" direction')
case 3
him = imagesc(data(:,:,round(end/2)));
colorbar
title('Sliding along the "Z" direction');
otherwise
dim = 3;
disp('Display direction set to "z"')
him = imagesc(data(:,:,round(end/2)));
title('Sliding along the "Z" direction')
end
colormap('default')
colorbar
caxis('auto')
% define figure handles
handles.data = data;
handles.dim = dim;
handles.s = [s1 s2 s3];
handles.txt = htxt;
handles.slide = hslide;
handles.cbox = hcbox;
handles.cmapbox = hcmapbox;
handles.im = him;
handles.ax = ha;
handles.dmin = dat_min; handles.dmax = dat_max;
handles.hcmin = hcmin; handles.hcmax = hcmax;
handles.pop = hpop;
handles.popcmap = hpopcmap;
handles.f = f;
guidata(handles.f,handles)
% activation of the gui
set(f,'toolbar','figure');
set(f,'Units','normalized');
set(ha,'Units','normalized');
set(hslide,'Units','normalized');
set(hpop,'Units','normalized');
set(hcbox,'Units','normalized');
set(htxt,'Units','normalized');
set(hcmapbox,'Units','normalized');
set(hcmax,'Units','normalized');
set(hcmin,'Units','normalized');
set(f,'position',[0.0891 0.3417 0.3885 0.5037]);
set(f,'Visible','on');
end
function cbocx_Callback(source,~)
% edit_Callback(source)
slider_Callback(source);
end
function cmap_Callback(source,~)
h = guidata(gcf);
val = get(h.cmapbox,'value');
if val
set(h.hcmax,'enable','off')
set(h.hcmin,'enable','off')
else
set(h.hcmax,'enable','on')
set(h.hcmin,'enable','on')
end
slider_Callback(source);
end
function hcmax_Callback(source,~)
h = guidata(gcf);
cmax = str2double(get(h.hcmax,'string'));
cmin = str2double(get(h.hcmin,'string'));
cmax = clamp(cmax,h.dmin,h.dmax); cmin = clamp(cmin,h.dmin,h.dmax);
if cmax <= cmin; cmax = h.dmax;cmin = h.dmin; end
set(h.hcmax,'string',num2str(cmax))
set(h.hcmin,'string',num2str(cmin))
slider_Callback(source);
end
function slider_Callback(source,~)
h = guidata(gcf);
h.dim = get(h.pop,'value');
% update slide properties
set(h.slide,'max',h.s(h.dim));
slid_val = get(h.slide,'value');
if slid_val > h.s(h.dim)
set(h.slide,'value',h.s(h.dim))
end
val = get(h.slide,'value');
vmax = get(h.slide,'max');vmin = get(h.slide,'min');
val = round(val);
set(h.slide,'value',round(val));
% set(h.txt,'string',num2str(2*(round(val)-1)/(h.s(h.dim)-1)-1));
set(h.txt,'string',num2str(round(val)))
val = round((vmin + vmax)-val);
switch get(h.pop,'value')
case 1
temp = reshape(h.data(val,:,:),[h.s(2) h.s(3)])';
set(h.im,'Cdata',temp)
set(h.ax,'xlim',[0.5 h.s(2)+0.5],'ylim',[0.5 h.s(3)+0.5])
title('Sliding along the "X" direction')
xlabel('"Y" direction sdf');ylabel('"Z" direction')
case 2
temp = reshape(h.data(:,val,:),[h.s(1) h.s(3)])';
set(h.im,'Cdata',temp)
set(h.ax,'xlim',[0.5 h.s(1)+0.5],'ylim',[0.5 h.s(3)+0.5])
title('Sliding along the "Y" direction')
xlabel('"X" direction');ylabel('"Z" direction')
case 3
temp = h.data(:,:,val) ;
set(h.im,'Cdata',temp)
set(h.ax,'xlim',[0.5 h.s(2)+0.5],'ylim',[0.5 h.s(1)+0.5])
title('Sliding along the "Z" direction')
xlabel('"Y" direction');ylabel('"X" direction')
end
try
cmapS = get(h.popcmap,'string');
colormap(cmapS{get(h.popcmap,'value')})
end
if get(h.cbox,'value')
if (h.dmin-h.dmax)
caxis([h.dmin h.dmax])
else
caxis([h.dmin h.dmax+1])
end
else
if get(h.cmapbox,'value')
caxis('auto')
else
cmax = str2double(get(h.hcmax,'string'));
cmin = str2double(get(h.hcmin,'string'));
caxis([cmin cmax])
end
end
% save global changes
guidata(h.f,h);
end
function pop_Callback(source,event)
h = guidata(gcf);
set(h.txt,'string','0');
h.dim = get(h.pop,'value');
guidata(gcf,h);
edit_Callback(source,event);
% slider_Callback(source,event);
end
function popcmap_Callback(source,event)
edit_Callback(source,event);
% slider_Callback(source,event);
end
function edit_Callback(source,event)
h = guidata(gcf);
val = str2num(get(h.txt,'string'));
if val < 1
% val = floor(((val+1)/2)*(h.s(h.dim)-1)+1)
val = floor(linmap(val,-1,1,1,h.s(h.dim)));
end
if val > h.s(h.dim)
val = h.s(h.dim);
elseif val < 1
val = 1;
end
set(h.slide,'value',val);
slider_Callback(source,event);
end
function figScroll(source,event)
dir = event.VerticalScrollCount;
h = guidata(gcf);
val = get(h.slide,'value');
% val = round(val - dir.*0.05.*h.s(h.dim));
val = val -dir;
if val > h.s(h.dim)
val = h.s(h.dim);
elseif val < 1
val = 1;
end
set(h.slide,'value',val);
slider_Callback(source,event);
end