-
Notifications
You must be signed in to change notification settings - Fork 5
/
naz_remove_fragments.m
58 lines (52 loc) · 2.39 KB
/
naz_remove_fragments.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
function boundaryOutput = naz_remove_fragments(boundaryInput, fragmentList)
%NAZ_REMOVE_FRAGMENTS Remove fragments and merges corresponding regions
% NB! Reliably alters only boundaryInfo.edges.fragments (used in naz_plot_fragments),
% and boundaryInfo.imgRegions (used in evaluate_segmentation); If you need to use other information
% (like junctions) from penalized boundaryInfo, you need to remove it properly in this funciton.
boundaryOutput = boundaryInput;
% removing image region (labels) by assigning region
% on the left from fragment label of the region on the right.
for k=1:size(fragmentList,1)
f = fragmentList{k,1};
for p = 1:size(f,1)
L = f{p}(1);
ndxs = boundaryOutput.imgRegions == L;
boundaryOutput.imgRegions(ndxs) = f{p}(2); %merging regions
% changing paired labels ahead of fragmentlist accordingly
for v=p:size(f,1)
if any(f{v}==L)
f{v}( f{v}==L ) = f{p}(2);
end
end
end
end
% after the previous loop, we have labeling "gaps" (e.g. 1 2 3 . 6 7 8)
% here we will shift (redefine) all the labeling so they will have a sequential order
labels = unique(boundaryOutput.imgRegions);
for k = 1:length(labels)
boundaryOutput.imgRegions(boundaryOutput.imgRegions==labels(k)) = k;
end
clear lables;
% removing fragments
frags = []; %flatenning cells in single-column array
for k = 1:size(fragmentList,1)
f = fragmentList{k,2};
for p = 1:size(f,1)
frags = [frags; f{p}(:)]; %#ok<AGROW>
end
end
frags = sort(frags);
ndxs = true(size(boundaryInput.edges.fragments));
ndxs(frags) = false;
boundaryOutput.edges.fragments = boundaryInput.edges.fragments(ndxs);
% removing some other fields (with no purpose so far, just for consistency)
%boundaryOutput.ne = boundaryOutput.ne - length(frags);
%boundaryOutput.edges.indices = boundaryInput.edges.indices(ndxs);
%boundaryOutput.edges.spLR = boundaryInput.edges.spLR(ndxs',:);
%boundaryOutput.edges.thetaDirected = boundaryInput.edges.thetaDirected(ndxs');
%boundaryOutput.edges.thetaUndirected = boundaryInput.edges.thetaUndirected(ndxs');
% NB! need to take care of corresponding boundaryInfo.junctions, before removing boundaryInfo.edges.juncitons
%boundaryOutput.edges.junctions = boundaryInput.edges.junctions(ndxs');
% NB! length(adjacency) == ne*2
%boundaryOutput.edges.adjacency = boundaryInput.edges.adjacency(ndxs');
end