-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathroiMatchPub.m
610 lines (544 loc) · 23.9 KB
/
roiMatchPub.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
function varargout = roiMatchPub(varargin)
% ROIMATCHPUB MATLAB code for roiMatchPub.fig
% ROIMATCHPUB, by itself, creates a new ROIMATCHPUB or raises the existing
% singleton*.
%
% H = ROIMATCHPUB returns the handle to a new ROIMATCHPUB or the handle to
% the existing singleton*.
%
% ROIMATCHPUB('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ROIMATCHPUB.M with the given input arguments.
%
% ROIMATCHPUB('Property','Value',...) creates a new ROIMATCHPUB or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before roiMatchPub_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to roiMatchPub_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help roiMatchPub
% Last Modified by GUIDE v2.5 11-Apr-2019 17:33:41
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @roiMatchPub_OpeningFcn, ...
'gui_OutputFcn', @roiMatchPub_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 roiMatchPub is made visible.
function roiMatchPub_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to roiMatchPub (see VARARGIN)
% Choose default command line output for roiMatchPub
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes roiMatchPub wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global roiMatchGlobal;
% clear any current data
roiMatchGlobal.data = [];
roiMatchGlobal.data.rois = {};
roiMatchGlobal.data.mapping = [];
roiMatchGlobal.data.comparisonMatrix = [];
roiMatchGlobal.data.allRois = [];
updateGUI(handles)
function updateGUI(handles)
global roiMatchGlobal;
global dataGUIGlobal;
% update lists
set(handles.listROIs,'String',roiMatchGlobal.data.allRois)
set(handles.listROIs2,'String',roiMatchGlobal.data.allRois)
% --- Outputs from this function are returned to the command line.
function varargout = roiMatchPub_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in btnNew.
function btnNew_Callback(hObject, eventdata, handles)
% hObject handle to btnNew (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global roiMatchGlobal;
% clear any current data
roiMatchGlobal.data = [];
roiMatchGlobal.data.rois = {};
roiMatchGlobal.data.mapping = [];
roiMatchGlobal.data.comparisonMatrix = [];
roiMatchGlobal.data.allRois = [];
updateGUI(handles)
% --- Executes on button press in btnAddFromDataBrowse.
function btnAddFromDataBrowse_Callback(hObject, eventdata, handles)
global roiMatchGlobal;
[FileName,PathName] = uigetfile('*Fall*');
Fall = load(fullfile(PathName,FileName));
cd(PathName);
% load numpy file containing cell classification
cellValid = Fall.iscell(:,1);
% make masks of cells (for longitidinal tracking etc)
cellIDMap = zeros(size(Fall.ops.meanImg));
validCellList = find(cellValid(:,1)==1);
for iCell = 1:length(validCellList)
cellID = validCellList(iCell);
% roiPix = sub2ind(size(cellMask),Fall.stat{cellID}.ypix+int64(Fall.ops.yrange(1))-1,Fall.stat{cellID}.xpix+int64(Fall.ops.xrange(1))-1);
roiPix = sub2ind(size(cellIDMap),Fall.stat{cellID}.ypix+1,Fall.stat{cellID}.xpix+1);
cellIDMap(roiPix) = iCell;
end
figure;
meanFrame = Fall.ops.meanImg;
B = bwboundaries(cellIDMap);
imagesc(imadjust(int16(meanFrame)));
colormap gray;
hold on
visboundaries(B)
newRoiID = length(roiMatchGlobal.data.rois)+1;
roiMatchGlobal.data.allRois{newRoiID} = fullfile(PathName,FileName);
roiMatchGlobal.data.rois{newRoiID}.cellCount = sum(cellValid);
roiMatchGlobal.data.rois{newRoiID}.meanFrame = Fall.ops.meanImg;
% every experiment needs an associated matrix which defines if it has been
% compared to another experiment already
if ~isempty(roiMatchGlobal.data.comparisonMatrix)
% add a row and a column and set intersect comparison to 1
% row
roiMatchGlobal.data.comparisonMatrix(end+1,:) = 0; % [roiMatchGlobal.data.comparisonMatrix;zeros(1,size(roiMatchGlobal.data.comparisonMatrix,2)+1
% column
roiMatchGlobal.data.comparisonMatrix(:,end+1) = 0; % [roiMatchGlobal.data.comparisonMatrix;zeros(1,size(roiMatchGlobal.data.comparisonMatrix,2)+1
roiMatchGlobal.data.comparisonMatrix(end,end) = 1;
else
roiMatchGlobal.data.comparisonMatrix = 1;
end
% if it's the first experiment then use it as the comparison point
if newRoiID == 1
roiMatchGlobal.data.refImage = roiMatchGlobal.data.rois{newRoiID}.meanFrame;
roiMatchGlobal.data.rois{newRoiID}.meanFrameRegistered = roiMatchGlobal.data.rois{newRoiID}.meanFrame;
roiMatchGlobal.data.rois{newRoiID}.roiMapRegistered = cellIDMap;
else
% register mean frame + roi map to reference
moving = imadjusta(roiMatchGlobal.data.rois{newRoiID}.meanFrame);
fixed = imadjusta(roiMatchGlobal.data.refImage);
while(true)
[moving_out,fixed_out] = cpselect(moving,fixed,'Wait',true);
if size(moving_out,1)>6
break
else
msgbox('Choose at least 6 control points');
end
end
roiMatchGlobal.data.rois{newRoiID}.trans.moving_out = moving_out;
roiMatchGlobal.data.rois{newRoiID}.trans.fixed_out = fixed_out;
t_concord = fitgeotrans(moving_out,fixed_out,'projective');
ref = imref2d(size(fixed));
roiMatchGlobal.data.rois{newRoiID}.meanFrameRegistered = imwarp(moving,t_concord,'OutputView',ref);
roiMatchGlobal.data.rois{newRoiID}.roiMapRegistered = imwarp(cellIDMap,t_concord,'OutputView',ref,'Interp','nearest','SmoothEdges',false);
figure;
subplot(1,2,1);
imagesc(imfuse(roiMatchGlobal.data.rois{newRoiID}.meanFrameRegistered,roiMatchGlobal.data.rois{1}.meanFrameRegistered));
axis square;xticks([]);yticks([]);
subplot(1,2,2);
imagesc(imfuse(roiMatchGlobal.data.rois{newRoiID}.roiMapRegistered>0,roiMatchGlobal.data.rois{1}.roiMapRegistered>0));
axis square;xticks([]);yticks([]);
end
updateGUI(handles)
% --- Executes on selection change in listROIs.
function listROIs_Callback(hObject, eventdata, handles)
% hObject handle to listROIs (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listROIs contents as cell array
% contents{get(hObject,'Value')} returns selected item from listROIs
% --- Executes during object creation, after setting all properties.
function listROIs_CreateFcn(hObject, eventdata, handles)
% hObject handle to listROIs (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in listROIs2.
function listROIs2_Callback(hObject, eventdata, handles)
% hObject handle to listROIs2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listROIs2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listROIs2
% --- Executes during object creation, after setting all properties.
function listROIs2_CreateFcn(hObject, eventdata, handles)
% hObject handle to listROIs2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in btnRemove.
function btnRemove_Callback(hObject, eventdata, handles)
global roiMatchGlobal;
% load currently selected roi
currentAnimalID = handles.listROIs.Value;
expToKeep = setdiff(1:length(roiMatchGlobal.data.allRois),currentAnimalID);
roiMatchGlobal.data.rois = roiMatchGlobal.data.rois(expToKeep);
roiMatchGlobal.data.allRois = roiMatchGlobal.data.allRois(expToKeep);
roiMatchGlobal.data.comparisonMatrix = roiMatchGlobal.data.comparisonMatrix(expToKeep,expToKeep);
% update lists
updateGUI(handles);
handles.listROIs.Value = 1;
handles.listROIs2.Value = 1;
% --- Executes on button press in btnSave.
function btnSave_Callback(hObject, eventdata, handles)
global roiMatchGlobal;
[FileName,PathName] = uiputfile('*.mat');
cd(PathName);
roiMatchData = roiMatchGlobal.data;
save(fullfile(PathName,FileName),'roiMatchData');
% --- Executes on button press in btnLoad.
function btnLoad_Callback(hObject, eventdata, handles)
global roiMatchGlobal;
[FileName,PathName] = uigetfile('*.mat');
cd(PathName);
load(fullfile(PathName,FileName));
roiMatchGlobal.data = roiMatchData;
updateGUI(handles);
handles.listROIs.Value = 1;
handles.listROIs2.Value = 1;
% --- Executes on button press in btnCompare.
function btnCompare_Callback(hObject, eventdata, handles)
global roiMatchGlobal;
exp1 = handles.listROIs.Value;
exp2 = handles.listROIs2.Value;
figure;
subplot(2,2,1);
imagesc(imadjusta(roiMatchGlobal.data.rois{exp1}.meanFrameRegistered));
axis equal;xticks([]);yticks([]);
colormap gray
title('Experiment 1')
subplot(2,2,2);
imagesc(imadjusta(roiMatchGlobal.data.rois{exp2}.meanFrameRegistered));
axis equal;xticks([]);yticks([]);
title('Experiment 2')
subplot(2,2,3);
imagesc(imfuse(imadjusta(roiMatchGlobal.data.rois{exp1}.meanFrameRegistered),imadjusta(roiMatchGlobal.data.rois{exp2}.meanFrameRegistered)));
axis equal;xticks([]);yticks([]);
title('Fused images')
subplot(2,2,4);
imagesc(imfuse(roiMatchGlobal.data.rois{exp1}.roiMapRegistered>0,roiMatchGlobal.data.rois{exp2}.roiMapRegistered>0));
axis equal;xticks([]);yticks([]);
title('White = overlapping rois')
% --- Executes on button press in btnAuto.
function btnAuto_Callback(hObject, eventdata, handles)
global roiMatchGlobal;
allPerms = nchoosek(1:length(roiMatchGlobal.data.rois),2);
allOverlaps = [];
overlapThreshold = str2num(handles.editOverlapThreshold.String);
roiMatchGlobal.data.mapping = zeros(1,length(roiMatchGlobal.data.rois));
% set all rois from all experiments as unanalysed
allCellCount = 0;
figure
tic
for iExp1 = 1:length(roiMatchGlobal.data.rois)
exp1CellIDMap = roiMatchGlobal.data.rois{iExp1}.roiMapRegistered;
roiMatchGlobal.data.rois{iExp1}.committed(1:roiMatchGlobal.data.rois{iExp1}.cellCount)=0;
for iCell = 1:roiMatchGlobal.data.rois{iExp1}.cellCount
allCellCount = allCellCount + 1;
for iExp2 = setdiff(1:length(roiMatchGlobal.data.rois),iExp1)
exp2CellIDMap = roiMatchGlobal.data.rois{iExp2}.roiMapRegistered;
cellPix1 = find(exp1CellIDMap(:)==iCell);
exp2PixVals = exp2CellIDMap(cellPix1);
% find the most numerous pix value in exp2
mostSimilarIdx = mode(exp2PixVals);
if mostSimilarIdx~=0
% find all pix of that roi
cellPix2 = find(exp2CellIDMap(:)==mostSimilarIdx);
% find proportion overlap as function of larger cell
overlapFrac = length(intersect(cellPix1,cellPix2))/max([length(cellPix1),length(cellPix2)]);
allOverlaps(end+1) = overlapFrac;
% debug
%imagesc(imfuse(exp1CellIDMap==iCell,exp2CellIDMap==mostSimilarIdx));
% add it as a match
if overlapFrac>=overlapThreshold
roiMatchGlobal.data.mapping(allCellCount,iExp1)=iCell;
roiMatchGlobal.data.mapping(allCellCount,iExp2)=mostSimilarIdx;
end
end
end
end
end
% check 'reuse' of cells
hist(allOverlaps);
% cycle through mappings committing each cell to a longitudinal group
roiMatchGlobal.data.allSessionMapping = [];
matchMap = zeros(size(roiMatchGlobal.data.refImage));
for iRow = 1:size(roiMatchGlobal.data.mapping,1)
% check if cell is detected in all 3 sessions
putativeMap = roiMatchGlobal.data.mapping(iRow,:);
if sum(putativeMap~=0)==length(roiMatchGlobal.data.rois);
% there's something at each time
% check each cell is available
avail = zeros(1,length(roiMatchGlobal.data.rois));
for iExp = 1:length(roiMatchGlobal.data.rois)
avail = roiMatchGlobal.data.rois{iExp}.committed(putativeMap(iExp));
end
if sum(avail) == 0
% all cells available
for iExp = 1:length(roiMatchGlobal.data.rois)
roiMatchGlobal.data.rois{iExp}.committed(putativeMap(iExp)) = 1;
matchPix = bwperim(roiMatchGlobal.data.rois{iExp}.roiMapRegistered==putativeMap(iExp));
matchMap(matchPix==1)=iExp;
end
roiMatchGlobal.data.allSessionMapping(end+1,:) = putativeMap;
% display outlines of the matches
end
end
end
imagesc(matchMap);colormap(hot);
disp(['Total longitudinal ROIs = ',num2str(size(roiMatchGlobal.data.allSessionMapping,1))]);
% display all rois longitudinally as images
compositeROIs = [];
for iRoi = 1:size(roiMatchGlobal.data.allSessionMapping,1)
cellIDs = roiMatchGlobal.data.allSessionMapping(iRoi,:);
roiColumn = [];
for iExp = 1:length(roiMatchGlobal.data.rois)
roiBounds = bwboundaries(roiMatchGlobal.data.rois{iExp}.roiMapRegistered==cellIDs(iExp));
Top = min(roiBounds{1}(:,1));
Bottom = max(roiBounds{1}(:,1));
Left = min(roiBounds{1}(:,2));
Right = max(roiBounds{1}(:,2));
cellImage = imresize(roiMatchGlobal.data.rois{iExp}.meanFrameRegistered(Top:Bottom,Left:Right),[20 20]);
cellImage = imadjusta(cellImage);
roiColumn = [roiColumn;ones(1,20);cellImage];
end
compositeROIs = [compositeROIs,ones(size(roiColumn,1),1),roiColumn];
end
figure
imagesc(compositeROIs);
title(['Total longitudinal overlapping ROIs = ',num2str(size(roiMatchGlobal.data.allSessionMapping,1)),' (Pan across using hand tool)']);
axis equal;
box off;
colormap gray
ylim([1 size(compositeROIs,1)]);
xlim([1 210]);
axis equal;
axis off
toc;
function editOverlapThreshold_Callback(hObject, eventdata, handles)
% hObject handle to editOverlapThreshold (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editOverlapThreshold as text
% str2double(get(hObject,'String')) returns contents of editOverlapThreshold as a double
% --- Executes during object creation, after setting all properties.
function editOverlapThreshold_CreateFcn(hObject, eventdata, handles)
% hObject handle to editOverlapThreshold (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in btnValidate.
function btnValidate_Callback(hObject, eventdata, handles)
% display all rois longitudinally as images
global roiMatchGlobal;
surroundPix = str2num(handles.editSurroundPix.String);
compositeROIs = [];
resizedROISize = [100 100];
f = figure('units','normalized','outerposition',[0 0 0.5 1]);
for iRoi = 1:size(roiMatchGlobal.data.allSessionMapping,1)
cellIDs = roiMatchGlobal.data.allSessionMapping(iRoi,:);
roiColumn = [];
roiColumnOutline = [];
for iExp = 1:length(roiMatchGlobal.data.rois)
roiBounds = bwboundaries(roiMatchGlobal.data.rois{iExp}.roiMapRegistered==cellIDs(iExp));
imageSize = size(roiMatchGlobal.data.rois{iExp}.roiMapRegistered);
Top = min(roiBounds{1}(:,1))-surroundPix;
Bottom = max(roiBounds{1}(:,1))+surroundPix;
Left = min(roiBounds{1}(:,2))-surroundPix;
Right = max(roiBounds{1}(:,2))+surroundPix;
% check if roi border is larger than image
topPad = 0;
bottomPad = 0;
leftPad = 0;
rightPad = 0;
if Top < 1
topPad = Top*-1;
Top = 1;
end
if Bottom > imageSize(1)
bottomPad = Bottom - imageSize(1);
Bottom = imageSize(1);
end
if Left < 1
leftPad = Left * -1;
Left = 1;
end
if Right > imageSize(2)
rightPad = Right - imageSize(2);
Right = imageSize(2);
end
cellImageRaw = roiMatchGlobal.data.rois{iExp}.meanFrameRegistered(Top:Bottom,Left:Right);
roiImageRaw = roiMatchGlobal.data.rois{iExp}.roiMapRegistered(Top:Bottom,Left:Right);
% add padding if needed
medVal = nanmedian(cellImageRaw(:));
if topPad
cellImageRaw = [nan(topPad,size(cellImageRaw,2));cellImageRaw];
roiImageRaw = [nan(topPad,size(roiImageRaw,2));roiImageRaw];
end
if bottomPad
cellImageRaw = [cellImageRaw;nan(bottomPad,size(cellImageRaw,2))];
roiImageRaw = [roiImageRaw;nan(bottomPad,size(roiImageRaw,2))];
end
if leftPad
cellImageRaw = [nan(size(cellImageRaw,1),leftPad),cellImageRaw];
roiImageRaw = [nan(size(roiImageRaw,1),leftPad),roiImageRaw];
end
if rightPad
cellImageRaw = [cellImageRaw,nan(size(cellImageRaw,1),rightPad)];
roiImageRaw = [roiImageRaw,nan(size(roiImageRaw,1),rightPad)];
end
cellImageRaw(isnan(cellImageRaw(:)))=medVal;
cellImage = imresize(cellImageRaw,resizedROISize);
cellImage = imadjusta(cellImage);
roiImage = imresize(roiImageRaw,resizedROISize,'nearest');
matchPix = bwperim(roiImage==cellIDs(iExp));
roiColumnOutline = [roiColumnOutline;zeros(1,resizedROISize(1));matchPix==1];
roiColumn = [roiColumn;ones(1,resizedROISize(1));cellImage];
end
% display and confirm etc
dispImage = repmat(roiColumn,[1,1,3]);
outlineDisp = roiColumn;
outlineDisp(roiColumnOutline==1) = 1;
dispImage(:,:,1)=outlineDisp;
imagesc(dispImage);
axis equal;
box off;
colormap gray
ylim([1 size(roiColumn,1)]);
xlim([1 20]);
axis equal;
axis off
title(['Keep (space) Discard (z) Stop (escape) (',num2str(iRoi),'/',num2str(size(roiMatchGlobal.data.allSessionMapping,1)),')']);
while (f.isvalid)
disp(['Keep (space) Discard (z) Stop (escape) (',num2str(iRoi),'/',num2str(size(roiMatchGlobal.data.allSessionMapping,1)),')']);
pause; % wait for a keypress
currkey=get(gcf,'CurrentKey');
switch currkey
case 'escape'
f.delete;
return;
case 'space'
roisToKeep(iRoi) = 1;
break;
case 'z'
roisToKeep(iRoi) = 0;
break;
otherwise
title(['Unknown key command - Keep (space) Discard (z) Stop (escape) (',num2str(iRoi),'/',num2str(size(roiMatchGlobal.data.allSessionMapping,1)),')']);
end
end
end
if f.isvalid;f.delete;end;
roiMatchGlobal.data.allSessionMapping=roiMatchGlobal.data.allSessionMapping(logical(roisToKeep),:);
disp(['Total longitudinal ROIs = ',num2str(size(roiMatchGlobal.data.allSessionMapping,1))]);
% --- Executes on button press in btnShowAll.
function btnShowAll_Callback(hObject, eventdata, handles)
global roiMatchGlobal;
compositeROIs = [];
for iRoi = 1:size(roiMatchGlobal.data.allSessionMapping,1)
cellIDs = roiMatchGlobal.data.allSessionMapping(iRoi,:);
roiColumn = [];
for iExp = 1:length(roiMatchGlobal.data.rois)
roiBounds = bwboundaries(roiMatchGlobal.data.rois{iExp}.roiMapRegistered==cellIDs(iExp));
Top = min(roiBounds{1}(:,1));
Bottom = max(roiBounds{1}(:,1));
Left = min(roiBounds{1}(:,2));
Right = max(roiBounds{1}(:,2));
cellImage = imresize(roiMatchGlobal.data.rois{iExp}.meanFrameRegistered(Top:Bottom,Left:Right),[20 20]);
cellImage = imadjusta(cellImage);
roiColumn = [roiColumn;ones(1,20);cellImage];
end
compositeROIs = [compositeROIs,ones(size(roiColumn,1),1),roiColumn];
end
figure
imagesc(compositeROIs);
axis equal;
box off;
colormap gray
ylim([1 size(compositeROIs,1)]);
xlim([1 210]);
axis equal;
axis off
title(['Number of rois = ',num2str(size(roiMatchGlobal.data.allSessionMapping,1)),' - rows are experiments - pan with hand tool']);
function editSurroundPix_Callback(hObject, eventdata, handles)
% hObject handle to editSurroundPix (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of editSurroundPix as text
% str2double(get(hObject,'String')) returns contents of editSurroundPix as a double
% --- Executes during object creation, after setting all properties.
function editSurroundPix_CreateFcn(hObject, eventdata, handles)
% hObject handle to editSurroundPix (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in btnShowValid.
function btnShowValid_Callback(hObject, eventdata, handles)
global roiMatchGlobal;
compositeROIs = [];
for iRoi = 1:size(roiMatchGlobal.data.allSessionMapping,1)
cellIDs = roiMatchGlobal.data.allSessionMapping(iRoi,:);
roiColumn = [];
for iExp = 1:length(roiMatchGlobal.data.rois)
roiBounds = bwboundaries(roiMatchGlobal.data.rois{iExp}.roiMapRegistered==cellIDs(iExp));
Top = min(roiBounds{1}(:,1));
Bottom = max(roiBounds{1}(:,1));
Left = min(roiBounds{1}(:,2));
Right = max(roiBounds{1}(:,2));
cellImage = imresize(roiMatchGlobal.data.rois{iExp}.meanFrameRegistered(Top:Bottom,Left:Right),[20 20]);
cellImage = imadjusta(cellImage);
roiColumn = [roiColumn;ones(1,20);cellImage];
end
compositeROIs = [compositeROIs,ones(size(roiColumn,1),1),roiColumn];
end
figure
imagesc(compositeROIs);
axis equal;
box off;
colormap gray
ylim([1 size(compositeROIs,1)]);
xlim([1 210]);
axis equal;
axis off
title(['Number of rois = ',num2str(size(roiMatchGlobal.data.allSessionMapping,1))]);
function [I2] = imadjusta(I)
I2 = I - min(I(:));
I2 = I2/max(I2(:));
I2 = imadjust(I2);
% --- Executes on button press in btnHelp.
function btnHelp_Callback(hObject, eventdata, handles)
edit RoiMatchHelp.m;