-
Notifications
You must be signed in to change notification settings - Fork 0
/
EllipticSmoothness.m
45 lines (29 loc) · 1.21 KB
/
EllipticSmoothness.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
Ax7 = axes ;;
hold(Ax7,'on') ;
%%
[~,Lab,~,~] = bwboundaries(BW) ;
bw = Lab == 1 ;
[Bound,Lab,~,~] = bwboundaries(bw) ;
imshow(bw,'Parent',Ax7) ;
plot(Ax7,Bound{2,1}(:,2),Bound{2,1}(:,1),'b','LineWidth',1.25) ;
%%
S = regionprops(~bw,'Perimeter','MajoraxisLength','MinoraxisLength','Orientation','Centroid') ;
a = S.MajorAxisLength/2 ;
b = S.MinorAxisLength/2 ;
%% Show
Theta = 0:0.01:2*pi ;
x = a * cos(Theta) ;
y = b * sin(Theta) ;
X = x * sind(90 + S.Orientation) + y * cosd(90 + S.Orientation) ;
Y = x * cosd(90 + S.Orientation) - y * sind(90 + S.Orientation) ;
X = X + S.Centroid(1) ;
Y = Y + S.Centroid(2) ;
plot(Ax7,X,Y,'r','LineWidth',1.25)
%%
PE = pi*(a+b)*(3*(((a-b)^2)/(((a+b)^2)*(sqrt(((-3*((a-b)^2))/((a+b)^2))+4)+10)))+1) ;
EllipticSmoothnessFactor = S.Perimeter / PE
%%
Ti = title(Ax7,{'$Elliptic Smoothness = \frac{P}{P_{Ellipse}}$';['$Elliptic Smoothness = ' num2str(EllipticSmoothnessFactor) '$']},'interpreter','latex','fontsize',16) ;
Ti.Units = 'normalized' ;
Ti.Position = Ti.Position + [0 -0.1 0] ;
legend(Ax7,{['$P = $' num2str(S.Perimeter)] ; ['$P_{ellipse} = $' num2str(PE)]},'Interpreter','latex','FontSize',11,'Location','northeastoutside') ;