-
Notifications
You must be signed in to change notification settings - Fork 1
/
Segment.m
454 lines (361 loc) · 13.6 KB
/
Segment.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
function varargout = Segment(varargin)
% function varargout = Segment(varargin)
% Diinamic package
% GUI to create ROIs and segmented images (masks)
%
% Marianne Renner may 2022
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Last Modified by GUIDE v2.5 09-Nov-2022 10:23:06
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Segment_OpeningFcn, ...
'gui_OutputFcn', @Segment_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes just before Segment is made visible.
function Segment_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
set(handles.displaypushbutton,'Enable','off');
set(handles.nextpushbutton,'Enable','off');
set(handles.createroipushbutton,'Enable','off');
set(handles.createmaskpushbutton,'Enable','off');
% to fit screen definition/changes in size
h3 = findobj('Type','figure');
txtHand = findall(h3, '-property', 'FontUnits');
%set(txtHand, 'FontUnits', 'normalized');
set(txtHand, 'FontUnits', 'centimeters');
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = Segment_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function loadpushbutton_Callback(hObject, eventdata, handles)
% load data simplified version
px_mu = str2num(get(handles.szpx,'String'));
mu=get(handles.muradiobutton,'Value');
dialog_title=['Select data folder'];
directory_name = uigetdir(cd,dialog_title);
if directory_name==0
return
end
cd(directory_name);
d = dir('*.mat'); % movie
st={d.name};
cuenta=1;
if isempty(st)==1
msgbox('No files!!','Select files','error');
return
else
for jj=1:size(st,2)
k1 = strfind(st{jj},'roidata');
k2 = strfind(st{jj},'Irend');
k3 = strfind(st{jj},'auxdens');
k4 = strfind(st{jj},'mask');
if isempty(k1)==1 && isempty(k2)==1 && isempty(k3)==1 && isempty(k4)==1
stok{cuenta}=st{jj};
cuenta=cuenta+1;
end
end
end
[files,v] = listdlg('PromptString','Select files:','SelectionMode','multiple','ListString',stok);
if v==0
return
end
for i=1:size(files,2)
listafiles{i}=stok{files(i)};
end
filename=listafiles{1}; %first file
set (handles.filename, 'Userdata',filename);
if size(files,2)>1 %batch
set (handles.filename, 'string',['Batch: File ',filename,' (1/',num2str(size(files,2)),')']) ;
set(handles.nextpushbutton,'Enable','on');
else
set (handles.filename, 'string',filename) ;
end
set(handles.displaypushbutton,'Enable','on');
set(handles.createroipushbutton,'Enable','on');
set(handles.createmaskpushbutton,'Enable','on');
[namefile,~]=strtok(filename,'.'); %!!!!!!!!!!!!!!!!!!!!!!!!!!!!
handles.ffname = fullfile(directory_name,filename);
set(handles.savename,'String',namefile);
set(handles.textlistafiles,'userdata',listafiles);
set(handles.nextpushbutton,'userdata',directory_name);
set(handles.textnrofiles,'userdata',1);
if mu==0
handles=loadselectPALMdata(filename,px_mu,handles);
else
handles=loadselectPALMdata(filename,1,handles); %data already in microns
end
set(handles.alpha1,'string','0')
set(handles.alpha2,'string','100')
% pointillistic
showimagesauto = get(handles.autoimradiobutton,'value');
if showimagesauto==1
pointillistic(handles)
end
% Update handles structure
guidata(hObject, handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function createroipushbutton_Callback(hObject, eventdata, handles)
listafiles=get(handles.textlistafiles,'userdata');
if isempty(listafiles)==0
varargin{1}=handles;
disp('')
disp('Draw ROIs')
disp('Reading previous data, please wait...')
% window to create ROIs
varargout=CreateROI(varargin); %
else
disp('Choose the files first')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function createmaskpushbutton_Callback(hObject, eventdata, handles)
docreateMask(handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function displaypushbutton_Callback(hObject, eventdata, handles)
pointillistic(handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function previouspushbutton_Callback(hObject, eventdata, handles)
px_mu= str2num(get(handles.szpx,'String'));
mu=get(handles.muradiobutton,'Value');
listafiles=get(handles.textlistafiles,'userdata');
nrofile=get(handles.textnrofiles,'userdata');
directory_name=get(handles.nextpushbutton,'userdata');
next=nrofile-1;
% go for previous file
if next>0
set(handles.textnrofiles,'userdata',next);
filename=listafiles{next}
handles.ffname = fullfile(directory_name,filename);
[namefile,~]=strtok(filename,'.'); %sin extension
set(handles.savename,'String',namefile);
set(handles.filename,'string',[filename,' (',num2str(next),' of ',num2str(size(listafiles,2)),')']);
set(handles.textlistafiles,'userdata',listafiles);
set(handles.textnrofiles,'userdata',next);
set(handles.filename,'userdata',filename);
if mu==0
handles=loadselectPALMdata(filename,px_mu,handles);
else
handles=loadselectPALMdata(filename,1,handles); %data already in microns
end
% pointillistic
showimagesauto = get(handles.autoimradiobutton,'value');
if showimagesauto==1
pointillistic(handles)
end
set(handles.nextpushbutton,'Enable','on')
if next==1
set(handles.previouspushbutton,'Enable','off')
end
else
set(handles.previouspushbutton,'Enable','off')
end %there is previous
clear file listafiles
% Update handles structure
guidata(gcbo, handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function nextpushbutton_Callback(hObject, eventdata, handles)
px_mu= str2num(get(handles.szpx,'String'));
mu=get(handles.muradiobutton,'Value');
listafiles=get(handles.textlistafiles,'userdata');
nrofile=get(handles.textnrofiles,'userdata');
directory_name=get(handles.nextpushbutton,'userdata');
next=nrofile+1;
% go for next file
if size(listafiles,2)<next
set(handles.nextpushbutton,'Enable','off')
else
set(handles.textnrofiles,'userdata',next);
filename=listafiles{next}
handles.ffname = fullfile(directory_name,filename);
[namefile,~]=strtok(filename,'.'); %sin extension
set(handles.savename,'String',namefile);
set(handles.filename,'string',[filename,' (',num2str(next),' of ',num2str(size(listafiles,2)),')']);
set(handles.textlistafiles,'userdata',listafiles);
set(handles.textnrofiles,'userdata',next);
set(handles.filename,'userdata',filename);
if mu==0
handles=loadselectPALMdata(filename,px_mu,handles);
else
handles=loadselectPALMdata(filename,1,handles); %data already in microns
end
% pointillistic
showimagesauto = get(handles.autoimradiobutton,'value');
if showimagesauto==1
pointillistic(handles)
end
set(handles.previouspushbutton,'Enable','on')
if next==size(listafiles,2)
set(handles.nextpushbutton,'Enable','off')
end
end %there is next
clear file listafiles
% Update handles structure
guidata(gcbo, handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function helptag_Callback(hObject, eventdata, handles)
%-------------------------------------------------------------------------
function openhelp_Callback(hObject, eventdata, handles)
helpsegment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function extras_Callback(hObject, eventdata, handles)
%-------------------------------------------------------------------------
function batchfull_Callback(hObject, eventdata, handles)
disp('Creating ROIs of the full image')
fullimageroi(handles)
disp('Done')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function pointillistic(handles)
% plots pointillistic images
X_mu=handles.x;
Y_mu=handles.y;
alpha=handles.alpha;
alpha(1:10);
fr=handles.fr;
gausssmooth = 1;
dx = str2num(get(handles.PALMszpx,'String'));
sigmaloc=dx*2;
vect2remove=selectremovealpha2(handles,X_mu,Y_mu,alpha); %selection by absolute intensities
if ~isempty(vect2remove)
[X_mu,Y_mu,alpha,fr]=removealpha(vect2remove,X_mu,Y_mu,alpha,fr);
end
% clean data
xmax = max(X_mu);
ymax = max(Y_mu);
% figure
fig_points = figure('Name','Pointillist image','Toolbar','figure');
axis equal;
pointsize = 2;
set(gca,'YDir','reverse')
xlim([0 xmax]); ylim([0 ymax]);
color = 'k';
hold on;
title([' Selected positions =',num2str(length(X_mu))]);
handles.pointsplotted = plot(X_mu,Y_mu,'.','MarkerSize',pointsize,'Color',color);
hold on
figure(fig_points);
handles.fig_points = fig_points;
%rendered
xdim=ceil(max(X_mu)/dx);
ydim=ceil(max(Y_mu)/dx);
%% Create rendered image
[I,xxi,yyi] = PALM_rendering3( X_mu,Y_mu,alpha,dx*2,dx,0,xdim, ydim, gausssmooth);
figselected = figure('Name','Rendered image','Toolbar','figure');
hold on;
% rendered in false colors, pixel 0,0 top left
imshow(I,'InitialMagnification','fit')
colormap(gca,'hot')
hold on
rendx=X_mu/dx;
rendy=Y_mu/dx;
handles.rendx=rendx;
handles.rendy=rendy;
set(handles.displaypushbutton,'userdata',I); %also to recover size of rendered
clear x y X_mu Y_mu alpha fr I
% Update handles structure
guidata(gcbo, handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function M = flagmatrixelements(M,vectorindices)
siz = size(M);
aux = M(:);
aux(vectorindices) = 1;
M = reshape(aux,siz);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function figurapoints=plotpoints(x,y,fr,handles)
figurapoints = figure('Name','Pointillist image','Toolbar','figure');
% set boundaries
if isfield(handles,'xlim')
[xmin,xmax] = deal(handles.xlim(1),handles.xlim(2));
[ymin,ymax] = deal(handles.ylim(1),handles.ylim(2));
else
xmin = min(x); xmax = max(x);
ymin = min(y); ymax = max(y);
end
axis equal;
pointsize = str2num(get(handles.dotsize,'String'));
xlim([xmin xmax]); ylim([ymin ymax]);
color = 'k';
hold on;
xlabel('X (mu)');
ylabel('Y (mu)');
handles.pointsplotted = plot(x,y,'.','MarkerSize',pointsize,'Color',color);
title([' Total nb of positions =',num2str(length(x))]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function I = image_ch(varargin)
xx1 = varargin{1};
yy1 = varargin{2};
I = varargin{3};
pct_sat = 0;
if ndims(I)==2
if nargin>3
clims = varargin{4};
else
Imax = prctile(I(:),100-pct_sat);
Imin = min(I(:));
clims = [Imin Imax];
end
if any(isnan(clims)) || clims(2)<=clims(1)
warning(['clims (=',num2str(clims),')! Using [0,1] instead !']);
clims = [0 1];
end
I = imagesc(xx1,yy1,I,clims);
else
image(xx1,yy1,I);
end
colorbar;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function szpx_Callback(hObject, eventdata, handles)
function szpx_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function savename_Callback(hObject, eventdata, handles)
function savename_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function alpha1_Callback(hObject, eventdata, handles)
function alpha1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function alpha2_Callback(hObject, eventdata, handles)
function alpha2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function PALMszpx_Callback(hObject, eventdata, handles)
function PALMszpx_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function minsizeclumask_Callback(hObject, eventdata, handles)
function minsizeclumask_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function intensthresh_Callback(hObject, eventdata, handles)
function intensthresh_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function muradiobutton_Callback(hObject, eventdata, handles)
function lengthradiobutton_Callback(hObject, eventdata, handles)
function autoimradiobutton_Callback(hObject, eventdata, handles)
function savematradiobutton_Callback(hObject, eventdata, handles)
function smallradiobutton_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%