function profile = profile_feature(img)
max_row = size(img,1);
max_col = size(img,2);
lp = zeros(max_row,1);
rp = zeros(max_row,1);
tp = zeros(max_col,1);
bp = zeros(max_col,1);
% Process image 1 by 1
for i = 1
% Create left profile
row = 1; col = 1;
while row ~=max_row
if img(row,col)== 1 % when 1 is found in a rowss
lp(row,i)=col;
row = row + 1; col = 1;
else
col = col + 1;
end
if col == max_col
row = row + 1; col = 1;
end
end
% Create right Profile
row = 1; col = max_col;
while row ~=max_row
if img(row,col)== 1 % when 1 is found in a row
rp(row,i)=col;
row = row + 1; col = max_col;
else
col = col - 1;
end
if col == 1
row = row + 1; col = max_col;
end
end
% Create Top Profile
row = 1; col = 1;
while col ~=max_col
if img(row,col)== 1 % when 1 is found in a col
tp(col,i)=row;
col = col + 1; row = 1;
else
row = row + 1;
end
if row == max_row
row = 1; col = col + 1;
end
end
% Create Bottom Profile
row = max_row; col = 1;
while col ~=max_col
if img(row,col)== 1 % when 1 is found in a col
bp(col,i)=row;
row = max_row; col = col + 1;
else
row = row - 1;
end
if row == 0
row = max_row; col = col + 1;
end
end
end % End of for loop
lp = smooth(lp);
rp = smooth(rp);
tp = smooth(tp);
bp = smooth(bp);
lp = imresize(lp,[40,1]);
rp = imresize(rp,[40,1]);
tp = imresize(tp,[40,1]);
bp = imresize(bp,[40,1]);
load line_or_circle;
[r1,c1]=predict(mdl,lp');
[r2,c2]=predict(mdl,tp');
[r3,c3]=predict(mdl,rp');
[r4,c4]=predict(mdl,bp');
if r1==0
c1 = 1-c1;
end
if r2==0
c2=1-c2;
end
if r3==0
c3=1-c3;
end
if r4==0
c4=1-c4;
end
profile = [c1(r1+1);c2(r2+1);c3(r3+1);c4(r4+1)];
MATLAB.zip_arc_complete a pro
版权申诉
112 浏览量
2022-09-14
22:29:23
上传
评论
收藏 214KB ZIP 举报
朱moyimi
- 粉丝: 64
- 资源: 1万+