-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoSecOrder.m
167 lines (132 loc) · 4.05 KB
/
DemoSecOrder.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
% main function
clear
close all
addpath('.\testData\')
addpath('.\clusterData\')
addpath(genpath('.\Evaluation\'));
%% -----------parameter setting----------
wn1 = 1; %clustering : 100
wn2 = 1;
%% ui input image
[pname,adrname]=uigetfile('.\Evaluation\pics\clusterTransform\icon.bmp','Select Your Images'); %'*.jpg','*.bmp', '*bmp'
if exist(strcat(adrname,pname), 'file')
src = imread(strcat(adrname,pname));
figure
imshow(src);
[h,w,~] = size(src);
% srcData = getSpecShape(shape);
[xd,yd] = findLocation(src);
else
warndlg('No image input','warning !');
return;
end
filename = pname;
filename(end-3:end)=[];
savePath = '.\Evaluation\pics\clusteringdata\TwoReach\';
%% input image
% src = imread('sqr.bmp');
% srcImg = im2bw(src); % only the binary image
% [xd,yd] = findLocation(src);
% [h,w,~] = size(src);
%% input real-word image
% ImgName = '132.jpg';
% Img = imread(ImgName);
% [avgOppChnn,segments]= calFeature(ImgName);
% h = ceil(2*max(abs(avgOppChnn(:,1))))+10;
% w = ceil(2*max(abs(avgOppChnn(:,2))))+10;
%
% xd = avgOppChnn(:,1);
% yd =avgOppChnn(:,2);
%
% src = ones(h,w);
%% load clustering data
% nameData = 'Flame';
% [yd,xd,h,w] =loadClusterData(nameData);
% src = [];
%%
tic
TRI = delaunay(xd,yd);
[adjList, adjSecList, uniSecLoc] = findAdjMatrix(TRI);
plotFigure(src,adjList,xd,yd,w,h) % adjList: 1st order
Task = 1; % task == 1: 1st order; task ==2: 1st and 2nd order.
[dataList, ratioList] = calLengthRatioList(unique([adjList;fliplr(adjList)],'rows'),Task, xd, yd);
% Task = 2;
% [dataSecList, ratioSecList] = calLengthRatioList(adjSecList,Task, xd, yd);
[Q, oList]= sort(ratioList(:));
ymax = max(Q);
figure
plot(Q,'LineWidth',2)
title('Q')
ylim([0,ymax])
grid on
order = 1;
th=0.12*wn1;
orderLabel = 1;
T = findTreshold(Q,th,orderLabel); % threshold for Q; wl = T.
wl = T;
disp('first order')
%%----------------------------------------------------
sortedDataList = [];
for iData = oList'
sortedDataList = [sortedDataList; dataList(iData,:)];
end
resDataList = sortedDataList(Q <= wl,: );
plotFigure(src, resDataList,xd,yd,w,h)
%----------------------------fill triangles----------------------------
one_reachList = FindTriangle(resDataList);
%% trifill
figure
imshow(src)
hold on
ppDualplot(one_reachList,yd,xd,w,h) % result
% set(get(gca, 'Title'), 'String', 'Result of point set topological reconstruction.');
hold on
triFill(one_reachList,yd,xd);
hold off
title('Result of 1-reach method')
%%-------------------------------------------------------
% outlier removel
[secDataList, secRatioList] = calSecRatio(resDataList,xd,yd); %
% 1order-->2order
% [secDataList, secRatioList] = calSecRatio(ratioSecList,xd,yd);
[Q, oList]= sort(secRatioList(:));
ymax = max(Q);
figure
plot(Q,'LineWidth',2)
title('Q')
ylim([0,ymax])
grid on
order = 2;
scaleInd = 1;
th = 0.035*wn2;
orderLabel = 2;
T = findTreshold(Q,th,orderLabel); % threshold for Q; wl = T.
sortedDataList = [];
for iData = oList'
sortedDataList = [sortedDataList; secDataList(iData,:)];
end
resList = sortedDataList(Q < T,: ); % <= 2019.11.2
if ~isempty(resList) % 0?
clnList = cleanResList(resList);
% save([savePath filename '_2' '.mat'], 'clnList'); % save resultDataR
plotFigure(src,clnList,xd,yd,w,h)
%% ---------find clusters and outliers------------------
outlier_neib = 2;
[S,C,sort_List] = findConnCluster(TRI,clnList,outlier_neib,yd,xd,w,h);
TriList = FindTriangle(clnList);
%% save clustering method
% save([savePath filename '.mat'],'C')
%% trifill
figure
imshow(src)
hold on
ppDualplot(TriList,yd,xd,w,h) % result
% set(get(gca, 'Title'), 'String', 'Result of point set topological reconstruction.');
hold on
triFill(TriList,yd,xd);
hold off
else
figure
imshow(src)
end
toc