-
Notifications
You must be signed in to change notification settings - Fork 3
/
dynamic_local_maxima_3d_new.m
81 lines (75 loc) · 1.74 KB
/
dynamic_local_maxima_3d_new.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
function [id, pos,Ntree] = dynamic_local_maxima_3d_new(data)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% dynamic method
%{
% parameters
% x direction max and min
thres = 0.5;
minsrh = 0.5;
h = data(:,3);
% search size maximum
if max(data(:,3)) >15
maxsrh = 3;
else
maxsrh = 5;
end
%step search size
stepss = [minsrh:0.5:maxsrh];
% vectorise OHM & filter <2m
h(h<2)=[];
%[mm,nn] = size(OHM);
% plot histogram & divide data from thres to quantile 0.99
%hh = hist(H,length(stepss));
hq = quantile(h,0.99);
% generate sequence with length(stepss) interval
ss = thres:(hq-thres)/(length(stepss)-1):hq;
%}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% fixed window method
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% fixed case
%window = knnsearch(data(:,1:2),data(:,1:2),'k',100,'IncludeTies',true);
h = data(:,3)<2;
data(h,:)=[];
[window,dist] = rangesearch(data(:,1:2),data(:,1:2),2);
% local maxima points
index = [];
thr = quantile(data(:,3),0.5);
for i = 1:length(data)
% dynamic search
%{
%check height quantile
if h(i)<max(ss)
pos = find(Gnew(r,k)<ss, 1 )-1;
else
pos = dd;
end
if pos ==0
pos = 1;
end
search = stepss(pos);
%}
% local window sample
if data(i,3) > thr
list = window{i};
else
list = window{i};
dd = dist{i}>1.5;
list(dd)=[];
end
%list = window{i};
sample = data(list,3);
hmax = max(data(list,3));
if data(i,3) == hmax;
tie = find(sample==hmax);
others = find(list(tie) ~= i);
if ~isempty(others)
data(list(tie(others)),3)=0;
end
index = [index,i];
end
end
n_data = data(index,:);
id = find(n_data(:,3)>0);
pos = n_data(id,:);
Ntree = length(id);