-
Notifications
You must be signed in to change notification settings - Fork 1
/
ISI_selectContour.m
executable file
·246 lines (210 loc) · 7.94 KB
/
ISI_selectContour.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
function idx = ISI_selectContour(XdataLowest,YdataLowest,prmtsCurrent,dipIm, contour_level)
%label each of the contour lines and let user select by chosing from dialog
imRef = imread(fullfile(prmtsCurrent.path2dir,prmtsCurrent.refImage));
h2RoiSelect = figure('Name','Select Isolated barrel');
%Compute size difference between filtered "dip" image and reference
[deltaRC] = size(imRef) - size(dipIm);
deltaR = fix(deltaRC(1)/2);
deltaC = fix(deltaRC(2)/2);
imshow(imRef)
axis image
hold on
%% create region for each
nROI = numel(XdataLowest);
str = cell(nROI+1,1);
for iROI = 1 : nROI
x = XdataLowest{iROI}+deltaR;
y = YdataLowest{iROI}+deltaC;
plot(x,y,'b-','LineWidth',2)
text(mean(x(~isnan(x))),mean(y(~isnan(y))),num2str(iROI),'color','r','fontSize',12);
str{iROI} = num2str(iROI);
end
str{end} = 'None';
title(['Contour= ' num2str(contour_level)]);
%% list dialog
cpos=get(h2RoiSelect,'position'); %contour fig position
figpos=[cpos(1)+cpos(3) cpos(2)+cpos(4) 192 386];
[idx]=showlistbox('ListString',str,'PromptString','Select ROI',...
'position',figpos,'initialvalue',length(str));
if idx == nROI + 1; idx = -1;end %user selecte None -> set idx to -1
if isempty(idx)
error('ISI_isolateBarrel: cancelled contour selection');
end
%% clean up
close(h2RoiSelect)
%% showlistbox
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [selection, value]=showlistbox(varargin)
%SHOWLISTBOX list selection dialog box, based on listdlg
% [SELECTION,OK] = LISTDLG('ListString',S) creates a modal dialog box
% which allows you to select a string or multiple strings from a list.
% SELECTION is a vector of indices of the selected strings (length 1 in
% the single selection mode). This will be [] when OK is 0. OK is 1 if
% you push the OK button, or 0 if you push the Cancel button or close the
% figure.
% Double-clicking on an item or pressing <CR> when multiple items are
% selected has the same effect as clicking the OK button. Pressing <CR>
% is the same as clicking the OK button. Pressing <ESC> is the same as
% clicking the Cancel button.
%
% Inputs are in parameter,value pairs:
%
% Parameter Description
% 'ListString' cell array of strings for the list box.
% 'ListSize' [width height] of listbox in pixels; defaults
% to [160 300].
% 'InitialValue' vector of indices of which items of the list box
% are initially selected; defaults to the first item.
% 'Name' String for the figure's title; defaults to ''.
% 'PromptString' string matrix or cell array of strings which appears
% as text above the list box; defaults to {}.
% 'OKString' string for the OK button; defaults to 'OK'.
% 'CancelString' string for the Cancel button; defaults to 'Cancel'.
% 'Position' [left bottom width height], bases the actual
% width & height on ListSize, default vals are w=192,h=386
%
%mjp 2011.09.30 a lot of the code is borrowed directly from listdlg
figname = '';
listsize = [160 300];
promptstring = {};
liststring = [];
initialvalue = [];
okstring = 'OK';
cancelstring = 'Cancel';
fus = 8; %frame/uicontrol height
ffs = 8; %frame/figure spacing
uh = 22; %uicontrol button height
ex = get(0,'defaultuicontrolfontsize')*1.7; % height extent per line of uicontrol text (approx)
fp = get(0,'defaultfigureposition');
w = 2*(fus+ffs)+listsize(1);
h = 2*ffs+6*fus+ex*length(promptstring)+listsize(2)+uh;
fp = [fp(1) fp(2)+fp(4)-h w h]; % keep upper left corner fixed
if mod(length(varargin),2) ~= 0
% input args have not com in pairs, woe is me
error('MATLAB:listdlg:InvalidArgument', 'Arguments to LISTDLG must come param/value in pairs.')
end
for i=1:2:length(varargin)
switch lower(varargin{i})
case 'name'
figname = varargin{i+1};
case 'promptstring'
promptstring = varargin{i+1};
case 'listsize'
listsize = varargin{i+1};
case 'liststring'
liststring = varargin{i+1};
case 'initialvalue'
initialvalue = varargin{i+1};
case 'position'
newfp = varargin{i+1}; %taking initial left and bottom
%default w=192, h=386
fp = [newfp(1) newfp(2)+fp(4)-h w h]; % keep upper left corner fixed
end
end
%set defaults
if isempty(liststring)
error('showlistbox:NeedParameter', 'ListString parameter is required.')
end
if isempty(initialvalue)
initialvalue = 1;
end
if ischar(promptstring)
promptstring = cellstr(promptstring);
end
fig_props = { ...
'name' figname ...
'color' get(0,'defaultUicontrolBackgroundColor') ...
'resize' 'off' ...
'numbertitle' 'off' ...
'menubar' 'none' ...
'windowstyle' 'modal' ...
'visible' 'off' ...
'createfcn' '' ...
'position' fp ...
'closerequestfcn' 'delete(gcbf)' ...
};
liststring=cellstr(liststring);
fig = figure(fig_props{:});
if ~isempty(promptstring)
prompt_text = uicontrol('style','text','string',promptstring,...
'horizontalalignment','left',...
'position',[ffs+fus fp(4)-(ffs+fus+ex*length(promptstring))+fus ...
listsize(1) ex*length(promptstring)]); %#ok
end
btn_wid = (fp(3)-2*(ffs+fus)-fus)/2;
listbox = uicontrol('style','listbox',...
'position',[ffs+fus ffs+uh+4*fus listsize],...
'string',liststring,...
'backgroundcolor','w',...
'max',2,... %allows multiple selection
'tag','listbox',...
'value',initialvalue, ...
'callback', {@doListboxClick});
ok_btn = uicontrol('style','pushbutton',...
'string',okstring,...
'position',[ffs+fus ffs+fus btn_wid uh],...
'callback',{@doOK,listbox});
cancel_btn = uicontrol('style','pushbutton',...
'string',cancelstring,...
'position',[ffs+2*fus+btn_wid ffs+fus btn_wid uh],...
'callback',{@doCancel,listbox});
set([fig, ok_btn, cancel_btn, listbox], 'keypressfcn', {@doKeypress, listbox});
% make sure we are on screen
movegui(fig)
set(fig, 'visible','on'); drawnow;
try
% Give default focus to the listbox *after* the figure is made visible
uicontrol(listbox);
uiwait(fig);
catch e
if ishandle(fig)
delete(fig)
end
rethrow(e)
end
if isappdata(0,'ListDialogAppData__')
ad = getappdata(0,'ListDialogAppData__');
selection = ad.selection;
value = ad.value;
rmappdata(0,'ListDialogAppData__')
else
% figure was deleted
selection = [];
value = 0;
end
%% figure, OK and Cancel KeyPressFcn
function doKeypress(src, evd, listbox) %#ok
switch evd.Key
case 'escape'
doCancel([],[],listbox);
end
%% OK callback
function doOK(ok_btn, evd, listbox) %#ok
if (~isappdata(0, 'ListDialogAppData__'))
ad.value = 1;
ad.selection = get(listbox,'value');
setappdata(0,'ListDialogAppData__',ad);
delete(gcbf);
end
%% Cancel callback
function doCancel(cancel_btn, evd, listbox) %#ok
ad.value = 0;
ad.selection = [];
setappdata(0,'ListDialogAppData__',ad)
delete(gcbf);
%% SelectAll callback
function doSelectAll(selectall_btn, evd, listbox) %#ok
set(selectall_btn,'enable','off')
set(listbox,'value',1:length(get(listbox,'string')));
%% Listbox callback
function doListboxClick(listbox, evd, selectall_btn) %#ok
% if this is a doubleclick, doOK
if strcmp(get(gcbf,'SelectionType'),'open')
doOK([],[],listbox);
elseif nargin == 3
if length(get(listbox,'string'))==length(get(listbox,'value'))
set(selectall_btn,'enable','off')
else
set(selectall_btn,'enable','on')
end
end