[讨论]一个算法的实现程序,谁可以看看哪里出问题了
程序如下:
clear all,close all;
a=imread('grab1003.bmp');
%读取图像
level=graythresh(a);
b=im2bw(a,level);
figure,imshow(b);
%将图像二值化,并将二值图像显示出来
c=b(340:402,70:411);
figure,imshow(c);
%区域划分,并将目标区域显示出来
d=double(a(338:404,67:414));
figure,imshow(d);
K1=[1 1 1 0 0 0 0;
0 1 1 1 0 0 0;
0 0 1 1 1 0 0;
0 0 0 1 1 1 0;
0 0 0 0 1 1 1]
K2=[0 0 1 1 1 0 0;
0 0 1 1 1 0 0;
0 0 1 1 1 0 0;
0 0 1 1 1 0 0;
0 0 1 1 1 0 0]
K3=[0 0 0 0 1 1 1;
0 0 0 1 1 1 0;
0 0 1 1 1 0 0;
0 1 1 1 0 0 0;
1 1 1 0 0 0 0]
K4=[0 0 0 0 0 0 0;
1 1 1 1 1 1 1;
1 1 1 1 1 1 1;
1 1 1 1 1 1 1;
0 0 0 0 0 0 0]
J1=K1/15;J2=K2/15;J3=K3/15;J4=K4/15;
maxpoint=[]
for i=3:65
for j=4:342
M1=J1.*d(i-2:i+2,j-3:j+3);%sum(M1);
M2=J2.*d(i-2:i+2,j-3:j+3);%sum(M2);
M3=J3.*d(i-2:i+2,j-3:j+3);%sum(M3);
M4=J4.*d(i-2:i+2,j-3:j+3);%sum(M4);
end
u1=max(M1);u2=max(M2);u3=max(M3);u4=max(M4);
if (u1>u2)&&(u1>u3)&&(u1>u4)
maxpoint=[maxpoint;[i,j]];
else if (u2>u1)&&(u2>u3)&&(u2>u4)
maxpoint=[maxpoint;[i,j]];
else if (u3>u1)&&(u3>u2)&&(u3>u4)
maxpoint=[maxpoint;[i,j]];
else if (u4>M1)&&(u4>u2)&&(u4>u3)
maxpoint=[maxpoint;[i,j]];
end;
end;
end;
end;
end;
figure,imshow(d);hold on;
plot(maxpoint(:,2),maxpoint(:,1),'r.');
hold off;
运行后出现:
??? Operands to the || and && operators must be convertible to logical scalar values.
谁可以给点意见咧?谢谢