-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimageAnalysis.m
More file actions
1145 lines (949 loc) · 42.2 KB
/
imageAnalysis.m
File metadata and controls
1145 lines (949 loc) · 42.2 KB
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 = population_GUI_v1_2(varargin)
% POPULATION_GUI_V1_2 MATLAB code for population_GUI_v1_2.fig
% POPULATION_GUI_V1_2, by itself, creates a new POPULATION_GUI_V1_2 or raises the existing
% singleton*.
%
% H = POPULATION_GUI_V1_2 returns the handle to a new POPULATION_GUI_V1_2 or the handle to
% the existing singleton*.
%
% POPULATION_GUI_V1_2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in POPULATION_GUI_V1_2.M with the given input arguments.
%
% POPULATION_GUI_V1_2('Property','Value',...) creates a new POPULATION_GUI_V1_2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before population_GUI_v1_2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to population_GUI_v1_2_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 population_GUI_v1_2
% Last Modified by GUIDE v2.5 08-Jul-2016 14:10:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @population_GUI_v1_2_OpeningFcn, ...
'gui_OutputFcn', @population_GUI_v1_2_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 population_GUI_v1_2 is made visible.
function population_GUI_v1_2_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 population_GUI_v1_2 (see VARARGIN)
% Choose default command line output for population_GUI_v1_2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes population_GUI_v1_2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = population_GUI_v1_2_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 slider movement.
function plane_slider_Callback(hObject, eventdata, handles)
% hObject handle to plane_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
% set slider_value to the plane_slider 'Value' GFP channel
%load in the existing centroids
centroid_points = handles.centroid_points;
% update axes3 first so that GFP channel is "selected" for thresholding
slider_value = ceil(get(handles.plane_slider,'Value'));
if isempty(centroid_points) == 0
subplot(handles.axes3);
hold on;
imshow(handles.im_mat_2(:,:,slider_value),[]);
plot(centroid_points(:,1), centroid_points(:,2), 'go');
hold off;
else
subplot(handles.axes3);
imshow(handles.im_mat_2(:,:,slider_value),[]);
end
if isempty(centroid_points) == 0
subplot(handles.axes1);
hold on;
imshow(handles.im_mat(:,:,slider_value),[]);
plot(centroid_points(:,1), centroid_points(:,2), 'go');
hold off;
else
subplot(handles.axes1);
imshow(handles.im_mat(:,:,slider_value),[]);
end
%set slider text
plane_num = handles.plane_num;
set(handles.slider_text, 'String', strcat(num2str(...
ceil(get(handles.plane_slider,'Value'))),...
'/', num2str(plane_num)));
%set Stack text
stack_total = plane_num/str2double(get(handles.step_number,'String'));
current_stack = ceil(slider_value/...
str2double(get(handles.step_number,'String')));
set(handles.stack_text,'String',strcat(num2str(current_stack),...
num2str('/'), num2str(stack_total)));
% --- Executes during object creation, after setting all properties.
function plane_slider_CreateFcn(hObject, eventdata, handles)
% hObject handle to plane_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
% --------------------------------------------------------------------
function file_menu_Callback(hObject, eventdata, handles)
% hObject handle to file_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function open_image_Callback(hObject, eventdata, handles)
% hObject handle to open_image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%set working directory to current directory
wdir = pwd;
%select the file
[filename pathname] = uigetfile('*.tif', 'Choose the GFP image stack');
%read in the file using tif3Dread.m
im_mat = tif3Dread(strcat(pathname,filename));
%change image to double
im_mat = double(im_mat);
%set up data to axes1 plot
subplot(handles.axes1);
%show first frame of image stack
imshow(im_mat(:,:,1),[]);
%read in the number of frames
[~,~,plane_num] = size(im_mat);
handles.plane_num = plane_num;
%set slider
slider_step = 1/plane_num;
set(handles.plane_slider, 'SliderStep', [slider_step slider_step],...
'Min', 1, 'Max', plane_num, 'Value', 1);
handles.im_mat = im_mat;
%set slider text
set(handles.slider_text, 'String', strcat(num2str(...
get(handles.plane_slider,'Value')),...
'/', num2str(plane_num)));
%set Stack text
stack_total = plane_num/str2double(get(handles.step_number,'String'));
current_stack = 1;
set(handles.stack_text,'String',strcat(num2str(current_stack),...
num2str('/'), num2str(stack_total)));
%open the RFP stack in axes3
[filename pathname] = uigetfile('*.tif', 'Choose the RFP image stack');
im_mat_2 = tif3Dread(strcat(pathname,filename));
im_mat_2 = double(im_mat_2);
handles.im_mat_2 = im_mat_2;
subplot(handles.axes3);
imshow(im_mat_2(:,:, ceil(get(handles.plane_slider,'Value'))),[]);
%set up the cell array that will hold the image stack data
data_cell = {'Plane', 'Major Axis (nm)','Minor Axis (nm)', 'Aspect Ratio',...
'Centroid', '3D Spindle (nm)','SPB 1', 'SPB 2', 'kMT 1', 'kMT2',...
'Plasmid Split?','Plasmid Image'};
handles.data_cell = data_cell;
record_num = 1;
handles.record_num = record_num;
%instantiate the handles.centroid_points
handles.centroid_points = [];
% update the handles data structure
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
% --- Executes on button press in FG_button.
function FG_button_Callback(hObject, eventdata, handles)
% hObject handle to FG_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h = imrect;
pos_fg = wait(h);
pos_fg = ceil(pos_fg);
handles.pos_fg = pos_fg;
im_mat_fg = handles.im_mat(pos_fg(2):pos_fg(2)+(pos_fg(4)),pos_fg(1):...
pos_fg(1)+pos_fg(3), ceil(get(handles.plane_slider,'Value')));
subplot(handles.axes2);
imshow(im_mat_fg, []);
mean(im_mat_fg(:));
k = waitforbuttonpress;
%subtract out the average BG from FG
im_mat_fg = im_mat_fg - handles.avg_bg;
%convert the negative numbers to zeros
im_mat_fg(im_mat_fg<0) = 0;
subplot(handles.axes2);
imshow(im_mat_fg,[]);
k = waitforbuttonpress;
%create a binary based on multithresh
im_thresh = multithresh(im_mat_fg);
im_bin = im_mat_fg > im_thresh;
subplot(handles.axes2);
imshow(im_bin, []);
handles.im_bin = im_bin;
%pad the binary image back to the orginal size
[im_y, im_x, ~] = size(handles.im_mat);
x_pad_1 = zeros(pos_fg(4) + 1, pos_fg(1) - 1);
im_bin_resize = horzcat(x_pad_1,im_bin);
[~,im_bin_resize_width] = size(im_bin_resize);
x_pad_2 = zeros(pos_fg(4) +1, im_x - im_bin_resize_width);
im_bin_resize = horzcat(im_bin_resize, x_pad_2);
y_pad_1 = zeros(pos_fg(2) - 1, im_x);
im_bin_resize = vertcat(y_pad_1,im_bin_resize);
[im_bin_resize_height, ~] = size(im_bin_resize);
y_pad_2 = zeros(im_y - im_bin_resize_height, im_x);
im_bin_resize = vertcat(im_bin_resize, y_pad_2);
slider_value = ceil(get(handles.plane_slider,'Value'));
handles.plasmid_mask = im_bin_resize;
handles.plasmid_plane = slider_value;
% Save the plasmid image, Note: this does not have the bg sub
size(handles.im_mat(:,:,slider_value))
size(im_bin_resize)
im_check = handles.im_mat(:,:,slider_value) .* im_bin_resize;
handles.im_check = im_check;
%get the centroid of the resized binary image
if get(handles.no_plasmid_check,'Value') == 0
centroid_struct = regionprops(im_bin_resize,'centroid');
centroid = centroid_struct(1);
handles.centroid = struct2array(centroid);
%plot the centroid
subplot(handles.axes1);
hold on
plot(handles.centroid(1,1), handles.centroid(1,2), 'go');
hold off
subplot(handles.axes3);
hold on
plot(handles.centroid(1,1), handles.centroid(1,2), 'go');
hold off
else
handles.centroid = [];
handles.plasmid_plane = [];
end
handles.centroid_points = [handles.centroid_points; struct2array(centroid)];
guidata(hObject,handles);
% --- Executes on button press in sub_bg.
function sub_bg_Callback(hObject, eventdata, handles)
% hObject handle to sub_bg (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.im_mat(:,:,ceil(get(handles.plane_slider,'Value'))) = ...
handles.im_mat(:,:,ceil(get(handles.plane_slider,'Value'))) - ...
handles.avg_bg;
max(max(handles.im_mat(:,:,ceil(get(handles.plane_slider,'Value')))))
%set up data to axes1 plot
subplot(handles.axes1);
imshow(handles.im_mat(:,:,ceil(get(handles.plane_slider,'Value'))),[]);
set(handles.bg_text, 'String', 'Applied BG sub');
% --- Executes on button press in major_axis.
function major_axis_Callback(hObject, eventdata, handles)
% hObject handle to major_axis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%get major axis length
bw_props = regionprops(handles.im_bin,'MajorAxisLength');
pixel_size = str2double(get(handles.pixel_size, 'String'));
axis_length = bw_props.MajorAxisLength * pixel_size;
%get minor axis length
bw_props_2 = regionprops(handles.im_bin,'MinorAxisLength');
minor_axis = bw_props_2.MinorAxisLength * pixel_size;
%calculate aspect ratio
aspect_rat = axis_length/minor_axis;
%puth major and minor axis to handles structure
handles.axis_length = axis_length;
handles.minor_axis = minor_axis;
handles.aspect_rat = aspect_rat;
guidata(hObject,handles);
%set the text boxes
set(handles.axis_tag, 'String', num2str(round(axis_length)));
set(handles.minor_tag,'String', num2str(round(minor_axis)));
set(handles.aspect_rat_tag,'String', num2str(aspect_rat));
% --- Executes on button press in spb_1_button.
function spb_1_button_Callback(hObject, eventdata, handles)
% hObject handle to spb_1_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Switch to axes3
subplot(handles.axes3);
%wait for user button press on SPB
k = waitforbuttonpress;
click_point = round(get(gca,'CurrentPoint'));
hold on
plot(click_point(1,1),click_point(1,2), '-rx');
hold off
%get the current plane to find Z position
current_plane=ceil(get(handles.plane_slider, 'Value'));
%figure out where we are in the z-stack
%get the step number information from the edit text box
step_number = str2double(get(handles.step_number,'String'));
%modulo of current step by step number
stack_mod = mod(ceil(get(handles.plane_slider,'Value')), step_number);
if stack_mod == 0
stack_min = (1-step_number) + current_plane;
stack_max = current_plane;
else
stack_min = (1-stack_mod) + current_plane;
stack_max = abs(stack_mod - step_number) + current_plane;
end
% let me display the search area and the resulting pixel
% on the command line to check
% current_plane
% stack_min
% stack_max
% select a portion of the stack based on the up a a larger XYZ search area based on the click_point
if click_point(1,1)<5
click_point(1,1)=5;
end
if click_point(1,2)<5
click_point(1,2)=5;
end
%correcting if click region is close to maximum
im_mat = handles.im_mat;
[y,x,~] = size(im_mat);
if click_point(1,1) > (x-4)
click_point(1,1) = x-4;
end
if click_point(1,2) > (y-4)
click_point(1,2) = y-4;
end
crop_im = handles.im_mat_2((click_point(1,2)-4):(click_point(1,2)+4),...
(click_point(1,1)-4):(click_point(1,1)+4),stack_min:stack_max);
max_pix = max(crop_im(:));
[max_y, max_x, max_z] = ind2sub(size(crop_im),find(crop_im==max_pix));
if length(max_x)~= 1
max_x=max_x(1);
max_y=max_y(1);
max_z=max_z(1);
end
%convert from crop_im coordinates back to the im_mat_2 coordinates
max_x_im = max_x + click_point(1,1)-4 - 1;
max_y_im = max_y + click_point(1,2)-4 - 1;
max_z_im = max_z + stack_min - 1;
test_max = handles.im_mat_2(max_y_im, max_x_im, max_z_im);
% %check that the intensity values match by displaying the crop and
% %the original
% % test_max
% % max_pix
% save the X Y and Plane data for SPB1 to the handles structure
spb1 = [max_x_im, max_y_im, max_z_im, max_pix];
handles.spb1 = spb1;
guidata(hObject,handles);
% --- Executes on button press in spb_2_button.
function spb_2_button_Callback(hObject, eventdata, handles)
% hObject handle to spb_2_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Switch to axes3
subplot(handles.axes3);
%wait for user button press on SPB
k = waitforbuttonpress;
click_point = round(get(gca,'CurrentPoint'));
hold on
plot(click_point(1,1),click_point(1,2), '-rx');
hold off
%get the current plane to find Z position
current_plane=ceil(get(handles.plane_slider, 'Value'));
%figure out where we are in the z-stack
%get the step number information from the edit text box
step_number = str2double(get(handles.step_number,'String'));
%modulo of current step by step number
stack_mod = mod(ceil(get(handles.plane_slider,'Value')), step_number);
if stack_mod == 0
stack_min = (1-step_number) + current_plane;
stack_max = current_plane;
else
stack_min = (1-stack_mod) + current_plane;
stack_max = abs(stack_mod - step_number) + current_plane;
end
% let me display the search area and the resulting pixel
% on the command line to check
% current_plane
% stack_min
% stack_max
% select a portion of the stack based on the up a a larger XYZ search area based on the click_point
if click_point(1,1)<5
click_point(1,1)=5;
end
if click_point(1,2)<5
click_point(1,2)=5;
end
%correcting if click region is close to maximum
im_mat = handles.im_mat;
[y,x,~] = size(im_mat);
if click_point(1,1) > (x-4)
click_point(1,1) = x-4;
end
if click_point(1,2) > (y-4)
click_point(1,2) = y-4;
end
% select a portion of the stack based on the up a a larger XYZ search area based on the click_point
crop_im = handles.im_mat_2((click_point(1,2)-4):(click_point(1,2)+4),...
(click_point(1,1)-4):(click_point(1,1)+4),stack_min:stack_max);
max_pix = max(crop_im(:));
[max_y, max_x, max_z] = ind2sub(size(crop_im),find(crop_im==max_pix));
if length(max_x)~= 1
max_x=max_x(1);
max_y=max_y(1);
max_z=max_z(1);
end
%convert from crop_im coordinates back to the im_mat_2 coordinates
max_x_im = max_x + click_point(1,1)-4 - 1;
max_y_im = max_y + click_point(1,2)-4 - 1;
max_z_im = max_z + stack_min - 1;
test_max = handles.im_mat_2(max_y_im, max_x_im, max_z_im);
% %check that the intensity values match by displaying the crop and
% %the original
% test_max
% max_pix
spb2 = [max_x_im, max_y_im, max_z_im, max_pix];
handles.spb2 = spb2;
guidata(hObject,handles);
function step_size_Callback(hObject, eventdata, handles)
% hObject handle to step_size (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 step_size as text
% str2double(get(hObject,'String')) returns contents of step_size as a double
% --- Executes during object creation, after setting all properties.
function step_size_CreateFcn(hObject, eventdata, handles)
% hObject handle to step_size (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
function step_number_Callback(hObject, eventdata, handles)
% hObject handle to step_number (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 step_number as text
% str2double(get(hObject,'String')) returns contents of step_number as a double
% --- Executes during object creation, after setting all properties.
function step_number_CreateFcn(hObject, eventdata, handles)
% hObject handle to step_number (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
function pixel_size_Callback(hObject, eventdata, handles)
% hObject handle to pixel_size (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 pixel_size as text
% str2double(get(hObject,'String')) returns contents of pixel_size as a double
% --- Executes during object creation, after setting all properties.
function pixel_size_CreateFcn(hObject, eventdata, handles)
% hObject handle to pixel_size (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 calc_button.
function calc_button_Callback(hObject, eventdata, handles)
% hObject handle to calc_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%make contigent on plasmid detected or not
%load in the SPB positions
if get(handles.no_spb1_check, 'Value') == 0
spb1 = handles.spb1;
else
spb1 = [];
handles.spb1 = spb1;
end
if get(handles.no_spb2_check, 'Value') == 0
spb2 = handles.spb2;
handles.spb2 = spb2;
else
spb2 = [];
handles.spb2 = spb2;
end
%load in the step size and pixel size
pixel_size = str2double(get(handles.pixel_size, 'String'));
step_size = str2double(get(handles.step_size, 'String'));
if get(handles.no_spb1_check,'Value') == 1 || ...
get(handles.no_spb2_check, 'Value') == 1 || ...
get(handles.split_check, 'Value') == 1
%set the spindle_3D value to blank
spindle_3D = [];
handles.spindle_3D = spindle_3D;
% Display that the spindle length cannot be calculated
set(handles.spindle_nm, 'String', 'NA');
else
%calculate the 3D spindle length
spindle_3D = sqrt(((spb1(1)-spb2(1))*pixel_size)^2 +...
(((spb1(2) - spb2(2))*pixel_size)^2) +...
(((spb1(3)-spb2(3))*step_size)^2));
handles.spindle_3D = spindle_3D;
% Display the spindle length in the GUI
set(handles.spindle_nm, 'String', num2str(round(spindle_3D)));
end
%loop through all the 1 positions in the binary and calculate
%the distance from SPB1 to each pixel
%load in the resized plasmid binary image
im_bin_resize = handles.plasmid_mask;
%load in the plasmid plane
plasmid_plane = handles.plasmid_plane;
bin_ind = find(im_bin_resize);
[y, x] = ind2sub(size(im_bin_resize),bin_ind);
%merge x and y plasmid coordinates with plane information
plane_array = ones(length(bin_ind),1) * plasmid_plane;
plasmid_coords = horzcat(x,y,plane_array);
if get(handles.no_spb1_check, 'Value') == 1 || ...
get(handles.no_plasmid_check, 'Value') == 1
%set kmt1 to blank
kmt1 = [];
%display that kMT1 cannot be calculated
set(handles.kmt1_text, 'String', 'NA');
else
%calculate the distance in pixels from SPB1 to each plasmid pixel
dist_array_spb1 = sqrt((plasmid_coords(:,1)*pixel_size - spb1(1)*pixel_size).^2 ...
+ (plasmid_coords(:,2)*pixel_size - spb1(2)*pixel_size).^2 ...
+ (plasmid_coords(:,3)*step_size - spb1(3)*step_size).^2);
min_dist_spb1 = min(dist_array_spb1);
kmt1 = min_dist_spb1;
set(handles.kmt1_text, 'String', num2str(round(kmt1)));
end
if get(handles.no_spb2_check, 'Value') == 1 || ...
get(handles.no_plasmid_check, 'Value') == 1
%set kmt2 to blank
kmt2 = [];
%display that kMT1 cannot be calculated
set(handles.kmt2_text, 'String', 'NA');
else
%calculate the distance in pixel from SPB2 to each plasmid pixel
dist_array_spb2 = sqrt((plasmid_coords(:,1) * pixel_size - spb2(1)*pixel_size).^2 ...
+ (plasmid_coords(:,2)*pixel_size - spb2(2)*pixel_size).^2 ...
+ (plasmid_coords(:,3)*step_size - spb2(3)*step_size).^2);
min_dist_spb2 = min(dist_array_spb2);
kmt2 = min_dist_spb2;
set(handles.kmt2_text, 'String', num2str(round(kmt2)));
end
%if the plasmid is split then let the user choose which kmt to save
split_logical = get(handles.split_check,'Value');
if split_logical == 1
kmt_array = get(handles.kmt1_check,'Value') -...
get(handles.kmt2_check,'Value');
switch kmt_array
case 1
kmt2 = [];
set(handles.kmt2_text, 'String', 'NA')
case -1
kmt1 = [];
set(handles.kmt1_text, 'String', 'NA')
end
end
% add kmt 1 and 2 to handles structure for recording data
handles.kmt2 = kmt2;
handles.kmt1 = kmt1;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function calc_button_CreateFcn(hObject, eventdata, handles)
% hObject handle to calc_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes during object deletion, before destroying properties.
function spb_1_button_DeleteFcn(hObject, eventdata, handles)
% hObject handle to spb_1_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over spb_1_button.
function spb_1_button_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to spb_1_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on key press with focus on spb_1_button and none of its controls.
function spb_1_button_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to spb_1_button (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function spb_2_button_CreateFcn(hObject, eventdata, handles)
% hObject handle to spb_2_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes during object deletion, before destroying properties.
function spb_2_button_DeleteFcn(hObject, eventdata, handles)
% hObject handle to spb_2_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on key press with focus on spb_2_button and none of its controls.
function spb_2_button_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to spb_2_button (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object deletion, before destroying properties.
function calc_button_DeleteFcn(hObject, eventdata, handles)
% hObject handle to calc_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over calc_button.
function calc_button_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to calc_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function axes2_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes2
% --- Executes during object creation, after setting all properties.
function axes3_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes3
% --- Executes during object deletion, before destroying properties.
function axes3_DeleteFcn(hObject, eventdata, handles)
% hObject handle to axes3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object deletion, before destroying properties.
function plane_slider_DeleteFcn(hObject, eventdata, handles)
% hObject handle to plane_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over plane_slider.
function plane_slider_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to plane_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on key press with focus on plane_slider and none of its controls.
function plane_slider_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to plane_slider (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in record_button.
function record_button_Callback(hObject, eventdata, handles)
% hObject handle to record_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%This button will record the data in some sort of strucuture that
%can be saved later
%read in all the data we want
plasmid_plane = handles.plasmid_plane;
axis_length = handles.axis_length;
minor_axis = handles.minor_axis;
aspect_rat = handles.aspect_rat;
centroid = handles.centroid;
spb1 = handles.spb1;
spb2 = handles.spb2;
spindle_3D = handles.spindle_3D;
kmt1 = handles.kmt1;
kmt2 = handles.kmt2;
record_num = handles.record_num;
split_logical = get(handles.split_check,'Value');
im_check = handles.im_check;
%if the plasmid could not be dectected set kMTs and plasmid value to blank
if get(handles.no_plasmid_check, 'Value') == 1
kmt1 = [];
kmt2 = [];
axis_length = [];
end
%if the plasmid is split, do not record spindle length
if get(handles.split_check, 'Value') == 1
spindle_3D = [];
end
% put it all in the cell array that we created when we opened the image
handles.data_cell(record_num + 1,:) = {plasmid_plane, axis_length,...
minor_axis, aspect_rat, centroid, spindle_3D, spb1, spb2,...
kmt1, kmt2, split_logical, im_check};
%increase the record number
record_num = record_num + 1;
handles.record_num = record_num;
%update the record display text
set(handles.record_text,'String', num2str(handles.record_num));
%clear all the data
handles.plasmid_plane = [];
handles.axis_length = [];
handles.minor_axis = [];
handles.aspect_rat = [];
handles.spb1 = [];
handles.spb2 = [];
handles.spindle_3D = [];
handles.kmt1 = [];
handles.kmt2 = [];
handles.centroid = [];
handles.im_check = [];
%revert text boxes to original states
set(handles.axis_tag, 'String', 'Major Axis Length');
set(handles.minor_tag, 'String', 'Minor Axis Length');
set(handles.aspect_rat_tag, 'String', 'Aspect Ratio');
set(handles.kmt1_text, 'String', 'kMT 1');
set(handles.kmt2_text, 'String', 'kMT 2');
set(handles.spindle_nm, 'String', '3D Spindle');
%update the handles data structure
guidata(hObject,handles);
% --------------------------------------------------------------------
function save_data_Callback(hObject, eventdata, handles)
% hObject handle to save_data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%load the cell array from the handles structure
data_cell = handles.data_cell;
uisave('data_cell');
% --- Executes on button press in no_spb1_check.
function no_spb1_check_Callback(hObject, eventdata, handles)
% hObject handle to no_spb1_check (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 no_spb1_check
% --- Executes on button press in no_spb2_check.
function no_spb2_check_Callback(hObject, eventdata, handles)
% hObject handle to no_spb2_check (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 no_spb2_check
% --- Executes on button press in clear_longaxis.
function clear_longaxis_Callback(hObject, eventdata, handles)
% hObject handle to clear_longaxis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%clear the major axis length
handles.axis_length = [];
set(handles.axis_tag, 'String', 'Major Axis Length');
%clear the minor axis length
handles.minor_axis = [];
set(handles.minor_tag,'String', 'Minor Axis Length');
%clear the aspect ratio
handles.aspect_rat = [];
set(handles.aspect_rat_tag,'String','Aspect Ratio');
%clear the centroid measurement
handles.centroid = [];
guidata(hObject,handles);
%Change the figure to axes1, the GFP channel
subplot(handles.axes1);
% --- Executes on button press in clear_spindle.
function clear_spindle_Callback(hObject, eventdata, handles)
% hObject handle to clear_spindle (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Clear all spindle related info
handles.spb1 = [];
handles.spb2 = [];
handles.spindle_3D = [];
handles.kmt1 = [];
handles.kmt2 = [];
%reset all text boxes
set(handles.kmt1_text, 'String', 'kMT 1');
set(handles.kmt2_text, 'String', 'kMT 2');
set(handles.spindle_nm, 'String', '3D Spindle');
% --- Executes on button press in split_check.
function split_check_Callback(hObject, eventdata, handles)
% hObject handle to split_check (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 split_check
% --- Executes on button press in no_plasmid_check.
function no_plasmid_check_Callback(hObject, eventdata, handles)
% hObject handle to no_plasmid_check (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%set the axis length in handles strucutre to blank
% --- Executes on button press in BG_button.
function BG_button_Callback(hObject, eventdata, handles)
% hObject handle to BG_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%get the current plane number
slider_value = ceil(get(handles.plane_slider,'Value'));
%change the plot to axes1, the GFP image
subplot(handles.axes1);
%draw a rectangle
h = imrect;
%get position coordinates of rectangle
pos_bg = wait(h);
%sample the GFP image
im_mat_bg = handles.im_mat(round(pos_bg(2)):round(pos_bg(2))+round((pos_bg(4))),round(pos_bg(1)):...
round(pos_bg(1))+ round(pos_bg(3)),slider_value);
%get average of that image
avg_bg = mean(im_mat_bg(:));
handles.avg_bg = avg_bg;
set(handles.BG_text, 'String', num2str(avg_bg));
guidata(hObject,handles);
% --- Executes on button press in imdilate_button.
function imdilate_button_Callback(hObject, eventdata, handles)
% hObject handle to imdilate_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%create a strucutral element
SE_disk = strel('disk', 1);
%load in the binary image
im_bin = handles.im_bin;
%apply the dilation
im_bin = imdilate(im_bin, SE_disk);
%show the new image
subplot(handles.axes2);
imshow(im_bin,[]);
%update the im_bin in the handles structure
handles.im_bin = im_bin;
%perform the same finishing operations as FG button
%load in the necessary variables from FG button
pos_fg = handles.pos_fg;
%pad the binary image back to the orginal size
[im_y, im_x, ~] = size(handles.im_mat);
x_pad_1 = zeros(pos_fg(4) + 1, pos_fg(1) - 1);
im_bin_resize = horzcat(x_pad_1,im_bin);
[~,im_bin_resize_width] = size(im_bin_resize);
x_pad_2 = zeros(pos_fg(4) +1, im_x - im_bin_resize_width);