close all;clear all;clc
%N=4提取的四个特征:面积,周长,紧致度,离心率
%N=5提取的五个特征:面积,周长,圆度,矩形度,伸长度
N=5;
Feature=zeros(150,N);
for r=1:150
I=imread('1.jpg');
I2=rgb2gray(I);
Threshold=graythresh(I2);
BW=im2bw(I2,Threshold);
% imshow(BW);
[M1,N1]=size(BW);
i1=M1;change=0;
for i =1:M1
if change==0&sum(BW(i,:))~=0
change=1;
if i<i1
i1=i;
end
elseif change==1&sum(BW(i,:))==0
i2=i;change=0;
end
end
j1=N1;change=0;
for j =1:N1
if change==0&sum(BW(:,j))~=0
change=1;
if j<j1
j1=j;
end
elseif change==1&sum(BW(:,j))==0
j2=j;change=0;
end
end
BW1=BW(i1:i2,j1:j2);
[M2,N2]=size(BW1);
BW=imresize(BW1,[50 ceil(50*N2/M2)]);
%标记面积最大的区域
L = bwlabel(BW);
stats = regionprops(L);
Ar = cat(1, stats.Area);
ind = find(Ar ==max(Ar));
BW2= ismember(L,ind);
% phi =ACSE(BW2);
if N==4
phi =ACSE(BW2);
elseif N==5
phi=ALCRE(BW2);
end
Feature(r,:)=phi;
end
运行结果如下:
D165