forked from evodevosys/AroSpotFindingSuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentifySpots.m
executable file
·1866 lines (1553 loc) · 80.4 KB
/
identifySpots.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 varargout = identifySpots(varargin) %nameMod
% Modified by Allison Wu, 2012 May
% - Work with the new data format.
% =============================================================
% Name: identifySpots.m %nameMod
% Version: 2.5.1, 20 May 2013 %nameMod
% Author: Allison Wu & Scott Rifkin, webpage: http://www.biology.ucsd.edu/labs/rifkin/
%
% Attribution: Wu, AC-Y and SA Rifkin. spotFinding Suite version 2.5, 2013 [journal citation TBA]
% License: Creative Commons Attribution-ShareAlike 3.0 United States, http://creativecommons.org/licenses/by-sa/3.0/us/
% Website: http://www.biology.ucsd.edu/labs/rifkin/software/spotFindingSuite
% Email for comments, questions, bugs, requests: Allison Wu < dblue0406 at gmail dot com >, Scott Rifkin < sarifkin at ucsd dot edu >
%
% =============================================================
% Updates:
% 2013 Apr. 29th: bug fixes for the zoom128 moving frame problem and
% max merge image.
% 2013 May 20th: fixed bugs caused by including 'Edge Spots';
% 2013 May 22nd: Fixed max-merged image problem.
%
%IDENTIFYSPOTS M-file for identifySpots.fig
% IDENTIFYSPOTS, by itself, creates a new IDENTIFYSPOTS or raises the existing
% singleton*.
%
% H = IDENTIFYSPOTS returns the handle to a new IDENTIFYSPOTS or the handle to
% the existing singleton*.
%
% IDENTIFYSPOTS('Property','Value',...) creates a new IDENTIFYSPOTS using the
% given property value pairs. Unrecognized properties are passed via
% varargin to identifySpots_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% IDENTIFYSPOTS('CALLBACK') and IDENTIFYSPOTS('CALLBACK',hObject,...) call the
% local function named CALLBACK in IDENTIFYSPOTS.M with the given input
% arguments.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
%
% identifySpots is a gui to create a training set. %nameMod
% The gui consists of three image panes and several buttons
% Regional maxima (=potential spots) are ranked by the function morphFilterSpotImage3D.m
% Then the program goes through the rankings and lets the user decide whether the maxima in the left image pane are spots or not
% The left pane shows a 16x16 square centered on a the focal maxima (there may be others in the image as well). Maxima are highlighted in blue. If a maximum has already been accepted, it is highlighted in red.
% Note also that these are 3D maxima. So if a clear maximum isn't highlighted in blue in the current slice, it will be in an adjacent slice
% The right pane shows the location of the zoomed left pane area at lower magnification
% The small bottom pane shows the location of the left pane in the whole image
% The 3D plots in the middle are intensity histograms of the 16x16 square in the left image and that same square in neighboring slices
% Possible actions:
% Click on a square in the left image pane.
% This toggles the square. Blue means it is a candidate spot. Greyscale means it is not under consideration.
% Click on a the right image pane.
% This will move the focus to wherever you clicked.
% Click Next and Nothing button
% This goes to the next maximum in the list without making any judgments about the maxima (blue squares) in the current left image
% Click Next and Accept button
% This accepts all maxima (blue squares) in the current left image as spots and adds them to the positive training set
% Click Next and Reject button
% This rejects all maxima (blue squares) in the current left image as spots and adds them to the negative training set
% Click Next Slice
% This moves up one slice in the z stack, not doing anything with current maxima in the left image
% Click Next and Reject button
% This rejects all maxima (blue squares) in the current left image as spots and adds them to the negative training set
% Click Undo last button
% This rolls back the current state one decision (one click on something). Default is a memory of 6 states, but this can be modified below
% in the line that reads: handles.rollbackDepth=6;
% Each memory state stored can be many MB, so it probably isn't a good idea nor necessary to go much beyond 6
% This button is useful because there will be times when the user clicks accept and only notices too late that there was a non-spot maximum hiding up there in the corner
% Or the user might simply press the wrong button
% Adjust spotRank slider. This is used to decide where in the ranked spot list to go next. By default it starts with the top ranked maximum and goes from there. Ideally you'd want some good examples of borderline spots. This turns out to be difficult to get at this point, but you can jump around the spot list to try.
% Click Finished.
% Self explanatory. Returns to createFISHTrainingSet
% Toggle Background spots checkbox
% When checked, any spots clicked on in the left image pane will be
% marked as background spots. This could be useful for image
% normalization, but isn't really used as the pipeline currently
% stands. Spots selected as background will be highlighted in
% yellow.
%
% To start, choose around 100 positive and 100 negative spots (this seems to be sufficient to get started but hasn't been tested exhaustively).. When you
% correct your first few images (using reviewFISHClassification.m), you'll add
% to this. Try to get some borderline examples, but this is easier from
% reviewFISHClassification because it has already highlighted borderline cases for you.
%Modified 3 May 2011. evaluateFISHImageStack is run on directory before
%everything. This creates a wormGaussianFit files. these have the
%statistics and (important for this function) also have the list of
%relevant maxima...no longer are all maxima in bounds. so morph function
%is no longer called
%11 May 2011. Modified so that it only loads one slice at a time to help
%with memory. Branched off 1p2p2_highMemory when I don't need to deal with
%this
%6 July 2011
%Modified so there is a flag to switch between high and low memory at the
%appropriate spots. Set the flag in the program for now.
%18Oct2011
%Made spotListSorted into a structure. Also tried to remove bugs and
%detritus
% Edit the above text to modify the response to help identifySpots
% Last Modified by GUIDE v2.5 20-Jun-2014 22:44:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
%mfilename
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @identifySpots_OpeningFcn, ...
'gui_OutputFcn', @identifySpots_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
%NEW WAY OF FINDING BACKGROUND
%MAKE A NEW GUI TO DO CAMERA BACKGROUND - JUST BASED ON WHAT I HAVE BUT NO
%BUTTON SWITCHING
%FOR EMBRYO BACKGROUND (IS THIS NEEDED?) JUST HAVE IT DO IT AUTOMATICALLY
%POSTHOC LIKE I DID IN THE RANDOM FORESTS THING
% --- Executes just before identifySpots is made visible.
function identifySpots_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 unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
%varargin is stack,segMasks,startingSlice,dye
% Choose default command line output for identifySpots
handles.output = hObject;
%EDIT SAR 4/15/09
%%%%% 19Oct2011
%%%The code throws an error where the spotRankSlider Min and Max are not
%%%changed until in the displayImFull function but iCurrentSpot may be
%%%outside this:
% Warning: slider control requires that Min be less than Max
% Control will not be rendered until all of its parameter values are valid
% (Type "warning off MATLAB:hg:uicontrol:ParameterValuesMustBeValid" to suppress
% this warning.)
% > In uiwait at 73
% In identifySpots>identifySpots_OpeningFcn at 365
% In gui_mainfcn at 221
% In identifySpots at 113
% In createFISHTrainingSet at 121
% This isn't an issue because the slider is reset in displayImFull, but
% the warning is annoying. Hence:
warning off MATLAB:hg:uicontrol:ParameterValuesMustBeValid
%%%%%%%%%%%%%
handles.highMemory=1;
global intensityFraction
handles.figure_handle=get(0,'CurrentFigure');
handles.surfPlots={handles.surfMinus2,handles.surfMinus1,handles.surfCurrentZ,handles.surfPlus1,handles.surfPlus2};
%get stuff from varargins
%%
%segMasks=varargin{1};
handles.currentZ=varargin{1};%will modify later if need be based on emptiness of maxima in slice
segStacks=varargin{2};
segMasks=varargin{3};
worms=varargin{4};
wi=varargin{5};
%%
%%%Note that this depends on particular file name structure of
%%%wormGaussianFit
%load([dye '_' stackSuffix '_wormGaussianFit.mat']);
%load([dye '_' stackSuffix '_SegStacks.mat']);
%%%%%%%%%%%%%%%%%
outlines=bwperim(segMasks{wi})>0;
handles.worms=worms;
%stackInfo.stackName=worms{1}.stackName;
stackInfo.segStackFile=worms{1}.segStackFile;
%stackInfo.stackFileType=worms{1}.stackFileType;
stackInfo.numberOfPlanes=worms{1}.numberOfPlanes;
%%%%%%%%%%% Set up the spot data info
%%
spotNum=length(worms{wi}.spotDataVectors.rawValue);
%sortedSpotData.rows=[];
%sortedSpotData.cols=[];
%sortedSpotData.zs=[];
%sortedSpotData.wormNumber=[];
%sortedSpotData.spotInfoNumberInWorm=[];
sortedSpotData.xyz=[worms{wi}.spotDataVectors.locationStack];
sortedSpotData.values=worms{wi}.spotDataVectors.rawValue;
sortedSpotData.filteredValue=worms{wi}.spotDataVectors.filteredValue;
sortedSpotData.spotInfoNumberInWorm=worms{wi}.spotDataVectors.spotInfoNumberInWorm;
sortedSpotData.wormNumber=ones(spotNum,1)*wi;
%for si=1:size(worms{wi}.spotInfo,2)
%sortedSpotData.rows=[sortedSpotData.rows;worms{wi}.spotInfo{si}.locations.stack(1)];
%sortedSpotData.cols=[sortedSpotData.cols;worms{wi}.spotInfo{si}.locations.stack(2)];
%sortedSpotData.zs=[sortedSpotData.zs;worms{wi}.spotInfo{si}.locations.stack(3)];
%sortedSpotData.values=[sortedSpotData.values;worms{wi}.spotInfo{si}.rawValue];
%sortedSpotData.filteredValues=[sortedSpotData.filteredValues;worms{wi}.spotInfo{si}.filteredValue];
%sortedSpotData.wormNumber=[sortedSpotData.wormNumber; wi];%could pull out but clearer here
%sortedSpotData.spotInfoNumberInWorm=[sortedSpotData.spotInfoNumber
%InWorm; si];
%end;
%Need to sort them
[sortedSpotData.filteredValue,VFiltSortOrder]=sort(sortedSpotData.filteredValue,'descend');
sortedSpotData.xyz=sortedSpotData.xyz(VFiltSortOrder,:);
%sortedSpotData.rows=sortedSpotData.rows(VFiltSortOrder);
%sortedSpotData.cols=sortedSpotData.cols(VFiltSortOrder);
%sortedSpotData.zs=sortedSpotData.zs(VFiltSortOrder);
sortedSpotData.values=sortedSpotData.values(VFiltSortOrder);
%sortedSpotData.wormNumber=sortedSpotData.wormNumber(VFiltSortOrder);
sortedSpotData.spotInfoNumberInWorm=sortedSpotData.spotInfoNumberInWorm(VFiltSortOrder);
sortedSpotData.scaledValues=sortedSpotData.values;
handles.sortedSpotData=sortedSpotData;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%Count the number in each slice
%%
handles.nMaximaBySlice=zeros(1,stackInfo.numberOfPlanes);
for zi=1:stackInfo.numberOfPlanes;
handles.nMaximaBySlice(zi)=sum(handles.sortedSpotData.xyz(:,3)==zi);
end;
%%
%9/17/11 - modify handles.currentZ if nMaxima is empty
%%
zi=handles.currentZ;
while handles.nMaximaBySlice(zi)==0 && zi<=stackInfo.numberOfPlanes
zi=zi+1;
handles.currentZ=zi;
end;
if handles.currentZ>stackInfo.numberOfPlanes
disp('No regional maxima in stack. This could cause a problem in the program, but there is a bigger problem.');
return
end;
%%%%%%%%%%%%%%%%%%%%%%
%%
dataStructure.segMasks=segMasks{wi}; % Note: original segments were for the entire stack. now segMasks is for each worm.
dataStructure.outlines=outlines; % Note: original outlines were for the entire stack. now outlines is for each worm.
dataStructure.cameraBackground=[];
%dataStructure.segStacks=segStacks{wi};
dataStructure.wi=wi;
dataStructure.stackInfo=stackInfo;
dataStructure.scaledStack=segStacks{wi};
clearvars -except dataStructure handles hObject
%save(fullfile(pwd,'tmp.mat'))
%load tmp.mat
intensityFraction=.8;
if handles.highMemory
for k=1:dataStructure.stackInfo.numberOfPlanes
[dataStructure.scaledStack(:,:,k),handles.sortedSpotData.scaledValues]=loadAndScaleSlice(dataStructure.scaledStack,k,handles);
%slice=stk(:,:,k);
%mnSlice=min(slice(:));
%mxSlice=max(slice(:));
%rangeSlice=mxSlice-mnSlice;
%dataStructure.scaledStack(:,:,k)=(slice-mnSlice)/rangeSlice;
%handles.sortedSpotData.scaledValues(handles.sortedSpotData.xyz(:,3)==k)=(handles.sortedSpotData.scaledValues(handles.sortedSpotData.xyz(:,3)==k)-mnSlice)/rangeSlice;%All are not scaled yet
end
else
[slice,handles.sortedSpotData.scaledValues]=loadAndScaleSlice(dataStructure.scaledStack,handles.currentZ,handles);
dataStructure.scaledSlice=slice;
clear slice
end
h=size(dataStructure.scaledStack,3);
%dataStructure.fullImage=imscale(max(dataStructure.scaledStack(:,:,floor(h/5):ceil(h*4/5)),[],3));
dataStructure.fullImage=max(dataStructure.scaledStack(:,:,max(handles.currentZ-1,1):min(handles.currentZ+1,h)),[],3);
handles.lastHandles={};
handles.rollbackDepth=6;
dataStructure.goodSpots=[];
dataStructure.rejectedSpots=[];
dataStructure.bkgdSpots=[];
handles.dataStructure=dataStructure;
handles.dataStructure.origSize=[size(dataStructure.segMasks) handles.worms{dataStructure.wi}.numberOfPlanes];%size(handles.dataStructure.scaledStack);
%x=1,y=1 is NW, x runs W-E, y runs N-S
%Deal with the slider
zoom128Size=get(handles.zoom128_slider,'Value');
set(handles.zoom128_slider,'Max',max(size(dataStructure.segMasks)));
set(handles.zoom128_slider_txt,'String',['Zoom128 Size: ' num2str(get(handles.zoom128_slider,'Value'))]);
handles.currentZoom16_width=16;
handles.currentZoom128_width=zoom128Size;
handles.currentZoom16_height=16;
handles.currentZoom128_height=zoom128Size;
%set(handles.zoom128Slider,'Value',log2(zoom128Size));
%these are in axes=spatial coordinates -> NW corner is .5,.5 [x,y]
handles.currentZoom16_x=.5;
handles.currentZoom16_y=.5;
handles.currentZoom128_x=.5;
handles.currentZoom128_y=.5;
handles.currentZoom16_nSpots=0;
c16X=handles.currentZoom16_x;
c16Y=handles.currentZoom16_y;
c16W=handles.currentZoom16_width;
c16H=handles.currentZoom16_height;
c16R=yToRow(c16Y);
c16C=xToCol(c16X);
if handles.highMemory
currentSlice=handles.dataStructure.scaledStack(:,:,handles.currentZ);
else
currentSlice=handles.dataStructure.scaledSlice;
end;
[handles.blueSlice,handles.confirmedSlice,handles.blueSpotRankList,handles.blueSpots,handles.bkgd,handles.sliceSortedSpotData]=updateBlueSlice2(handles.sortedSpotData,zeros(size(currentSlice)),handles.currentZ);
%blueSpots is an nx2 matrix of row and column locations
set(handles.spotRankSlider,'Max',handles.nMaximaBySlice(handles.currentZ));
handles.iCurrentSpot=1;%start at 1 get(handles.spotRankSlider,'Value');
%%%%%%%%%%%%%%%
%Current Locations
%%
c16X=handles.currentZoom16_x;
c16Y=handles.currentZoom16_y;
c16W=handles.currentZoom16_width;
c16H=handles.currentZoom16_height;
c128X=handles.currentZoom128_x;
c128Y=handles.currentZoom128_y;
c128W=handles.currentZoom128_width;
c128H=handles.currentZoom128_height;
c16R=yToRow(c16Y);
c16C=xToCol(c16X);
c128R=yToRow(c128Y);
c128C=xToCol(c128X);
%%
%%%%%%%%%%%%%%%%%
[c16X,c16Y,c16R,c16C,handles.blueSlice,handles.confirmedSlice,handles.currentZ,didTopSlice,handles.blueSpots,handles.iCurrentSpot,handles.blueSpotRankList,handles.bkgd,handles.sortedSpotData.scaledValues,handles.sliceSortedSpotData,handles.dataStructure.scaledSlice]=moveZoom16(c16X,c16Y,c16W,c16H,c128X,c128Y,c128W,c128H,handles);
[regionalMaxes16,WC16,EC16,NR16,SR16]=shiftZoom16Frame(handles.blueSlice,c16R, c16C,c16H,c16W);
regionalMaxes16=handles.blueSlice(NR16:SR16,WC16:EC16);
handles.currentZoom16_x=c16X;
handles.currentZoom16_y=c16Y;
%%%%%%%%%%%%%%%%%%%%
%always try to keep zoom16 in the middle of zoom128
%but if at the edge, still do a full square
handles.currentZoom128_x=min(colToX(handles.dataStructure.origSize(1))-c128W+1,max(.5,c16X-c128W/2));
display(handles.currentZoom128_x)
display(colToX(handles.dataStructure.origSize(1))-c128W+1)
display(max(.5,c16X-c128W/2))
handles.currentZoom128_y=min(rowToY(handles.dataStructure.origSize(2))-c128H+1,max(.5,c16Y-c128H/2));
display(handles.currentZoom128_y)
%%%%%%%%%%%%%%%%%%%%%%%
%this is the function that will record the center of the spot
set(handles.zoom16,'ButtonDownFcn',@zoom16_ButtonDownFcn);
%this function will move the focus to a new place
set(handles.zoom128,'ButtonDownFcn',@zoom128_ButtonDownFcn);
%%%%%%%%%%%%%%%%%%%%% Set text data in gui
set(handles.z_pos_txt,'String',outOf('slice', handles.currentZ,handles.dataStructure.stackInfo.numberOfPlanes));
%set(handles.x16_txt,'String',['x16: ' num2str(handles.currentZoom16_x)]);
%set(handles.y16_txt,'String',['y16: ' num2str(handles.currentZoom16_y)]);
%set(handles.x128_txt,'String',['x128: ' num2str(handles.currentZoom128_x)]);
%set(handles.y128_txt,'String',['y128: ' num2str(handles.currentZoom128_y)]);
handles.currentZoom16_nSpots=sum(regionalMaxes16(:)>0);
set(handles.nSpots_txt,'String',[num2str(handles.currentZoom16_nSpots) ' spots in view']);
set(handles.acceptedNSpots_txt,'String','0 accepted spots');
set(handles.rejectedNSpots_txt,'String','0 rejected spots');
set(handles.NregionalMaximaLeftInSlice_txt,'String',[num2str(length(handles.blueSpotRankList)) ' regional maxima left']);
set(handles.spotRankReporter_txt,'String',['Spot Rank: ' num2str(handles.blueSpotRankList(handles.iCurrentSpot))]);
%%%%%%%%%%%%%%%%%%%%%%%%%%
%set(handles.zoom128Slider_txt,'String',num2str(2^get(handles.zoom128Slider,'Value')));
%right now I won't have a scrollbar function
guidata(hObject,handles);
displayImFull(hObject,handles);
%END SAR EDITS
% UIWAIT makes identifySpots wait for user response (see UIRESUME)
uiwait(handles.figure1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END OPENING_FCN %%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function row=yToRow(y)
row=floor(y+.5);
function col=xToCol(x)
col=floor(x+.5);
function x=colToX(c)
x=c-.5;
function y=rowToY(r)
y=r-.5;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on mouse press over axes background.
function zoom16_ButtonDownFcn(currhandle, eventdata)
% hObject handle to color_im (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%This function will be invoked when the user clicks on the zoom16 image.
%This happens usually when the user is manually rejecting a spot where
%there are other acceptable spots in the field of view
%The role of this function is to update blueSlice, blueSpots,
%blueSpotRankList,
data = guidata(currhandle);
data.lastHandles=data;
data=resetLastHandles(data,data.rollbackDepth, 0);
%%% Get the point that was clicked and translate it into rows and columns
pt = get(data.zoom16,'currentpoint');
pixelToChange_c=xToCol(pt(1,1));
pixelToChange_r=yToRow(pt(1,2));
%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% 18 Oct 2011. I removed the functionality where you
%%%%%%%%%%%%%%%%% can click in zoom16 and ADD a spot. This should not
%%%%%%%%%%%%%%%%% happen because all regional maxima are accounted
%%%%%%%%%%%%%%%%% for. However, I only comment it out here because it
%%%%%%%%%%%%%%%%% might be worthwhile to put it back in at some point
%%% So first check to see if this pixel is nonzero in blueSlice...if it is,
%%% then proceed. if it isn't then ignore.
if data.blueSlice(pixelToChange_r,pixelToChange_c)
%%% %%% %%% %% %%
%%%%%% If adding a spot, then add 1. If removing a spot then subtract
%%%%%% 1 from the count of the number of spots in the 16view
data.currentZoom16_nSpots=data.currentZoom16_nSpots+(-1)^(data.blueSlice(pixelToChange_r,pixelToChange_c)>0);
set(data.nSpots_txt,'String',[num2str(data.currentZoom16_nSpots) ' spots in view']);
%%%%%%%%%%%%%%
%%%%%%%%%%%% Change the blueSlice pixel value to 0 or the value of the
%%%%%%%%%%%% pixel
if data.highMemory
data.blueSlice(pixelToChange_r,pixelToChange_c)=(~data.blueSlice(pixelToChange_r,pixelToChange_c)).*data.dataStructure.scaledStack(pixelToChange_r,pixelToChange_c,data.currentZ);
else
data.blueSlice(pixelToChange_r,pixelToChange_c)=(~data.blueSlice(pixelToChange_r,pixelToChange_c)).*data.dataStructure.scaledSlice(pixelToChange_r,pixelToChange_c);
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%
%disp([num2str(size(data.blueSpots,1)) ' in blueSpots']);
%%% blue spots is an nx2 matrix of rows a columns
if ~data.blueSlice(pixelToChange_r,pixelToChange_c)
%then it was there and is no longer: remove and add to rejected list
%%%%%%%%%%%% add or remove from blueSpots and can use same index to
%%%%%%%%%%%% remove from blueSpotRankList
[~,~,indexToRemove]=intersect([pixelToChange_r,pixelToChange_c],data.blueSpots,'rows');
data.blueSpots(indexToRemove,:)=[];
data.blueSpotRankList(indexToRemove)=[];
%What does this do to iCurrentSpot which is the index of the
%center of the zoom16?
if indexToRemove<data.iCurrentSpot
data.iCurrentSpot=data.iCurrentSpot-1;
end;
data.iCurrentSpot=min(max(1,data.iCurrentSpot),length(data.blueSpotRankList));
%%%%%%%%%%%%%%
data.dataStructure.rejectedSpots=[data.dataStructure.rejectedSpots ;[pixelToChange_r,pixelToChange_c data.currentZ]];
set(data.rejectedNSpots_txt,'String',[num2str(size(data.dataStructure.rejectedSpots,1)),' rejected spots']);
%%%%%%%%%%%%% now it is gone from blueSpots and blueSpotRankList
%%%%%% Don't want to adjust currentSpotRank here because this only
%%%%%% happens when press Next & something
else
%%%%%%%%% 18 Oct 2011
% With the initial if statement, this part of the if-then will
% never be run....however, I keep it in here if it needs to be
% added back in the future. However, would need to make sure the
% data structures are updated since I didn't finish doing that
%then add it
%This is more complicated. need to add to the various data
%structures
%But this should not happen
%Because later on would also have to add to worms file and do the
%statistics
data.blueSpots=[data.blueSpots;[pixelToChange_r,pixelToChange_c]];
%also check to see if it happens to be in rejectedSpots (say clicked
%off then clicked back on...if it is, then remove it
if ~isempty(data.dataStructure.rejectedSpots)
[~,~,indexOfSpot]=intersect([pixelToChange_r,pixelToChange_c data.currentZ],data.dataStructure.rejectedSpots,'rows');
if isempty(indexOfSpot)
data.dataStructure.rejectedSpots(indexOfSpot,:)=[];
end;
end;
set(data.rejectedNSpots_txt,'String',[num2str(size(data.dataStructure.rejectedSpots,1)),' rejected spots']);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end;
set(data.NregionalMaximaLeftInSlice_txt,'String',[num2str(length(data.blueSpotRankList)) ' regional maxima left']);
%%%%%%%%%%%% Was that just the last spot in the slice? %%%%%%%%%%%%%%%%%
%%%%%%%%% Copied from nextSlice_Callback
if isempty(data.blueSpots)
data.lastHandles=data;
data=resetLastHandles(data,data.rollbackDepth,0);
if data.highMemory
data.lastHandles.dataStructure=rmfield(data.lastHandles.dataStructure,'scaledStack');
else
data.lastHandles.dataStructure=rmfield(data.lastHandles.dataStructure,'scaledSlice');
end;
if data.currentZ<data.dataStructure.origSize(3)
%disp(['Moving from slice ' num2str(data.currentZ) ' to slice ' num2str(data.currentZ+1)]);
data.currentZ=data.currentZ+1;
if ~data.highMemory
[currentSlice,spotVSortedScaled]=loadAndScaleSlice(data.dataStructure.scaledStack,data.currentZ,data);
data.dataStructure.scaledSlice=currentSlice;
data.sortedSpotData.scaledValues=spotVSortedScaled;
end;
c16X=1;
c16Y=1;
c128X=1;
c128Y=1;
c16W=data.currentZoom16_width;
c16H=data.currentZoom16_height;
c128W=data.currentZoom128_width;
c128H=data.currentZoom128_height;
c16R=yToRow(c16Y);
c16C=xToCol(c16X);
c128R=yToRow(c128Y);
c128C=xToCol(c128X);
%%%
%Start new slice from 1
previousSpotRank=1;
%update blueSlice and blueSpots
[data.blueSlice, data.confirmedSlice,data.blueSpotRankList,data.blueSpots,data.bkgd,data.sliceSortedSpotData]=updateBlueSlice2(data.sortedSpotData,data.confirmedSlice,data.currentZ);
%Now blueSpotRankList is updated for the new slice
if previousSpotRank>data.blueSpotRankList(end)
data.iCurrentSpot=length(data.blueSpotRankList);
else
data.iCurrentSpot=find(data.blueSpotRankList==previousSpotRank,1,'first');
end;
data.currentZoom16_x=1;
data.currentZoom16_y=1;
data.currentZoom128_x=1;
data.currentZoom128_y=1;
%moves the 16 square along (with the possibility of going to next
%slice)
[c16X,c16Y,c16R,c16C,data.blueSlice,data.confirmedSlice,data.currentZ,didTopSlice,data.blueSpots,data.iCurrentSpot,data.blueSpotRankList,data.bkgd,data.sortedSpotData.scaledValues,data.sliceSortedSpotData,data.dataStructure.scaledSlice]=moveZoom16(c16X,c16Y,c16W,c16H,c128X,c128Y,c128W,c128H,data);
if didTopSlice==1
uiresume(gcbf);%this should jump back right after uiwait
end;
data.currentZoom16_x=c16X;
data.currentZoom16_y=c16Y;
%always try to keep zoom16 in the middle of zoom128
%but if at the edge, still do a full square
data.currentZoom128_x=min(colToX(data.dataStructure.origSize(2))-c128W+1,max(.5,c16X-c128W/2));
data.currentZoom128_y=min(rowToY(data.dataStructure.origSize(1))-c128H+1,max(.5,c16Y-c128H/2));
c16R=yToRow(c16Y);
c16C=xToCol(c16X);
%now redo regional max stuff
[regionalMaxes16,WC16,EC16,NR16,SR16]=shiftZoom16Frame(data.blueSlice,c16R, c16C,c16H,c16W);
data.currentZoom16_nSpots=sum(regionalMaxes16(:)>0);
set(data.nSpots_txt,'String',[num2str(data.currentZoom16_nSpots) ' spots in view']);
else%already at top slice
disp('identifySpots finished');
uiresume(data.figure1);
end;
end;%%if this is the topSlice, then this might cause an error
%Need to deal with the case where I clikc on th elast spot in a slice
%Also seems ot be a problem where sliceSortedSpotData is getting cut by one
%when go to knew slice
guidata(currhandle,data);
displayImFull(currhandle,data,0);
end;%%end if it is a regional maximum - Added 18Oct2011
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on mouse press over axes background.
function zoom128_ButtonDownFcn(currhandle, eventdata)
% hObject handle to color_im (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%This function is just to move around the zoom128 image. It doesn't do
%anything to blueSpots or any of the data structures.
%But it could complicate matters in that it escapes from the rank ordering
%and won't necessarily come back exactly...if you move to a zoom16 with
%blueSpotRank less than the previous one, then when these are deleted upon
%Next&, iCurrentSpot will not change but will come back X later than
%previous.
data = guidata(currhandle);
%%%%%%%%%%%%%%%%%%%%%%
c16X=data.currentZoom16_x;
c16Y=data.currentZoom16_y;
c16W=data.currentZoom16_width;
c16H=data.currentZoom16_height;
c128X=data.currentZoom128_x;
c128Y=data.currentZoom128_y;
c128W=data.currentZoom128_width;
c128H=data.currentZoom128_height;
c16R=yToRow(c16Y);
c16C=xToCol(c16X);
c128R=yToRow(c128Y);
c128C=xToCol(c128X);
%%%%%%
pt = get(data.zoom128,'currentpoint');
% xPixelOffset=floor(pt(1,2)-.5);
% yPixelOffset=floor(pt(1,1)-.5);
newC=xToCol(pt(1,1));
newR=yToRow(pt(1,2));
%%%%%%%%%%%%%%%%%%%%%
% 1 July 14
% If this is too close to the edge it will throw an error when trying to
% figure out where the zoom16 image should be. Protect it from that
%newR and newC should be the upper left corner
% disp('newR, newC');
% disp([newR, newC]);
% disp(data.dataStructure.origSize([2 1]));
% disp(newR-floor(c16H/2));
newC=max(1,min(newC,data.dataStructure.origSize(2)-c16W+1));
newR=max(1,min(newR,data.dataStructure.origSize(1)-c16H+1));
% disp([newR, newC]);
% disp(pt(1,:));
%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% I don't know why this is in here.
% [spotR,spotC]=find(data.blueSlice(c16R:c16R+c16H-1,c16C:c16C+c16W-1)>0);
% %need to add z information
% newSpots=[];
% for i=1:size(spotR)
% newSpots=[newSpots; [spotR(i)+c16R-1 spotC(i)+c16C-1 data.currentZ]];
% end;
% %remove from blueSpots...why?
% if size(newSpots,1)>0 && size(data.blueSpots,1)>0
% [~,~,blueSpotsToDelete]=intersect(newSpots(:,1:2),data.blueSpots,'rows');
% data.blueSpots(blueSpotsToDelete,:)=[];
% end;
% set(data.NregionalMaximaLeftInSlice_txt,'String',[num2str(length(data.blueSpotRankList)) ' regional maxima left']);
%move all the axes - move zoom16 to start at the upper corner of zoom128
data.currentZoom16_x=colToX(newC);
data.currentZoom16_y=rowToY(newR);
data.currentZoom128_x=colToX(newC);
data.currentZoom128_y=rowToY(newR);
c16X=data.currentZoom16_x;
c16Y=data.currentZoom16_y;
c16W=data.currentZoom16_width;
c16H=data.currentZoom16_height;
c128X=data.currentZoom128_x;
c128Y=data.currentZoom128_y;
c128W=data.currentZoom128_width;
c128H=data.currentZoom128_height;
c16R=yToRow(c16Y);
c16C=xToCol(c16X);
c128R=yToRow(c128Y);
c128C=xToCol(c128X);
data.currentZoom128_x=min(colToX(data.dataStructure.origSize(1))-c128W+1,max(.5,c16X-c128W/2));
data.currentZoom128_y=min(rowToY(data.dataStructure.origSize(2))-c128H+1,max(.5,c16Y-c128H/2));
[regionalMaxes16,WC16,EC16,NR16,SR16]=shiftZoom16Frame(data.blueSlice,c16R, c16C,c16H,c16W);
data.currentZoom16_nSpots=sum(regionalMaxes16(:)>0);
set(data.nSpots_txt,'String',[num2str(data.currentZoom16_nSpots) ' spots in view']);
guidata(currhandle,data);
displayImFull(currhandle,data,1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function outstr=outOf(str,i,j)
outstr=[str ' ' num2str(i) '/' num2str(j)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function displayImFull(hObject,handles,calculateMaxima)
data=guidata(hObject);
%fprintf([num2str(sum((data.blueSlice(:))>0)) ' regional maxima in slice ' num2str(data.currentZ) '\n']);
set(data.z_pos_txt,'String',outOf('slice', data.currentZ,data.dataStructure.origSize(3)));
%set(data.x16_txt,'String',['x16: ' num2str(data.currentZoom16_x)]);
%set(data.y16_txt,'String',['y16: ' num2str(data.currentZoom16_y)]);
%set(data.x128_txt,'String',['x128: ' num2str(data.currentZoom128_x)]);
%set(data.y128_txt,'String',['y128: ' num2str(data.currentZoom128_y)]);
%iCurrentWorm=data.sliceSortedSpotData.wormNumber(data.blueSpotRankList(data.iCurrentSpot));
%iCurrentSpotInWorms=data.sliceSortedSpotData.spotInfoNumberInWorm(data.blueSpotRankList(data.iCurrentSpot));
%set(data.iWormiSpot_txt,'String',['Spot:' num2str(iCurrentSpotInWorms)]);
%set(data.scdValue_txt,'String',['scd: ' num2str(data.worms{iCurrentWorm}.spotInfo{iCurrentSpotInWorms}.stat.statValues.scd)]);
set(data.NregionalMaximaLeftInSlice_txt,'String',[num2str(length(data.blueSpotRankList)) ' regional maxima left']);
%%
%%%%%%%%%%%%%%%%%%%%%%%%
%check to make sure that currentSpotRank is not greater than the number of
%maxima in the slice
set(data.spotRankSlider,'Min',data.blueSpotRankList(1));
set(data.spotRankSlider,'Max',data.blueSpotRankList(end));
sliderStep=1/(data.blueSpotRankList(end)-data.blueSpotRankList(1));
if ~isinf(sliderStep)
set(data.spotRankSlider,'SliderStep',[sliderStep 5*sliderStep]);
else
set(data.spotRankSlider,'SliderStep',[0 1]);
end;
set(data.spotRankSlider,'Value',data.blueSpotRankList(data.iCurrentSpot));
set(data.spotRankReporter_txt,'String',['Spot Rank: ' num2str(data.blueSpotRankList(data.iCurrentSpot))]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
if data.highMemory
currentSlice=data.dataStructure.scaledStack(:,:,handles.currentZ);
else
currentSlice=data.dataStructure.scaledSlice;
end;
%get the zoom128 size
data.currentZoom128_width=round(get(data.zoom128_slider,'Value'));
data.currentZoom128_height=round(get(data.zoom128_slider,'Value'));
set(handles.zoom128_slider_txt,'String',['Zoom size (pixels): ' num2str(round(get(handles.zoom128_slider,'Value')))]);
c16X=data.currentZoom16_x;
c16Y=data.currentZoom16_y;
c16W=data.currentZoom16_width;
c16H=data.currentZoom16_height;
centerXY=[c16X+floor(c16H/2) c16Y+floor(c16W/2)];
c128W=data.currentZoom128_width;
c128H=data.currentZoom128_height;
c128X=min(max(1,centerXY(1)-floor(c128W/2)),size(currentSlice,2)-(c128W-1));
c128Y=min(max(1,centerXY(2)-floor(c128H/2)),size(currentSlice,1)-(c128H-1));
% c128X=data.currentZoom128_x;
% c128Y=data.currentZoom128_y;
c16R=yToRow(c16Y);
c16C=xToCol(c16X);
c128R=yToRow(c128Y);
c128C=xToCol(c128X);
%i need an argument to tell it whether to recalculate regional maxima or
%not...yes when i move, no when i toggle maxima
%if data.highMemory
set(data.figure_handle,'CurrentAxes',data.fullImage);
%fullColor=cat(3,currentSlice,currentSlice.*(~data.dataStructure.segMasks),currentSlice.*(~data.dataStructure.segMasks));
h=size(data.dataStructure.scaledStack,3);
%fullImage=max(data.dataStructure.scaledStack(:,:,floor(h/5):ceil(h*4/5)),[],3);
%mxFullImage=max(fullImage(fullImage~=0));
%mnFullImage=min(fullImage(fullImage~=0));
%rangeImage=mxFullImage-mnFullImage;
%fullImage(fullImage~=0)=(fullImage(fullImage~=0)-mnFullImage)/rangeImage;
%fullImage=imscale(fullImage);
data.fullImage=imshow(max(data.dataStructure.scaledStack(:,:,max(handles.currentZ-1,1):min(handles.currentZ+1,h)),[],3));
colormap(gray);
axis off
title('Max. Merged Image')
%note that rectangle x,y is axes (spatial) coordinate.
%it doesn't work the same way with an axes created by "plot" as an axes
%created by "imshow"...for imshow, the NW corner is (.5, .5) for plot, SW
%corner is (0,0)
rectangle('Position',[c128X, c128Y, c128W,c128H],'EdgeColor',[.8 .4 .8]);
rectangle('Position',[c16X, c16Y, c16W,c16H],'EdgeColor',[0 .85 0]);
%end;
set(data.figure_handle,'CurrentAxes',data.zoom16);
rgSlice=currentSlice.*(~data.blueSlice)+.5*data.blueSlice;
color16=cat(3,rgSlice,rgSlice.*(~data.confirmedSlice),(currentSlice).*(~data.confirmedSlice)-data.bkgd);
data.zoom16=imshow(color16);
origXLim=get(gca,'XLim'); origWidth=origXLim(2)-origXLim(1);
origYLim=get(gca,'YLim'); origHeight=origYLim(2)-origYLim(1);
zoomFactorX=origWidth/data.currentZoom16_width;
zoomFactorY=origHeight/data.currentZoom16_height;
zoomFactor=min(zoomFactorX,zoomFactorY);
data.zoom16Factor=zoomFactor;
zoom(data.zoom16Factor);
%the integer is in the middle of the square, so this needs to be -.5
xlim(get(data.figure_handle,'CurrentAxes'),[c16X c16X+c16W]);
ylim([c16Y c16Y+c16H]);
if data.highMemory
[~,WC16,EC16,NR16,SR16]=shiftZoom16Frame(data.dataStructure.scaledStack,c16R, c16C,c16H,c16W);
zoom16Column=data.dataStructure.scaledStack(NR16:SR16,WC16:EC16,:);
for i=1:5
if data.currentZ+(i-3)<=data.dataStructure.origSize(3) && data.currentZ+(i-3)>=1
surf(data.surfPlots{i},zoom16Column(:,:,data.currentZ+(i-3)));
end;
set(data.surfPlots{i},'YDir','reverse','XTick',[],'ZLim',[0 1],'YTick',[],'ZTick',[],'Visible','off','Color',get(data.figure_handle,'Color'));
end;
end;
set(data.figure_handle,'CurrentAxes',data.zoom128);
color128=cat(3,currentSlice+.2*data.dataStructure.outlines,currentSlice+.2*data.dataStructure.outlines,currentSlice-data.bkgd*.3);
data.zoom128=imshow(color128);
origXLim=get(gca,'XLim'); origWidth=origXLim(2)-origXLim(1);
origYLim=get(gca,'YLim'); origHeight=origYLim(2)-origYLim(1);
zoomFactorX=origWidth/c128W;
zoomFactorY=origHeight/c128H;
zoomFactor=min(zoomFactorX,zoomFactorY);
data.zoom128Factor=zoomFactor;
zoom(data.zoom128Factor);
xlim([c128X c128X+c128W]);
ylim([c128Y c128Y+c128H]);
rectColor=min(1,3*median(currentSlice(:)));
if get(data.greenBox_checkBox,'Value')
rectangle('Position',[c16X, c16Y, c16W,c16H],'EdgeColor',[rectColor/3 .8 rectColor/2],'LineWidth',.5);
end;
set(data.rejectedNSpots_txt,'String',[num2str(size(handles.dataStructure.rejectedSpots,1)),' rejected spots']);%handles
set(data.acceptedNSpots_txt,'String',[num2str(size(handles.dataStructure.goodSpots,1)),' accepted spots']);%handles
%this is the function that will record the center of the spot
set(data.zoom16,'ButtonDownFcn',@zoom16_ButtonDownFcn);
%this function will move the focus to a new place
set(data.zoom128,'ButtonDownFcn',@zoom128_ButtonDownFcn);
%guidata(hObject,data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Outputs from this function are returned to the command line.
function varargout = identifySpots_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;
%Before passing these back, tack on the worms locations using the
% handles.spotIndicesInWormsSorted
% handles.spotListSorted
spotListSorted=handles.sortedSpotData.xyz;
if size(handles.dataStructure.goodSpots,2)>0
[~,ispotListGood,igood]=intersect(spotListSorted,handles.dataStructure.goodSpots,'rows');
goodSpotInfoInformation=[handles.sortedSpotData.wormNumber(ispotListGood) handles.sortedSpotData.spotInfoNumberInWorm(ispotListGood)];
goodSpotValueInformation=handles.sortedSpotData.values(ispotListGood);
%Note that the below works because spots and rejected spots are a proper
%subset of all the candidates in spotListSorted(:,1:3)
handles.dataStructure.goodSpots=[handles.dataStructure.goodSpots(igood,:) goodSpotValueInformation goodSpotInfoInformation];
end;
if size(handles.dataStructure.rejectedSpots,2)>0
[~,ispotListRej,irej]=intersect(spotListSorted,handles.dataStructure.rejectedSpots,'rows');
rejectedSpotInfoInformation=[handles.sortedSpotData.wormNumber(ispotListRej) handles.sortedSpotData.spotInfoNumberInWorm(ispotListRej)];
rejectedSpotValueInformation=handles.sortedSpotData.values(ispotListRej);
%Note that the below works because spots and rejected spots are a proper
%subset of all the candidates in spotListSorted(:,1:3)
handles.dataStructure.rejectedSpots=[handles.dataStructure.rejectedSpots(irej,:) rejectedSpotValueInformation rejectedSpotInfoInformation];
end;
varargout{1} = handles.dataStructure.goodSpots;
varargout{2} = handles.dataStructure.rejectedSpots;
% Get the current position of the GUI from the handles structure
% to pass to the modal dialog.
pos_size = get(handles.figure1,'Position');
% Call modaldlg with the argument 'Position'.
%user_response = modaldlg('Title','If you are finished shall I close the GUI window?');
user_response = modaldlg('Title','Do another worm if possible?');
switch user_response
case {'No'}
% take no action
varargout{3}=0;
case 'Yes'
% Prepare to close GUI application window
% .
% .
% .
varargout{3}=1;
delete(handles.figure1)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in nextAccept_button.
function nextAccept_button_Callback(hObject, eventdata, handles)
% hObject handle to nextAccept_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%This function takes the blue pixels in the zoom16 window and adds them to
%good spots and then removes them from blueSlice and blueSpots and
%blueSpotRankList
%data=guidata(handles);
handles.lastHandles=handles;
if handles.highMemory
handles.lastHandles.dataStructure=rmfield(handles.lastHandles.dataStructure,'scaledStack');
else
handles.lastHandles.dataStructure=rmfield(handles.lastHandles.dataStructure,'scaledSlice');
end;
handles=resetLastHandles(handles,handles.rollbackDepth,0);
c16X=handles.currentZoom16_x;
c16Y=handles.currentZoom16_y;
c16W=handles.currentZoom16_width;
c16H=handles.currentZoom16_height;
c128X=handles.currentZoom128_x;
c128Y=handles.currentZoom128_y;
c128W=handles.currentZoom128_width;
c128H=handles.currentZoom128_height;
c16R=yToRow(c16Y);
c16C=xToCol(c16X);
c128R=yToRow(c128Y);
c128C=xToCol(c128X);
newSpots=getZoom16Spots(c16R,c16H,c16C,c16W,handles.blueSlice,handles.currentZ);
handles.dataStructure.goodSpots=[handles.dataStructure.goodSpots; newSpots];
set(handles.acceptedNSpots_txt,'String',[num2str(size(handles.dataStructure.goodSpots,1)),' accepted spots']);
%remove from blueSpots
[handles.blueSpots,handles.blueSpotRankList,handles.iCurrentSpot]=removeZoom16SpotsFromBlueSpotsAndUpdateCurrentSpotIndex(newSpots,handles.blueSpots,handles.blueSpotRankList,handles.iCurrentSpot);
%now transfer the spots from blueSlice to confirmedSlice and erase from
%blueSlice - why erase from blueSlice? - so don't go back to it
[~,WC16,EC16,NR16,SR16]=shiftZoom16Frame(handles.blueSlice,c16R, c16C,c16H,c16W);
handles.confirmedSlice(NR16:SR16,WC16:EC16)=handles.blueSlice(NR16:SR16,WC16:EC16);
handles.blueSlice(NR16:SR16,WC16:EC16)=zeros(c16H,c16W);
%moves the 16 square along
[c16X,c16Y,c16R,c16C,handles.blueSlice,handles.confirmedSlice,handles.currentZ,didTopSlice,handles.blueSpots,handles.iCurrentSpot,handles.blueSpotRankList,handles.bkgd,handles.sortedSpotData.scaledValues,handles.sliceSortedSpotData,handles.dataStructure.scaledSlice]=moveZoom16(c16X,c16Y,c16W,c16H,c128X,c128Y,c128W,c128H,handles);
if didTopSlice==1
uiresume(gcbf);%this should jump back right after uiwait
end;