-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_feat34.m
176 lines (144 loc) · 5.56 KB
/
get_feat34.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
% clear all, close all, clc;
function feat = get_feat34(Im,mask,ccs)
plt = ccs.plt; % 1 is for plot results, 0 for no plot
%% mask region props
mask = bwareafilt(mask,1);
properties = regionprops(mask,...
'Area',...
'BoundingBox',...
'Centroid',...
'Extent',...%Ratio of pixels in the region to pixels in the total bounding box,
'MajorAxisLength',...
'MinorAxisLength',...
'Perimeter',...
'Orientation');
% Extract boundary coordinates
outline = bwboundaries(mask);
[~, max_index] = max(cellfun('size', outline, 1));
outline = outline{max_index,1};
%% plot
if plt ==1
figure()
imshow(Im)
hold on;
rectangle('Position',properties.BoundingBox,...
'EdgeColor', 'b',...
'LineWidth',3,'LineStyle','--')
hold on;
scatter(properties.Centroid(1),properties.Centroid(2),200,'*',...
'MarkerEdgeColor',[1 0 1],...
'MarkerFaceColor',[.7 .7 .7],...
'LineWidth',2);
hold on;
plot(outline(:,2),outline(:,1),...
'g',...
'LineWidth',2);
end
%%
%% FACTORS (A, B, C) image processing
%%
%line centroid_boxPlot corners intersection with carcass outline
BB_box = properties.BoundingBox;
BB_coord = bbox2points(BB_box);
centroid = properties.Centroid;
coord_X0 = [];
coord_Y0 = [];
for i = 1:4
[X0 Y0] = polyxpoly([BB_coord(i,1);centroid(1)],...
[BB_coord(i,2);centroid(2)],...
outline(:,2),outline(:,1));% find intersection
X0 = mean(X0);
Y0 = mean(Y0);
X00 = [X0;centroid(1)];
Y00 = [Y0;centroid(2)];
if plt == 1
hold on;
scatter(X0,Y0,200,'+','m');
hold on;
line(X00,Y00,'Color','blue','LineStyle','-.');
pause(.01)
end
coord_X0 = [coord_X0;X0];
coord_Y0 = [coord_Y0;Y0];
end
cood_XY0 = [coord_X0,coord_Y0]; % intersect of centroid-box plot corners line with boundary
diff = centroid-cood_XY0;
A_fx = hypot(diff(:,1),diff(:,2));%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% A_fx
A_coord = [cood_XY0,repmat(centroid,4,1)];%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% A_fx
% horizontal nth percentile of length
B_fx = [];
C_fx = [];
C_points = [];
X11 = [];
Y11 = [];
B_coord = [];
C_coord =[];
for i = 1:16 % depends on number of segments you want to make (carcass divided into 16 along the body)
percentile = i/20;
BB_box_10 = BB_box;
BB_box_10(4) = percentile*BB_box(4);
BB_coord_10 = bbox2points(BB_box_10);
% find intersection between BB_coord and outline
[X1 Y1] = polyxpoly(BB_coord_10(3:4,1),...
BB_coord_10(3:4,2),...
outline(:,2),outline(:,1));%find intesection
X1 = [X1(1);X1(end)];
Y1 = [Y1(1);Y1(end)];
X11 = [X11;(X1)];
Y11 = [Y11;(Y1)];
C_pts = [X1,Y1];
C_points = [C_points;C_pts];
if plt ==1
hold on;
scatter(X1,Y1,200,'*','b');
hold on;
line(X1,Y1,'Color','red','LineStyle','-.');
hold on;
line([X1(1);centroid(1)],...
[Y1(1);centroid(2)],...
'Color','blue','LineStyle','--');
hold on;
line([X1(2);centroid(1)],...
[Y1(2);centroid(2)],...
'Color','blue','LineStyle','--');
pause(.01)
end
% distace between end to end of outline
diff_perc = [(X1(1)-X1(2)),(Y1(1)-Y1(2))];
dist_perc = hypot(diff_perc(1),diff_perc(2));
B_fx = [B_fx, dist_perc];%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% B_fx
B_coord = [B_coord;[X1(1),Y1(1),X1(2),Y1(2)]]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%B_coord
% distance between outline coordinates and centroid
diff_perc1 = [(X1-centroid(1)),(Y1-centroid(2))];
dist_perc1 = hypot(diff_perc1(:,1),diff_perc1(:,2));
C_fx = [C_fx, dist_perc1'];%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% C_fx
C_coord = [C_coord;[X1,Y1,repmat(centroid,2,1)]]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%C_coord
end
% distances between boundary points
% D_fx = [];
% for ii = 1:length(X11)
% diff_out_coord = [(X11-X11(ii)),(Y11-Y11(ii))];
% dist_out_coord = hypot(diff_out_coord(:,1),diff_out_coord(:,2));
% D_fx = [D_fx,dist_out_coord'];%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% D_fx
% end
for hh=1:length(B_fx)
B_name{hh} = strcat('B',num2str(hh));
end
for m=1:length(C_fx)
C_name{m} = strcat('C',num2str(m));
end
% for n=1:(length(D_fx))
% D_name{n} = strcat('D',num2str(n));
% end
%% compile features and respective names
fx_names = {'area', 'BB_width', 'BB_length', 'perimeter', 'major', 'minor',...
'extent','orientaion','A1','A2','A3','A4',B_name{:},C_name{:}};
fx_values = [properties.Area,BB_box(3:4),properties.Perimeter,...
properties.MajorAxisLength,properties.MinorAxisLength,...
properties.Extent,properties.Orientation,A_fx',B_fx,...
C_fx];
fx_coord.RP = properties; %Rp properties
fx_coord.A = A_coord; %A_features
fx_coord.B = B_coord; %B_features
fx_coord.C = C_coord; %C_features
feat = {fx_names,fx_values,fx_coord};