-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShapeFactors.m
50 lines (30 loc) · 980 Bytes
/
ShapeFactors.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
Ax13 = axes ;
hold(Ax13,'on') ;
[~,Lab,~,~] = bwboundaries(BW) ;
bw = Lab==1 ;
imshow(bw,'Parent',Ax13) ;
[Bound,~,~,~] = bwboundaries(bw) ;
X = Bound{2,1}(:,2) ;
Y = Bound{2,1}(:,1) ;
Coord = [X' ; Y'] ;
DistMatrix = squareform(pdist(Coord')) ;
while true
[rD , cD] = find(max(DistMatrix(:)) == DistMatrix) ;
[Index , ~ , ~ , ~] = BinaryLine(bw,[X(rD(1)) X(cD(1))] , [Y(rD(1)) Y(cD(1))]) ;
QualityFraction = nnz(~bw(Index))/length(Index) ;
if QualityFraction >= 0.98
L = DistMatrix(rD(1),cD(1)) ;
break
else
DistMatrix(rD(1),cD(1)) = 0 ;
end
end
plot(Ax13,[X(rD(1)) X(cD(1))] , [Y(rD(1)) Y(cD(1))],'r')
%%
% bl = bw ; bl(Index) = true ; figure ; imshow(bl)
% figure ; imshow(Binary)
% plot(Ax13, c , r ,'*b')
%%
S = regionprops(~bw,'Centroid','Perimeter','Area') ;
ShapeFactor1 = (4*pi*S.Area) / (S.Perimeter^2)
ShapeFactor1 = (4*S.Area) / (pi*(L^2))