-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialSeg.m
60 lines (44 loc) · 1.98 KB
/
initialSeg.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
function [omma_centroids, omma_area] = initialSeg(ilastik_probabilities,threshold)
%--------------------------------------------------------------------------
% segment the ommatidia using a threshold
%--------------------------------------------------------------------------
disp('/n')
disp('Thresholding ilastik probabilities to find ommatidia')
% store thresholded probabilites
segmented_ommatidia = zeros(size(ilastik_probabilities));
% loop through probability masks and threshold each one
for i = 1:size(ilastik_probabilities,3)
% thresholding ilastik probability masks
segmented_ommatidia(:,:,i) = im2bw(ilastik_probabilities(:,:,i),threshold);
end
%--------------------------------------------------------------------------
% find centroids of segmented ommatidia
%--------------------------------------------------------------------------
disp('Calculating ommatidia centroids')
labeled_ommatidia = zeros(size(segmented_ommatidia));
% bwlabel segmented ommatidia
for i = 1:size(labeled_ommatidia,3)
labeled_ommatidia(:,:,i) = bwlabel(segmented_ommatidia(:,:,i));
end
% create cell array to hold centroid positions - each cell contains the
% centroids for one of the images
omma_centroids = cell(size(labeled_ommatidia,3),1);
% compute centroid positions and screen out small ones
for i = 1:length(omma_centroids)
temp_centroid = regionprops(labeled_ommatidia(:,:,i),'Centroid');
temp_area = regionprops(labeled_ommatidia(:,:,i),'Area');
omma_centroids{i} = round(cat(1,temp_centroid.Centroid));
omma_area{i} = round(cat(1,temp_area.Area));
end
% for j = 1:size(omma_cent_disp,3)
% omma_cent_disp(:,:,j) = zeros(size(omma_cent_disp(:,:,j)));
% for jj = 1:size(omma_cent{j})
% omma_cent_disp(omma_cent{j}(jj,2),omma_cent{j}(jj,1),j) = 1;
% end
% end
%
% dilate_omma_cent_disp = zeros(size(omma_cent_disp));
% se = strel('disk',2);
% for t = 1:size(omma_cent_disp,3)
% dilate_omma_cent_disp(:,:,t) = imdilate(omma_cent_disp(:,:,t),se);
% end