-
Notifications
You must be signed in to change notification settings - Fork 0
/
O_GUI_6.m
1914 lines (1597 loc) · 72.7 KB
/
O_GUI_6.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 = O_GUI_6(varargin)
% O_GUI_6 MATLAB code for O_GUI_6.fig
% O_GUI_6, by itself, creates a new O_GUI_6 or raises the existing
% singleton*.
%
% H = O_GUI_6 returns the handle to a new O_GUI_6 or the handle to
% the existing singleton*.
%
% O_GUI_6('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in O_GUI_6.M with the given input arguments.
%
% O_GUI_6('Property','Value',...) creates a new O_GUI_6 or raises the
% existing singleton*.
%Starting from the left, property value pairs are
% applied to the GUI before O_GUI_6_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to O_GUI_6_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 O_GUI_6
%
% Last Modified by GUIDE v2.5 13-Aug-2016 21:05:09
%
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @O_GUI_6_OpeningFcn, ...
'gui_OutputFcn', @O_GUI_6_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 O_GUI_6 is made visible.
function O_GUI_6_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 O_GUI_6 (see VARARGIN)
% Choose default command line output for O_GUI_6
handles.output = hObject;
% Shixuan: Setting Default Parameters
handles.O.selectImage = 0; % identify whether a image has been selected; 0 mean no image
handles.O.IsExcel = 0;
handles.O.IsExcel = 0;
handles.O.OutputDir = '\\carbon.research.sickkids.ca\rkafri\OPRETTA\Operetta Processed OutPutFiles\';
% Update handles structure
set(handles.MaxSize,'SliderStep',[0.001 0.01])
warning off
addpath('\\carbon.research.sickkids.ca\rkafri\MATLAB\General Tools')
figure(900)
imagesc(1)
colormap gray
set(handles.Dataset_selection,'BackgroundColor',[0.8 0.8 0]); % the yellow road
figure(999);
handles.Image_Display=gca;
handles.O.Display_Mode='Regular';
set(handles.Image_Display,'visible','on')
% GETTING THE SPOT CELLS
LS=dir('O_SpotCells*');
LS=struct2cell(LS);
LS=LS(1,:)';
set(handles.Spotting_algorithm,'string',LS)
handles.O.Spotting_alg='O_SpotCells';
handles.O.Watershed_not_calculated=false(1,4);
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = O_GUI_6_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;
% Kafri: prepare the visual GUI
figure(999); set(gca,'xtick',[],'ytick',[])
figure(998); set(gca,'xtick',[],'ytick',[])
% Kafri: populate the popup menue based on default excel file
DataSetDescriptionFile=get(handles.Excell_sheet_location,'String');
[~,~,raw]=xlsread(DataSetDescriptionFile,'General_Info');
GlobalDirName=raw{1,2};
FlatFieldDirName=raw{3,2};
[rrr,txt,rr]=xlsread(DataSetDescriptionFile,'DataSet_List');
rr=rr(1:1+length(rrr(:,1)),1:17);
T=cell2table(rr(2:end,:),'variablenames',rr(1,:));
Number_Of_datasets=size(txt,1);
List_of_datasets=T.Dataset_name;
set(handles.Dataset_selection,'String',List_of_datasets)
DDD=dir('\\carbon.research.sickkids.ca\rkafri\OPRETTA\FlatFieldFiles');
counter=0;
for i=3:length(DDD)
if ~isempty(regexp(DDD(i).name,'.mat'))
counter=counter+1;
LS{counter}=DDD(i).name;
LSd(counter)=DDD(i).datenum;
end
end
[srt,srti]=sort(LSd,'descend');
set(handles.Flat_Field_selection,'String',LS)
set(handles.Flat_Field_selection,'value',1)
contents = cellstr(get(handles.Flat_Field_selection,'String'));
FileName=contents{get(handles.Flat_Field_selection,'Value')};
load(['\\carbon.research.sickkids.ca\rkafri\OPRETTA\FlatFieldFiles\' FileName]);
handles.O.flat.Multipicative_Biase=Multipicative_Biase;
handles.O.flat.FileName=['\\carbon.research.sickkids.ca\rkafri\OPRETTA\FlatFieldFiles\' FileName];
% handles.O.flat.Additive_Biase=Additive_Biase;
guidata(hObject, handles);
XLS=T;
handles.O.XLS=XLS;
handles.O.GlobalDirName=GlobalDirName;
handles.O.IsExcel=1;
handles.O.CurrentTimePoint=1;
handles.O.FlatFieldDirName=FlatFieldDirName;
handles.O.Excell_Sheet_Location=DataSetDescriptionFile;
Selected_dataset=get(handles.Dataset_selection,'value');
handles.O.Magnification=handles.O.XLS.magnification(Selected_dataset);
handles.O.Smoothing_alpha_max_width=handles.O.Magnification;
figure(999)
handles.O.SegmentedImage.CorruptRegion=[];
% axis off
% axes(handles.axes2)
axis off
figure(998)
axis off
% axes(handles.line_scan_2)
axis off
handles.O.SegmentedImage.BW_spots=[];
smoothing_alpha=zeros(4,1);Intensity_thr=zeros(4,1);
Min_Area=ones(4,1)*100; Max_Area=ones(4,1)*1e9;
CloseW=ones(4,1); OpenW=ones(4,1); Seed=[false ; false ; false ; false];
Watershed=[false ; false ; false ; false];
Name={' ',' ',' ',' '}';Label={' ',' ',' ',' '}';
handles.O.General_Thresholds=table(Name,Label,smoothing_alpha,Intensity_thr,Min_Area,Max_Area,CloseW,OpenW,Seed,Watershed);
guidata(hObject,handles)
set(handles.uitable3,'ColumnEditable',[false true true true true true true true true true]);
set(handles.uitable3,'ColumnFormat',{'char',{'Nucleus' 'Cell' 'Other' 'Non'},'numeric','numeric','numeric','numeric','numeric','numeric','logical','logical'});
set(handles.uitable3,'ColumnName',{'Name' 'Label' 'smoothing' 'Threshold' 'Min Area' 'Max Area' 'Close W' 'Open W' 'Seed' 'Watershed'});
%% Kafri: docking the figure
% set(handles.figure1,'windowstyle','docked');
% --- pushbutton: SAVE button ---% Shixuan: save parameters to excel file
function save_parameters_button_Callback(~, eventdata, handles)
% hObject handle to save_parameters_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%ImageIDs=handles.O.ImageIDs; %DirName=handles.O.DirName;
Spotting_Choice=find(handles.O.General_Thresholds.Seed);
if isempty(Spotting_Choice)
clc
disp('WARNING: NO SEEDS!!')
YN=input('OK? (yes/no)','s');
if strcmpi(YN,'no')
return
end
end
Nuclear_Channel=find(strcmp(handles.O.General_Thresholds.Label,'Nucleus'));
if isempty(Nuclear_Channel)
clc
disp('WARNING: NO Nucleus!!')
YN=input('OK? (yes/no)','s');
if strcmpi(YN,'no')
return
end
end
Cytoplasmic_Channel=find(strcmp(handles.O.General_Thresholds.Label,'Cell'));
if isempty(Cytoplasmic_Channel)
clc
disp('WARNING: NO Cell!!')
YN=input('OK? (yes/no)','s');
if strcmpi(YN,'no')
return
end
end
ImageIDs=handles.O.ImageIDs;
SegmentationParameters.NumRows=handles.O.NumRows;
SegmentationParameters.NumColumns=handles.O.NumColumns;
SegmentationParameters.magnification=handles.O.Magnification;
SegmentationParameters.DirName=[handles.O.DirName '\Images'];
SegmentationParameters.FlatField_Correction=get(handles.FlatField_Correction,'value');
SegmentationParameters.OutputDir=handles.O.OutputDir;
SegmentationParameters.DataSetName=handles.O.DataSetName;
SegmentationParameters.FlatFileName=handles.O.flat.FileName;
SegmentationParameters.Regional_Thresholding=0;
handles.O.SegmentationParameters=SegmentationParameters;
handles.O.FlatField_Correction=get(handles.FlatField_Correction,'value');
General_Thresholds=handles.O.General_Thresholds;
if ~isdir([SegmentationParameters.OutputDir 'Dataset_' regexprep(SegmentationParameters.DataSetName,'\W','_') 'RESULTS'])
mkdir([SegmentationParameters.OutputDir 'Dataset_' regexprep(SegmentationParameters.DataSetName,'\W','_') 'RESULTS'])
end
FileName=handles.SegmentationParameters_file_name.String;
Data.O=rmfield(handles.O,{'BW','WS','IM','BW_spots','Original_IM','XLS'});
save([SegmentationParameters.OutputDir 'Dataset_' regexprep(SegmentationParameters.DataSetName,'\W','_') 'RESULTS\SegPar_' FileName],'Data');
clc
disp([SegmentationParameters.OutputDir 'Dataset_' regexprep(SegmentationParameters.DataSetName,'\W','_') 'RESULTS\SegPar_' FileName])
winopen([SegmentationParameters.OutputDir 'Dataset_' regexprep(SegmentationParameters.DataSetName,'\W','_') 'RESULTS\'])
% --- Excell_sheet_location: excel File Directory ---% in case user use other excel file as input
function Excell_sheet_location_Callback(hObject, eventdata, handles)
% hObject handle to Excell_sheet_location (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 Excell_sheet_location as text
% str2double(get(hObject,'String')) returns contents of Excell_sheet_location as a double
set(handles.figure1,'color',[1 0 0 ])
InputDir=get(hObject,'String');
% TEST IF FILE EXISTS
if (exist(InputDir, 'file') == 2 && ~isempty(regexp(InputDir,'.xls', 'once'))) % excel file exist
DataSetDescriptionFile=get(handles.Excell_sheet_location,'String');
[~,~,raw]=xlsread(DescriptionFile,'General_Info');
GlobalDirName=raw{1,2};
FlatFieldDirName=raw{3,2};
[~,txt,~]=xlsread(DataSetDescriptionFile,'DataSet_List');
Number_Of_datasets=size(txt,1);
List_of_datasets=txt(2:Number_Of_datasets,1);
set(handles.Dataset_selection,'String',List_of_datasets)
for i=1:length(txt(1,:))
VarNames(i)=regexprep(txt(1,i),' ','_');
end
XLS=cell2table(txt(2:end,:),'variablenames',VarNames);
handles.O.XLS=XLS;
handles.O.GlobalDirName=GlobalDirName;
handles.O.IsExcel=1;
handles.O.FlatFieldDirName=FlatFieldDirName;
else % file doesn't exist OR not excel file
handles.O.IsExcel=0;
figure(999); cla
axes(handles.axes2); cla
figure(998); cla
end
handles.O.DataSetName = handles.O.XLS.Dataset_name{get(handles.Dataset_selection,'value')};
guidata(hObject,handles)
set(handles.figure1,'color',[0.9 0.9 0.9])
function Excell_sheet_location_CreateFcn(hObject, eventdata, handles)
% hObject handle to Excell_sheet_location (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
% --- Dataset_selection: Image Folder ---
function [handles]=Dataset_selection_Callback(hObject, eventdata, handles)
% hObject handle to Dataset_selection (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 Dataset_selection contents as cell array
% contents{get(hObject,'Value')} returns selected item from Dataset_selection
% Kafri: select a dataset from excell sheet
handles.O.Display_Mode='Regular';
set(handles.Display_Channal,'value',1)
set(handles.InspectedProperty,'value',1)
figure(900)
cla
set(handles.Image_selection,'BackgroundColor',[1 1 1])
Dataset_num=get(handles.Dataset_selection,'value');
handles.O.FileType=handles.O.XLS.FileType{Dataset_num};
if handles.O.IsExcel==1
figure(999)
axis on
cla
set(gca,'xlim',[0.5 1360.5])
set(gca,'ylim',[0.5 1024.5])
set(gca,'color','k')
text(100,200,'LOADING . . . ','fontsize',30,'color','r')
text(100,300,'PLEASE WAIT !!!!','fontsize',30,'color','r')
pause(0.1)
GlobalDirName=handles.O.GlobalDirName;
XLS=handles.O.XLS;
DatasetID=Dataset_num;
LocalDir=XLS.directory{DatasetID};
if isempty(regexp(LocalDir,'\\'))
DirName=[GlobalDirName '\' LocalDir];
else
DirName=LocalDir;
end
handles.O.DirName=DirName;
% Kafri populate the PlateMap
set(handles.Image_selection,'value',1)
if ~isdir(DirName) % if directory DOES NOT exist
% Clear the Listbox
set(handles.Image_selection,'String',{'non'})
handles.O.IsExcel=0;
figure(999)
axis on
cla
set(gca,'xlim',[0.5 1360.5])
set(gca,'ylim',[0.5 1024.5])
set(gca,'color','k')
text(100,200,'big problem !! . . . ','fontsize',30,'color','r')
text(100,300,'DIRECTORY DOES NOT EXIST !!!!','fontsize',30,'color','r')
pause(20)
% axes(handles.axes2); cla
figure(998); cla
else % if directory DOES exist
handles.O.IsExcel=1;
% WAIT MESSEGE
figure(999)
axis on
cla
set(gca,'xlim',[0.5 1360.5])
set(gca,'ylim',[0.5 1024.5])
set(gca,'color','k')
text(100,200,'LOADING . . . ','fontsize',30,'color','r')
text(100,300,'PLEASE WAIT !!!!','fontsize',30,'color','r')
drawnow
% END OF WAIT MESSEGE
[ImageIDs,BaseName,NumberLengths]=O_retrieve_names_v2(DirName,handles.O.XLS.FileType{DatasetID});
% if strcmp(XLS{94,2},'Operetta') && strcmp(ImageIDs.Properties.VariableNames(11),'Drug_treatment')
% ImageIDs.Properties.VariableNames{11}='Compound';
% end
% if strcmp(XLS{94,2},'Operetta') && strcmp(ImageIDs.Properties.VariableNames(12),'Drug_washout')
% ImageIDs.Properties.VariableNames{12}='Concentration';
% end
% if strcmp(XLS{94,2},'Operetta') && size(ImageIDs,2)==13
% ImageIDs.Cell_Count=char.empty(size(ImageIDs,1),0);
% end
handles.O.Image_Retrieval_data.Image_File_Base_Name=BaseName;
handles.O.Image_Retrieval_data.NumberLengths=NumberLengths;
handles.O.PlateType=handles.O.XLS.PlateSize(DatasetID);
handles.O.ImagedChannels=unique(ImageIDs.Channel);
if any(ismember(ImageIDs.Properties.VariableNames,'ch_name'))
[unq,iunq]=unique(ImageIDs.Channel);
handles.O.Image_Retrieval_data.ch_names=ImageIDs.ch_name(iunq);
ImageIDs.ch_name=[];
end
% DETERMINE IF IT IS A 96 OR 384 WELL PLATE
if handles.O.PlateType==384
handles.O.NumColumns=24;
handles.O.NumRows=16;
elseif handles.O.PlateType==96
handles.O.NumColumns=12;
handles.O.NumRows=8;
elseif handles.O.PlateType==1
handles.O.NumColumns=1;
handles.O.NumRows=1;
end
handles.O.Channels = [XLS.color_1(DatasetID) XLS.color_2(DatasetID) XLS.color_3(DatasetID) XLS.color_4(DatasetID)];
set(handles.Display_Channal,'String',[handles.O.Channels(handles.O.ImagedChannels)])
handles.O.ImageIDs=ImageIDs;
[handles]=Select_Plate_Region(hObject,handles,ImageIDs);
end
handles.O.selectImage = 0;
% write down the channel lables
guidata(hObject,handles)
end
figure(999);cla
set(gca,'color','w')
pause(0.1)
set(handles.Time_Scale_Slider,'Min',1,'Max',max(ImageIDs.Time),'Value',1)
handles.O.CurrentTimePoint=1;
if strcmpi(handles.O.XLS.FileType{DatasetID},'Operetta')
Plot_plate_map(handles)
end
handles.O.DataSetName = handles.O.XLS.Dataset_name{get(handles.Dataset_selection,'value')};
set(handles.Dataset_selection,'BackgroundColor',[1 1 1])
set(handles.Image_selection,'BackgroundColor',[0.8 0.8 0]);
% INITIALIZING GENERAL THRESHOLDS
smoothing_alpha=zeros(4,1);Intensity_thr=zeros(4,1);
Min_Area=ones(4,1)*100; Max_Area=ones(4,1)*1e9;
CloseW=ones(4,1); OpenW=ones(4,1); Seed=[false ; false ; false ; false];
Watershed=[false ; false ; false ; false];
Name={' ',' ',' ',' '}';Label={' ',' ',' ',' '}';
handles.O.General_Thresholds=table(Name,Label,smoothing_alpha,Intensity_thr,Min_Area,Max_Area,CloseW,OpenW,Seed,Watershed);
handles.O.General_Thresholds.Label={'Non' 'Non' 'Non' 'Non'}';
handles.O.General_Thresholds.Name={'' '' '' ''}';
handles.O.General_Thresholds.Seed=false(4,1);
handles.O.General_Thresholds.CloseW=zeros(4,1);
handles.O.General_Thresholds.OpenW=zeros(4,1);
handles.O.General_Thresholds.Intensity_thr=zeros(4,1);
handles.O.General_Thresholds.Max_Area=zeros(4,1);
handles.O.General_Thresholds.Min_Area=zeros(4,1);
handles.O.General_Thresholds.smoothing_alpha=zeros(4,1);
for i=1:size(handles.O.General_Thresholds,1)
eval(['str=handles.O.XLS.color_' num2str(i) '(' num2str(DatasetID) ');'])
if iscell(str)
Labels{i}=str{1};
else
Labels{i}='None';
end
end
Labels=Labels';
handles.O.General_Thresholds.Name=Labels;
% TRIMMING GENERAL THRESHOLDS TABLE TO INCLUDE ONLY IMAGED CHANNALS
handles.O.General_Thresholds=handles.O.General_Thresholds(handles.O.ImagedChannels,:);
handles.O.MaxInt=ones(size(handles.O.ImagedChannels))*NaN;
% REMOVING THE CH BUTTONS FOR NON-IMAGED CHANNALS
for i=1:4
if ismember(i,handles.O.ImagedChannels)
eval(['set(handles.ch' num2str(i) ',''string'',Labels{' num2str(i) '})'])
eval(['set(handles.ch' num2str(i) ',''visible'',''on'')'])
else
eval(['set(handles.ch' num2str(i) ',''visible'',''off'')'])
end
end
set(handles.uitable3,'data',table2cell(handles.O.General_Thresholds))
set(handles.uitable3,'data',handles.uitable3.Data(handles.O.ImagedChannels,:))
set(handles.ColorDisp,'visible','off')
set(handles.InspectedProperty,'visible','off')
if max(ImageIDs.Time)==1
set(handles.Time_Scale_Slider,'visible','off')
set(handles.text28,'visible','off')
else
set(handles.Time_Scale_Slider,'visible','on')
set(handles.text28,'visible','on')
end
for ch=handles.O.ImagedChannels'
handles.O.SeedChoice{ch}='';
end
[handles]=O_Update_GUI(handles);
[handles]=O_Update_General_Thresholds(hObject,handles);
guidata(hObject,handles)
function []=Plot_plate_map(handles)
Dataset_num=get(handles.Dataset_selection,'value');
if strcmpi(handles.O.FileType,'Operetta')
% PLOT PLATE MAP
figure(900)
hold off
[X,Y]=meshgrid(1:handles.O.NumRows,1:handles.O.NumColumns);
Rows=X(:);
Columns=Y(:);
% column goes to 12 row goes to 8
RelevantWells=unique([handles.O.ImageIDs.Row handles.O.ImageIDs.Column],'rows');
alpha=handles.O.NumColumns/12;
scatter(Columns,Rows,60/alpha,'b');
set(gca,'ydir','reverse')
hold on
scatter(RelevantWells(:,2),RelevantWells(:,1),60/alpha,'g','filled');
if isfield(handles,'ImageID')
scatter(handles.O.ImageID(2),handles.O.ImageID(1),150/alpha,'r','linewidth',4);
end
set(gca,'xtick',1:handles.O.NumColumns)
set(gca,'ytick',1:handles.O.NumRows,'yticklabel',{'A','B','C','D','E','F','G','H'})
set(gca,'fontsize',6/alpha)
axis([0 handles.O.NumColumns+1 0 handles.O.NumRows+1])
% set(gcf,'color',[0 0 0 ])
set(gca,'color',[0 0 0 ])
end
function Dataset_selection_CreateFcn(hObject, eventdata, handles)
% hObject handle to Dataset_selection (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
% guitable
function thrCheck_Callback(hObject, eventdata,handles)
% eventdata.Indices;
% eventdata.NewData;
Imaged_ch=handles.O.ImagedChannels;
data=get(hObject,'Data'); % get the data cell array of the table
cols=get(hObject,'ColumnFormat'); % get the column formats
SelectedVarID=eventdata.Indices(1,2);
Selected_variable=hObject.ColumnName{SelectedVarID};
L=size(handles.O.General_Thresholds,1);
switch Selected_variable
case 'Seed'
handles.O.General_Thresholds.Seed(Imaged_ch)=false(length(Imaged_ch),1);
handles.O.General_Thresholds.Seed(eventdata.Indices(1,1))=eventdata.NewData;
data(:,SelectedVarID)=mat2cell(handles.O.General_Thresholds.Seed,true(1,L));
set(hObject,'Data',data)
set(handles.OperationLabel,'string','Thresholding','fontsize',12)
set(handles.OperationLabel,'backgroundcolor','b')
handles.O.Watershed_not_calculated=true(1,4);
case 'Watershed'
handles.O.General_Thresholds.Watershed(Imaged_ch)=false(length(Imaged_ch),1);
handles.O.General_Thresholds.Watershed(eventdata.Indices(1,1))=eventdata.NewData;
data(:,SelectedVarID)=mat2cell(handles.O.General_Thresholds.Watershed,true(1,L));
set(hObject,'Data',data)
case 'Label'
if ~strcmp(eventdata.NewData,'Non')
ii=strcmp(handles.O.General_Thresholds.Label,eventdata.NewData);
if any(ii)
handles.O.General_Thresholds.Label{ii}='Non';
end
end
handles.O.General_Thresholds{eventdata.Indices(1,1),eventdata.Indices(1,2)}={eventdata.NewData};
handles.O.Watershed_not_calculated=true(1,4);
otherwise
handles.O.General_Thresholds{eventdata.Indices(1,1),eventdata.Indices(1,2)}=eventdata.NewData;
end
[handles]=O_Update_GUI(handles);
[handles]=O_Update_General_Thresholds(hObject,handles);
% --- Image_selection: list the images in the directory---
function Image_selection_Callback(hObject, eventdata, handles)
% hObject handle to Image_selection (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 Image_selection contents as cell array
% contents{get(hObject,'Value')} returns selected item from Image_selection
Dataset_num=get(handles.Dataset_selection,'value');
handles.O.FileType=handles.O.XLS.FileType{Dataset_num};
if handles.O.IsExcel==1 && handles.O.IsExcel ==1
drawnow
handles.O.selectImage = 1;
ID=get(hObject,'Value');
handles.O.ImageID=handles.O.ActivePlateListNumbers(ID,:);
[handles]=O_LoadImages_Internal(hObject,handles);
guidata(hObject,handles)
[handles]=O_Threshold_and_Display(hObject,handles);
% [handles]=DisplayImage(hObject,handles);
Plot_plate_map(handles)
set(handles.Image_selection,'BackgroundColor',[1 1 1])
end
function Image_selection_CreateFcn(hObject, eventdata, handles)
% hObject handle to Image_selection (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
% --- smoothing_slider: Smooth Factor------
function smoothing_slider_Callback(hObject, eventdata, handles)
% hObject handle to smoothing_slider (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
if handles.O.IsExcel==1 && handles.O.IsExcel ==1 && handles.O.selectImage == 1
handles.O.Display_Mode='Regular';
set(handles.OperationLabel,'string','SEEDS','fontsize',15)
set(handles.OperationLabel,'BackgroundColor','g','FontWeight','bold','ForegroundColor','w')
[handles]=O_Update_General_Thresholds(hObject,handles);
[handles]=O_Spot_Image(hObject,handles);
end
function smoothing_slider_CreateFcn(hObject, eventdata, handles)
% hObject handle to smoothing_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Threshold: Threshold for Nuclear Mask ---
function Threshold_Callback(hObject, eventdata, handles)
% hObject handle to Threshold (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% IF WE "JUST" IDENTIFIED SEEDS WE NEED TO WATERSHED
ch=get(handles.Display_Channal,'value');
Seed_ch=find(handles.O.General_Thresholds.Seed);
thr=get(hObject,'Value');
handles.O.General_Thresholds.Intensity_thr(ch)=thr;
handles.O.Display_Mode='Regular';
guidata(hObject,handles)
set(handles.OperationLabel,'string','Thresholding','fontsize',12)
set(handles.OperationLabel,'backgroundcolor','b')
[handles]=O_Update_General_Thresholds(hObject,handles);
function Threshold_CreateFcn(hObject, eventdata, handles)
% hObject handle to Threshold (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% function [handles]=O_Threshold_and_Display(hObject,handles)
% ch=get(handles.Display_Channal,'value');
% Nucleus_ch=find(strcmp(handles.O.General_Thresholds.Label,'Nucleus'));
% Cell_ch=find(strcmp(handles.O.General_Thresholds.Label,'Cell'));
% if ~isempty(Nucleus_ch) && ...
% ~isempty(Cell_ch) && ...
% handles.O.General_Thresholds.Intensity_thr(Nucleus_ch)>0 && ...
% handles.O.General_Thresholds.smoothing_alpha(Nucleus_ch)>0 && ...
% isempty(handles.O.BW{Nucleus_ch})
% set(handles.Display_Channal,'value',Nucleus_ch);
% [handles]=O_Threshold_and_Display2(hObject,handles);
% set(handles.Display_Channal,'value',ch);
% end
% [handles]=O_Threshold_and_Display2(hObject,handles);
% --- nuc_border_button: Show/NOT Show nuclear border ---
function nuc_border_button_Callback(hObject, eventdata, handles)
% hObject handle to nuc_border_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of nuc_border_button
if handles.O.selectImage == 1
set(handles.figure1,'color',[0 0 1])
[handles]=O_Segment_and_display_Image(hObject,handles);
set(handles.figure1,'color',[0.9 0.9 0.9])
end
% --- Display_Channal: choose channel for showing ---
function Display_Channal_Callback(hObject, eventdata, handles)
% hObject handle to Display_Channal (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 Display_Channal contents as cell array
% contents{get(hObject,'Value')} returns selected item from Display_Channal
ch=get(hObject,'value');
set(handles.Threshold,'Min',0,'Max',prctile(IM{ch}(:),90))
if get(handles.Threshold,'max')<get(handles.Threshold,'value')
v=get(handles.Threshold,'value');
set(handles.Threshold,'max',v+100)
end
set(handles.figure1,'color',[0 0 1])
[handles]=O_Update_GUI(handles);
[handles]=O_Segment_and_display_Image(hObject,handles);
% [handles]=DisplayImage(hObject,handles);
set(handles.figure1,'color',[0.9 0.9 0.9])
guidata(hObject,handles)
function Display_Channal_CreateFcn(hObject, eventdata, handles)
% hObject handle to Display_Channal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
function [handles]=Select_Plate_Region(hObject,handles,ImageIDs)
Dataset_num=get(handles.Dataset_selection,'value');
T=ImageIDs;
if strcmpi(handles.O.FileType,'Operetta')
T(:,{'Channel','Plate','FileNumber','FileName','FileDate','Color','Compound','Concentration','Cell_Type','Cell_Count'})=[];
else
T(:,{'Channel'})=[];
end
T=unique(T,'rows');
if size(T,1)>100
I=round(linspace(1,size(T,1),100));
T=T(I,:);
end
for counter=1:size(T,1)
for k=1:size(T,2)
txt{k}=[T.Properties.VariableNames{k} ':' num2str(T{counter,k})];
end
PlateList{counter,1}=strjoin(txt);
end
handles.PlateList=PlateList;
handles.O.ActivePlateList=PlateList;
handles.O.PlateListNumbers=T;
handles.O.ActivePlateListNumbers=T;
set(handles.Image_selection,'String',PlateList')
guidata(hObject,handles)
% --- Executes on slider movement.
function Image_contrast_1_Callback(hObject, eventdata, handles)
% hObject handle to Image_contrast_1 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
val=min([get(handles.Image_contrast_1,'value') get(handles.Image_contrast_2,'value')]);
set(handles.Image_contrast_1,'value',val);
[handles]=O_Threshold_and_Display(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Image_contrast_1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Image_contrast_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function Image_contrast_2_Callback(hObject, eventdata, handles)
% hObject handle to Image_contrast_2 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
val=max([get(handles.Image_contrast_1,'value') get(handles.Image_contrast_2,'value')]);
set(handles.Image_contrast_2,'value',val);
[handles]=O_Threshold_and_Display(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Image_contrast_2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Image_contrast_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function slider6_Callback(hObject, eventdata, handles)
% hObject handle to slider6 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.LineScanPos=1-get(hObject,'Value');
guidata(hObject,handles)
if get(handles.DispBG,'value')
[handles]=CalcDark2(hObject, handles);
O_Threshold_and_Display(hObject,handles);
else
O_Threshold_and_Display(hObject,handles);
end
% --- Executes during object creation, after setting all properties.
function slider6_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in Rescale_Intensity.
function Rescale_Intensity_Callback(hObject, eventdata, handles)
% hObject handle to Rescale_Intensity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ch=get(handles.Display_Channal,'value');
figure(999)
hold off
imshow(handles.O.IM{ch},[])
colormap hsv
[x,y,u]=ginput(1);
SelectedIntensity=handles.O.IM{ch}(round(y),round(x));
eval(['set(handles.Threshold,''Max'',SelectedIntensity)'])
eval(['set(handles.Threshold,''value'',SelectedIntensity/2)'])
handles.O.MaxInt(ch)=SelectedIntensity;
colormap gray
guidata(hObject,handles)
% --- Executes on slider movement.
function Time_Scale_Slider_Callback(hObject, eventdata, handles)
% hObject handle to Time_Scale_Slider (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.O.CurrentTimePoint=round(get(hObject,'value'));
handles.O.ImageID.Time=handles.O.CurrentTimePoint;
[handles]=O_LoadImages_Internal(hObject,handles);
% handles=DisplayImage(hObject,handles);
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function Time_Scale_Slider_CreateFcn(hObject, eventdata, handles)
% hObject handle to Time_Scale_Slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function MaxSize_Callback(hObject, eventdata, handles)
% hObject handle to MaxSize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.O.Display_Mode='Regular';
MinAllowedArea=get(handles.MinSize,'value')+1;
val=max([round(get(hObject,'Value')) MinAllowedArea]);
if val>get(hObject,'max')
set(hObject,'max',val+1)
end
set(hObject,'value',val)
[handles]=O_Update_General_Thresholds(hObject,handles);
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function MaxSize_CreateFcn(hObject, eventdata, handles)
% hObject handle to MaxSize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function MinSize_Callback(hObject, eventdata, handles)
% hObject handle to MinSize (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.O.Display_Mode='Regular';
MinAllowedArea=get(handles.MaxSize,'value');
val=min([round(get(hObject,'Value')) MinAllowedArea]);
if val>get(hObject,'max')
set(hObject,'max',val+1)
end
set(hObject,'value',val)
[handles]=O_Update_General_Thresholds(hObject,handles);
% --- Executes during object creation, after setting all properties.
function MinSize_CreateFcn(hObject, eventdata, handles)
% hObject handle to MinSize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on mouse motion over figure - except title and menu.
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in FlatField_Correction.
function FlatField_Correction_Callback(hObject, eventdata, handles)
if get(hObject,'Value')
contents = cellstr(get(handles.Flat_Field_selection,'String'));
FileName=contents{get(handles.Flat_Field_selection,'Value')};
load(['\\carbon.research.sickkids.ca\rkafri\OPRETTA\FlatFieldFiles\' FileName]);
handles.O.flat.Multipicative_Biase=Multipicative_Biase;
% handles.O.flat.Additive_Biase=Additive_Biase;
handles.O.flat.FileName=['\\carbon.research.sickkids.ca\rkafri\OPRETTA\FlatFieldFiles\' FileName];
guidata(hObject, handles);
else
handles.O.flat.Multipicative_Biase=ones(1024,1360);
end
% hObject handle to FlatField_Correction (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of FlatField_Correction
% --- Executes on selection change in Flat_Field_selection.
function Flat_Field_selection_Callback(hObject, eventdata, handles)
% hObject handle to Flat_Field_selection (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
contents = cellstr(get(hObject,'String'));
FileName=contents{get(hObject,'Value')};
load(['\\carbon.research.sickkids.ca\rkafri\OPRETTA\FlatFieldFiles\' FileName]);
handles.O.flat.Multipicative_Biase=Multipicative_Biase;
handles.O.flat.FileName=['\\carbon.research.sickkids.ca\rkafri\OPRETTA\FlatFieldFiles\' FileName];
% handles.O.flat.Additive_Biase=Additive_Biase;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function Flat_Field_selection_CreateFcn(hObject, eventdata, handles)
% hObject handle to Flat_Field_selection (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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');