-
Notifications
You must be signed in to change notification settings - Fork 0
/
cornerMyMethod.m
55 lines (42 loc) · 1.85 KB
/
cornerMyMethod.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
function Out = cornerMyMethod(bw)
[Bound,~,~,~] = bwboundaries(bw) ;
if length(Bound) == 2
Y = Bound{2,1}(:,2) ;
X = Bound{2,1}(:,1) ;
S = regionprops(bw) ;
for i = 1:length(X)
D(i,1) = pdist([S(1).Centroid(1) S(1).Centroid(2) ; X(i) Y(i)]) ;
end
[xData, yData] = prepareCurveData( [], D );
ft = fittype( 'smoothingspline' );
opts = fitoptions( 'Method', 'SmoothingSpline' );
opts.SmoothingParam = 0.5;
[Fit, ~] = fit(xData,yData,ft,opts);
D = Fit(xData) ;
base_ind = find(D==min(D)) ;
XX = [X(base_ind(1)+1:end) ; X(1:base_ind(1))] ;
YY = [Y(base_ind(1)+1:end) ; Y(1:base_ind(1))] ;
DD = [D(base_ind(1)+1:end) ; D(1:base_ind(1))] ;
X = XX ; Y = YY ; D = DD ;
[P,Loc] = findpeaks(D,'MinPeakDistance',15,'MinPeakHeight',60,'MinPeakProminence',0.25,'MinPeakWidth',1) ;
% figure ; AxD = axes ; plot(D) ; text(Loc,P,'max') ; hold on ;
% plot(Ax12,Y(Loc),X(Loc),'*y') ;
dD = [0 ; diff(D)] ; % 1st order
d2D = [0 ; diff(dD)] ; % 2st order
[xData, yData] = prepareCurveData( [], d2D );
ft = fittype( 'smoothingspline' );
opts = fitoptions( 'Method', 'SmoothingSpline' );
opts.SmoothingParam = 0.2;
[Fit, ~] = fit(xData,yData,ft,opts);
d2D = Fit(xData) ;
[~,dLoc] = findpeaks(d2D,'MinPeakDistance',1,'MinPeakHeight',min(d2D),'MinPeakProminence',0.00125,'MinPeakWidth',0.01) ;
d_Loc = find((d2D < 0.015 & d2D > -0.015) == 1) ;
DLoc = intersect(dLoc , d_Loc) ;
% figure ; plot(d2D) ; text(DLoc,d2D(DLoc),'max') ;
% plot(AxD,DLoc,D(DLoc),'ro','MarkerEdgeColor','none','MarkerFaceColor','r') ;
% plot(Ax12,Y(DLoc),X(DLoc),'*r') ;
LOC = unique([Loc ; DLoc]) ;
XCON = Y(LOC) ;
YCON = X(LOC) ;
Out = [XCON , YCON] ;
end % end of process