|
a |
|
b/Image features calculation code/Working/shape features/calcShapeFeatures2D.m |
|
|
1 |
function STATS = calcShapeFeatures2D(bwImage) |
|
|
2 |
%% compute shape features |
|
|
3 |
|
|
|
4 |
% given an image region and returns a structure with the results. |
|
|
5 |
STATS = regionprops (bwImage,'Area', 'Extent', 'Perimeter', ... |
|
|
6 |
'Centroid', 'ConvexArea', 'ConvexImage','ConvexHull',... |
|
|
7 |
'Solidity', 'Eccentricity', 'MajorAxisLength', ... |
|
|
8 |
'EquivDiameter','MinorAxisLength'); |
|
|
9 |
|
|
|
10 |
%Call custom perimeter and convex perimeter method, because it is more precise |
|
|
11 |
STATS.Perimeter = FacetMidpointPerim(bwImage); |
|
|
12 |
STATS.ConvexPerimeter = ConvexPerim(bwImage); |
|
|
13 |
|
|
|
14 |
%Circularity |
|
|
15 |
STATS.Circularity = (4*pi*STATS.Area)/(STATS.ConvexPerimeter^2); |
|
|
16 |
%Roughness |
|
|
17 |
STATS.Roughness = STATS.ConvexPerimeter/STATS.Perimeter; |
|
|
18 |
%Elongation |
|
|
19 |
STATS.Elongation = STATS.MajorAxisLength/STATS.MinorAxisLength; |
|
|
20 |
%Compactness |
|
|
21 |
STATS.Compactness = STATS.Perimeter^2/(4*pi*STATS.Area); |
|
|
22 |
|
|
|
23 |
%% Compute Maximum Chord Length |
|
|
24 |
|
|
|
25 |
convexHullVertices = STATS.ConvexHull; |
|
|
26 |
maxChordLength = 0; |
|
|
27 |
|
|
|
28 |
for j = 1:size(convexHullVertices,1)-1 |
|
|
29 |
for k = j+1: size(convexHullVertices,1) |
|
|
30 |
|
|
|
31 |
chordLength = sqrt( ( convexHullVertices(j,1) - convexHullVertices(k,1) )^2 + ( convexHullVertices(j,2)- convexHullVertices(k,2) )^2 ) ; |
|
|
32 |
if chordLength > maxChordLength |
|
|
33 |
maxChordLength = chordLength; |
|
|
34 |
end |
|
|
35 |
|
|
|
36 |
end |
|
|
37 |
end |
|
|
38 |
STATS.MaxChordLength = maxChordLength; |
|
|
39 |
|
|
|
40 |
%% Compute Radial distance Standard Deviation |
|
|
41 |
|
|
|
42 |
I3=bwmorph(bwImage,'remove'); % Nodule Outline |
|
|
43 |
DR = NaN; % Vector of Outline Distance for RadialDistanceSD |
|
|
44 |
j = 0; |
|
|
45 |
for r = 1:size(I3,1) |
|
|
46 |
for c = 1:size(I3,2) |
|
|
47 |
if (I3(r,c) == 1) |
|
|
48 |
j = j + 1; |
|
|
49 |
% Distance |
|
|
50 |
DR(j) = sqrt((c-STATS.Centroid(1))^2+(r-STATS.Centroid(2))^2); |
|
|
51 |
end |
|
|
52 |
end |
|
|
53 |
end |
|
|
54 |
% RadialDistanceSD |
|
|
55 |
STATS.RadialDistanceSD = nanstd(DR(:)); |
|
|
56 |
|
|
|
57 |
%% Compute 2nd Moment |
|
|
58 |
% Vector of Distance to every pixel in the region for 2nd Moment |
|
|
59 |
DSM = NaN; |
|
|
60 |
k = 0; |
|
|
61 |
for r1 = 1:size(bwImage,1) |
|
|
62 |
for c1 = 1:size(bwImage,2) |
|
|
63 |
if (bwImage(r1,c1) == 1) |
|
|
64 |
k = k + 1; |
|
|
65 |
% Distance Square |
|
|
66 |
DSM(k) = (c1-STATS.Centroid(1))^2+(r1-STATS.Centroid(2))^2; |
|
|
67 |
end |
|
|
68 |
end |
|
|
69 |
end |
|
|
70 |
% SecondMoment (Variance)/Area |
|
|
71 |
STATS.SecondMoment = sum(DSM)/(STATS.Area)^2; |
|
|
72 |
|
|
|
73 |
|
|
|
74 |
end |