%读入图象
I=imread aa.jpg;
subplot(3,1,1),imshow(I);
title('原图像')
I=rgb2gray(I);%变为灰度图象
I=roicolor(I,150,255);%灰度图象变为二值图像 阈值选150
subplot(3,1,2),imshow(I);
title('二值化图像')
[M,N]=size(I);
% 去除干扰点
for i=2:M-1
for j=2:N-1
b=I(i-1,j-1)+I(i-1,j)+I(i-1,j+1)+I(i,j-1)+I(i,j+1)+I(i+1,j-1)+I(i+1,j)+I(i+1,j+1);
if b==8&I(i,j)==0
I(i,j)=1;
end
end
end
subplot(3,1,3),imshow(I);
title('去除干扰点的图象')
%变成一维图像
for i=1:N
for j=1:M
if I(j,i)==0
b(i)=j;
end
continue
end
end
b=M-b;
%保存一维图像
savefile = 'yiweibo.mat';
save(savefile, 'b') |